annotate libmpdemux/demux_rtp_codec.cpp @ 9423:36637ef379f1

sync
author nicolas
date Fri, 14 Feb 2003 15:00:22 +0000
parents 88bd19564b64
children e74916774667
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
1 ////////// Codec-specific routines used to interface between "MPlayer"
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
2 ////////// and the "LIVE.COM Streaming Media" libraries:
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
3
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
4 #include "demux_rtp_internal.h"
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
5 extern "C" {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
6 #include "stheader.h"
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
7 }
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
8
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
9 static Boolean
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
10 parseQTState_video(QuickTimeGenericRTPSource::QTState const& qtState,
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
11 unsigned& fourcc); // forward
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
12 static Boolean
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
13 parseQTState_audio(QuickTimeGenericRTPSource::QTState const& qtState,
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
14 unsigned& fourcc, unsigned& numChannels); // forward
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
15
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
16 void rtpCodecInitialize_video(demuxer_t* demuxer,
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
17 MediaSubsession* subsession,
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
18 unsigned& flags) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
19 flags = 0;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
20 // Create a dummy video stream header
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
21 // to make the main MPlayer code happy:
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
22 sh_video_t* sh_video = new_sh_video(demuxer,0);
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
23 BITMAPINFOHEADER* bih
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
24 = (BITMAPINFOHEADER*)calloc(1,sizeof(BITMAPINFOHEADER));
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
25 bih->biSize = sizeof(BITMAPINFOHEADER);
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
26 sh_video->bih = bih;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
27 demux_stream_t* d_video = demuxer->video;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
28 d_video->sh = sh_video; sh_video->ds = d_video;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
29
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
30 // If we happen to know the subsession's video frame rate, set it,
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
31 // so that the user doesn't have to give the "-fps" option instead.
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
32 int fps = (int)(subsession->videoFPS());
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
33 if (fps != 0) sh_video->fps = fps;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
34
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
35 // Map known video MIME types to the BITMAPINFOHEADER parameters
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
36 // that this program uses. (Note that not all types need all
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
37 // of the parameters to be set.)
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
38 if (strcmp(subsession->codecName(), "MPV") == 0 ||
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
39 strcmp(subsession->codecName(), "MP1S") == 0 ||
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
40 strcmp(subsession->codecName(), "MP2T") == 0) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
41 flags |= RTPSTATE_IS_MPEG;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
42 } else if (strcmp(subsession->codecName(), "H263") == 0 ||
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
43 strcmp(subsession->codecName(), "H263-1998") == 0) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
44 bih->biCompression = sh_video->format
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
45 = mmioFOURCC('H','2','6','3');
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
46 } else if (strcmp(subsession->codecName(), "H261") == 0) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
47 bih->biCompression = sh_video->format
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
48 = mmioFOURCC('H','2','6','1');
9370
88bd19564b64 Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents: 9250
diff changeset
49 } else if (strcmp(subsession->codecName(), "JPEG") == 0) {
88bd19564b64 Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents: 9250
diff changeset
50 bih->biCompression = sh_video->format
88bd19564b64 Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents: 9250
diff changeset
51 = mmioFOURCC('M','J','P','G');
88bd19564b64 Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents: 9250
diff changeset
52 #if (LIVEMEDIA_LIBRARY_VERSION_INT < 1044662400)
88bd19564b64 Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents: 9250
diff changeset
53 fprintf(stderr, "WARNING: This video stream might not play correctly. Please upgrade to version \"2003.02.08\" or later of the \"LIVE.COM Streaming Media\" libraries.\n");
88bd19564b64 Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents: 9250
diff changeset
54 #endif
88bd19564b64 Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents: 9250
diff changeset
55 } else if (strcmp(subsession->codecName(), "MP4V-ES") == 0) {
88bd19564b64 Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents: 9250
diff changeset
56 bih->biCompression = sh_video->format
88bd19564b64 Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents: 9250
diff changeset
57 = mmioFOURCC('m','p','4','v');
88bd19564b64 Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents: 9250
diff changeset
58 //flags |= RTPSTATE_IS_MPEG; // MPEG hdr checking in video.c doesn't work!
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
59 } else if (strcmp(subsession->codecName(), "X-QT") == 0 ||
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
60 strcmp(subsession->codecName(), "X-QUICKTIME") == 0) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
61 // QuickTime generic RTP format, as described in
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
62 // http://developer.apple.com/quicktime/icefloe/dispatch026.html
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
63
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
64 // We can't initialize this stream until we've received the first packet
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
65 // that has QuickTime "sdAtom" information in the header. So, keep
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
66 // reading packets until we get one:
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
67 unsigned char* packetData; unsigned packetDataLen;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
68 QuickTimeGenericRTPSource* qtRTPSource
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
69 = (QuickTimeGenericRTPSource*)(subsession->rtpSource());
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
70 unsigned fourcc;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
71 do {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
72 if (!awaitRTPPacket(demuxer, 0 /*video*/, packetData, packetDataLen)) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
73 return;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
74 }
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
75 } while (!parseQTState_video(qtRTPSource->qtState, fourcc));
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
76
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
77 bih->biCompression = sh_video->format = fourcc;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
78 } else {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
79 fprintf(stderr,
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
80 "Unknown MPlayer format code for MIME type \"video/%s\"\n",
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
81 subsession->codecName());
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
82 }
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
83 }
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
84
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
85 void rtpCodecInitialize_audio(demuxer_t* demuxer,
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
86 MediaSubsession* subsession,
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
87 unsigned& flags) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
88 flags = 0;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
89 // Create a dummy audio stream header
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
90 // to make the main MPlayer code happy:
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
91 sh_audio_t* sh_audio = new_sh_audio(demuxer,0);
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
92 WAVEFORMATEX* wf = (WAVEFORMATEX*)calloc(1,sizeof(WAVEFORMATEX));
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
93 sh_audio->wf = wf;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
94 demux_stream_t* d_audio = demuxer->audio;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
95 d_audio->sh = sh_audio; sh_audio->ds = d_audio;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
96
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
97 // Map known audio MIME types to the WAVEFORMATEX parameters
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
98 // that this program uses. (Note that not all types need all
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
99 // of the parameters to be set.)
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
100 wf->nSamplesPerSec
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
101 = subsession->rtpSource()->timestampFrequency(); // by default
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
102 if (strcmp(subsession->codecName(), "MPA") == 0 ||
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
103 strcmp(subsession->codecName(), "MPA-ROBUST") == 0 ||
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
104 strcmp(subsession->codecName(), "X-MP3-DRAFT-00") == 0) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
105 wf->wFormatTag = sh_audio->format = 0x55;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
106 // Note: 0x55 is for layer III, but should work for I,II also
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
107 wf->nSamplesPerSec = 0; // sample rate is deduced from the data
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
108 flags |= RTPSTATE_IS_MPEG;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
109 } else if (strcmp(subsession->codecName(), "AC3") == 0) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
110 wf->wFormatTag = sh_audio->format = 0x2000;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
111 wf->nSamplesPerSec = 0; // sample rate is deduced from the data
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
112 } else if (strcmp(subsession->codecName(), "PCMU") == 0) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
113 wf->wFormatTag = sh_audio->format = 0x7;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
114 wf->nChannels = 1;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
115 wf->nAvgBytesPerSec = 8000;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
116 wf->nBlockAlign = 1;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
117 wf->wBitsPerSample = 8;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
118 wf->cbSize = 0;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
119 } else if (strcmp(subsession->codecName(), "PCMA") == 0) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
120 wf->wFormatTag = sh_audio->format = 0x6;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
121 wf->nChannels = 1;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
122 wf->nAvgBytesPerSec = 8000;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
123 wf->nBlockAlign = 1;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
124 wf->wBitsPerSample = 8;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
125 wf->cbSize = 0;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
126 } else if (strcmp(subsession->codecName(), "GSM") == 0) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
127 wf->wFormatTag = sh_audio->format = mmioFOURCC('a','g','s','m');
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
128 wf->nChannels = 1;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
129 wf->nAvgBytesPerSec = 1650;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
130 wf->nBlockAlign = 33;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
131 wf->wBitsPerSample = 16;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
132 wf->cbSize = 0;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
133 } else if (strcmp(subsession->codecName(), "QCELP") == 0) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
134 wf->wFormatTag = sh_audio->format = mmioFOURCC('Q','c','l','p');
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
135 // The following settings for QCELP don't quite work right #####
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
136 wf->nChannels = 1;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
137 wf->nAvgBytesPerSec = 1750;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
138 wf->nBlockAlign = 35;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
139 wf->wBitsPerSample = 16;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
140 wf->cbSize = 0;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
141 } else if (strcmp(subsession->codecName(), "MP4A-LATM") == 0) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
142 wf->wFormatTag = sh_audio->format = mmioFOURCC('m','p','4','a');
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
143 #if (LIVEMEDIA_LIBRARY_VERSION_INT < 1042761600)
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
144 fprintf(stderr, "WARNING: This audio stream might not play correctly. Please upgrade to version \"2003.01.17\" or later of the \"LIVE.COM Streaming Media\" libraries.\n");
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
145 #else
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
146 // For the codec to work correctly, it needs "AudioSpecificConfig"
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
147 // data, which is parsed from the "StreamMuxConfig" string that
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
148 // was present (hopefully) in the SDP description:
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
149 unsigned codecdata_len;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
150 sh_audio->codecdata
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
151 = parseStreamMuxConfigStr(subsession->fmtp_config(),
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
152 codecdata_len);
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
153 sh_audio->codecdata_len = codecdata_len;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
154 #endif
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
155 flags |= RTPSTATE_IS_MPEG;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
156 } else if (strcmp(subsession->codecName(), "X-QT") == 0 ||
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
157 strcmp(subsession->codecName(), "X-QUICKTIME") == 0) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
158 // QuickTime generic RTP format, as described in
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
159 // http://developer.apple.com/quicktime/icefloe/dispatch026.html
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
160
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
161 // We can't initialize this stream until we've received the first packet
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
162 // that has QuickTime "sdAtom" information in the header. So, keep
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
163 // reading packets until we get one:
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
164 unsigned char* packetData; unsigned packetDataLen;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
165 QuickTimeGenericRTPSource* qtRTPSource
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
166 = (QuickTimeGenericRTPSource*)(subsession->rtpSource());
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
167 unsigned fourcc, numChannels;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
168 do {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
169 if (!awaitRTPPacket(demuxer, 1 /*audio*/, packetData, packetDataLen)) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
170 return;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
171 }
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
172 } while (!parseQTState_audio(qtRTPSource->qtState, fourcc, numChannels));
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
173
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
174 wf->wFormatTag = sh_audio->format = fourcc;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
175 wf->nChannels = numChannels;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
176 } else {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
177 fprintf(stderr,
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
178 "Unknown MPlayer format code for MIME type \"audio/%s\"\n",
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
179 subsession->codecName());
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
180 }
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
181 }
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
182
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
183 static Boolean
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
184 parseQTState_video(QuickTimeGenericRTPSource::QTState const& qtState,
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
185 unsigned& fourcc) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
186 // qtState's "sdAtom" field is supposed to contain a QuickTime video
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
187 // 'sample description' atom. This atom's name is the 'fourcc' that we want:
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
188 char const* sdAtom = qtState.sdAtom;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
189 if (sdAtom == NULL || qtState.sdAtomSize < 2*4) return False;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
190
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
191 fourcc = *(unsigned*)(&sdAtom[4]); // put in host order
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
192 return True;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
193 }
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
194
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
195 static Boolean
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
196 parseQTState_audio(QuickTimeGenericRTPSource::QTState const& qtState,
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
197 unsigned& fourcc, unsigned& numChannels) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
198 // qtState's "sdAtom" field is supposed to contain a QuickTime audio
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
199 // 'sample description' atom. This atom's name is the 'fourcc' that we want.
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
200 // Also, the top half of the 5th word following the atom name should
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
201 // contain the number of channels ("numChannels") that we want:
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
202 char const* sdAtom = qtState.sdAtom;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
203 if (sdAtom == NULL || qtState.sdAtomSize < 7*4) return False;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
204
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
205 fourcc = *(unsigned*)(&sdAtom[4]); // put in host order
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
206
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
207 char const* word7Ptr = &sdAtom[6*4];
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
208 numChannels = (word7Ptr[0]<<8)|(word7Ptr[1]);
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
209 return True;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
210 }