~libmms-devel/libmms/trunk

« back to all changes in this revision

Viewing changes to src/mmsh.c

  • Committer: Soren Hansen
  • Date: 2010-01-10 21:56:15 UTC
  • Revision ID: soren@ubuntu.com-20100110215615-zvhjkfi03crsensi
Handle ASF extended stream properties. Thanks to Paul Fleischer for the patch!

Show diffs side-by-side

added added

removed removed

Lines of Context:
605
605
  }
606
606
}
607
607
 
 
608
static void interp_stream_properties(mmsh_t *this, int i) {
 
609
  uint16_t flags;
 
610
  uint16_t stream_id;
 
611
  int      type;
 
612
  int      encrypted;
 
613
  int      guid;
 
614
 
 
615
  guid = get_guid(this->asf_header, i);
 
616
  switch (guid) {
 
617
    case GUID_ASF_AUDIO_MEDIA:
 
618
      type = ASF_STREAM_TYPE_AUDIO;
 
619
      this->has_audio = 1;
 
620
      break;
 
621
 
 
622
    case GUID_ASF_VIDEO_MEDIA:
 
623
    case GUID_ASF_JFIF_MEDIA:
 
624
    case GUID_ASF_DEGRADABLE_JPEG_MEDIA:
 
625
      type = ASF_STREAM_TYPE_VIDEO;
 
626
      this->has_video = 1;
 
627
      break;
 
628
 
 
629
    case GUID_ASF_COMMAND_MEDIA:
 
630
      type = ASF_STREAM_TYPE_CONTROL;
 
631
      break;
 
632
 
 
633
    default:
 
634
      type = ASF_STREAM_TYPE_UNKNOWN;
 
635
  }
 
636
 
 
637
  flags = LE_16(this->asf_header + i + 48);
 
638
  stream_id = flags & 0x7F;
 
639
  encrypted = flags >> 15;
 
640
 
 
641
  lprintf ("stream object, stream id: %d, type: %d, encrypted: %d\n",
 
642
      stream_id, type, encrypted);
 
643
 
 
644
  this->stream_types[stream_id] = type;
 
645
  this->stream_ids[this->num_stream_ids] = stream_id;
 
646
  this->num_stream_ids++;
 
647
}
 
648
 
608
649
static void interp_header (mms_io_t *io, mmsh_t *this) {
609
650
 
610
651
  int i;
651
692
        break;
652
693
 
653
694
      case GUID_ASF_STREAM_PROPERTIES:
654
 
        {
655
 
          uint16_t flags;
656
 
          uint16_t stream_id;
657
 
          int      type;
658
 
          int      encrypted;
659
 
 
660
 
          guid = get_guid(this->asf_header, i);
661
 
          switch (guid) {
662
 
            case GUID_ASF_AUDIO_MEDIA:
663
 
              type = ASF_STREAM_TYPE_AUDIO;
664
 
              this->has_audio = 1;
665
 
              break;
666
 
 
667
 
            case GUID_ASF_VIDEO_MEDIA:
668
 
            case GUID_ASF_JFIF_MEDIA:
669
 
            case GUID_ASF_DEGRADABLE_JPEG_MEDIA:
670
 
              type = ASF_STREAM_TYPE_VIDEO;
671
 
              this->has_video = 1;
672
 
              break;
673
 
 
674
 
            case GUID_ASF_COMMAND_MEDIA:
675
 
              type = ASF_STREAM_TYPE_CONTROL;
676
 
              break;
677
 
 
678
 
            default:
679
 
              type = ASF_STREAM_TYPE_UNKNOWN;
680
 
          }
681
 
 
682
 
          flags = LE_16(this->asf_header + i + 48);
683
 
          stream_id = flags & 0x7F;
684
 
          encrypted = flags >> 15;
685
 
 
686
 
          lprintf ("stream object, stream id: %d, type: %d, encrypted: %d\n",
687
 
                   stream_id, type, encrypted);
688
 
 
689
 
          this->stream_types[stream_id] = type;
690
 
          this->stream_ids[this->num_stream_ids] = stream_id;
691
 
          this->num_stream_ids++;
692
 
 
693
 
        }
 
695
        interp_stream_properties(this, i);
694
696
        break;
695
697
 
696
698
      case GUID_ASF_STREAM_BITRATE_PROPERTIES:
714
716
        }
715
717
        break;
716
718
 
 
719
      case GUID_ASF_HEADER_EXTENSION:
 
720
        {
 
721
          int size = LE_32(this->asf_header + i + 18);
 
722
          int j = 22;
 
723
          int l;
 
724
          lprintf("Extension header data size: %d\n", size);
 
725
 
 
726
          while( (j+24) < length ) {
 
727
            guid = get_guid(this->asf_header, i + j);
 
728
            j += 16;
 
729
 
 
730
            l = LE_64(this->asf_header + i + j);
 
731
            j += 8;
 
732
 
 
733
            switch(guid) {
 
734
              case GUID_ASF_EXTENDED_STREAM_PROPERTIES:
 
735
                {
 
736
                  int stream_no = LE_16(this->asf_header + i + j + 48);
 
737
                  int name_count = LE_16(this->asf_header + i + j + 60);
 
738
                  int ext_count = LE_16(this->asf_header + i + j + 62);
 
739
                  int ext_j = 64;
 
740
                  int x;
 
741
 
 
742
                  lprintf ("l: %d\n", l);
 
743
                  lprintf ("Stream No: %d\n", stream_no);
 
744
                  lprintf ("Name count: %d\n", name_count);
 
745
                  lprintf ("ext_count: %d\n", ext_count);
 
746
 
 
747
                  // Loop through the number of stream names
 
748
                  for(x=0; x<name_count; x++) {
 
749
                    int lang_id_index;
 
750
                    int stream_name_len;
 
751
 
 
752
                    lang_id_index = LE_16(this->asf_header + i + j + ext_j);
 
753
                    ext_j += 2;
 
754
 
 
755
                    stream_name_len = LE_16(this->asf_header + i + j + ext_j);
 
756
                    ext_j += stream_name_len + 2;
 
757
 
 
758
                    lprintf ("Language id index: %d\n", lang_id_index);
 
759
                    lprintf ("Stream name Len: %d\n", stream_name_len);
 
760
                  }
 
761
 
 
762
                  // Loop through the number of extension system info
 
763
                  for(x=0; x<ext_count; x++) {
 
764
                    ext_j += 18;
 
765
                    int len = LE_16(this->asf_header + i + j + ext_j);
 
766
                    ext_j += 4 + len;
 
767
                  }
 
768
 
 
769
                  lprintf ("ext_j: %d\n", ext_j);
 
770
                  // Finally, we arrive at the interesting point: The optional Stream Property Object
 
771
                  if( (ext_j+24) < l ) {
 
772
                    guid = get_guid(this->asf_header, i + j + ext_j);
 
773
                    if( guid == GUID_ASF_STREAM_PROPERTIES ) {
 
774
                      interp_stream_properties(this, i + j + ext_j + 24);
 
775
                    }
 
776
                  } else {
 
777
                    lprintf ("Sorry, field not long enough\n");
 
778
                  }
 
779
 
 
780
                }
 
781
                break;
 
782
              default:
 
783
                lprintf ("unknown object (%d)\n", guid);
 
784
                break;
 
785
            }
 
786
 
 
787
            if( l > 24 ) {
 
788
              j += l-24;
 
789
            }
 
790
          }
 
791
 
 
792
        }
 
793
        break;
 
794
 
717
795
      case GUID_ASF_DATA:
718
796
        this->asf_num_packets = LE_64(this->asf_header + i + 40 - 24);
719
797
        lprintf("mmsh: num_packets: %d\n", (int)this->asf_num_packets);