annotate libmpdemux/demux_rtp_codec.cpp @ 22016:4479e6a1a140

Changing debug messages and renaming method names according to their implementations.
author voroshil
date Sat, 27 Jan 2007 16:41:01 +0000
parents a6b624360aef
children c9214f2c30c4
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"
16572
56a5f69e9b35 "LIVE.COM Streaming Media" is now called "LIVE555 Streaming Media".
rsf
parents: 11398
diff changeset
2 ////////// and the "LIVE555 Streaming Media" libraries:
9250
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" {
21911
e86bb13ec44b demux_rtp_codec.cpp:100: `INT_MAX' undeclared (first use this function)
diego
parents: 21871
diff changeset
6 #include <limits.h>
21983
a6b624360aef better autodetection of framerate in case of h264; it works correctly with b-frames.
nicodvb
parents: 21911
diff changeset
7 #include <math.h>
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
8 #include "stheader.h"
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
9 }
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
10
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
11 static void
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
12 needVideoFrameRate(demuxer_t* demuxer, MediaSubsession* subsession); // forward
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
13 static Boolean
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
14 parseQTState_video(QuickTimeGenericRTPSource::QTState const& qtState,
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
15 unsigned& fourcc); // forward
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
16 static Boolean
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
17 parseQTState_audio(QuickTimeGenericRTPSource::QTState const& qtState,
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
18 unsigned& fourcc, unsigned& numChannels); // forward
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
19
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
20 void rtpCodecInitialize_video(demuxer_t* demuxer,
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
21 MediaSubsession* subsession,
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
22 unsigned& flags) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
23 flags = 0;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
24 // Create a dummy video stream header
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
25 // to make the main MPlayer code happy:
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
26 sh_video_t* sh_video = new_sh_video(demuxer,0);
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
27 BITMAPINFOHEADER* bih
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
28 = (BITMAPINFOHEADER*)calloc(1,sizeof(BITMAPINFOHEADER));
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
29 bih->biSize = sizeof(BITMAPINFOHEADER);
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
30 sh_video->bih = bih;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
31 demux_stream_t* d_video = demuxer->video;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
32 d_video->sh = sh_video; sh_video->ds = d_video;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
33
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
34 // Map known video MIME types to the BITMAPINFOHEADER parameters
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
35 // that this program uses. (Note that not all types need all
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
36 // of the parameters to be set.)
10478
b0d0aa726417 Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents: 9910
diff changeset
37 if (strcmp(subsession->codecName(), "MPV") == 0) {
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
38 flags |= RTPSTATE_IS_MPEG12_VIDEO;
10478
b0d0aa726417 Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents: 9910
diff changeset
39 } else if (strcmp(subsession->codecName(), "MP1S") == 0 ||
b0d0aa726417 Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents: 9910
diff changeset
40 strcmp(subsession->codecName(), "MP2T") == 0) {
b0d0aa726417 Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents: 9910
diff changeset
41 flags |= RTPSTATE_IS_MPEG12_VIDEO|RTPSTATE_IS_MULTIPLEXED;
9250
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');
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
46 needVideoFrameRate(demuxer, subsession);
19415
95ebc082c918 Simplistic attempt to make H.264 over RTSP work.
reimar
parents: 16572
diff changeset
47 } else if (strcmp(subsession->codecName(), "H264") == 0) {
95ebc082c918 Simplistic attempt to make H.264 over RTSP work.
reimar
parents: 16572
diff changeset
48 bih->biCompression = sh_video->format
95ebc082c918 Simplistic attempt to make H.264 over RTSP work.
reimar
parents: 16572
diff changeset
49 = mmioFOURCC('H','2','6','4');
95ebc082c918 Simplistic attempt to make H.264 over RTSP work.
reimar
parents: 16572
diff changeset
50 needVideoFrameRate(demuxer, subsession);
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
51 } else if (strcmp(subsession->codecName(), "H261") == 0) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
52 bih->biCompression = sh_video->format
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
53 = mmioFOURCC('H','2','6','1');
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
54 needVideoFrameRate(demuxer, subsession);
9370
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(), "JPEG") == 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','J','P','G');
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
58 needVideoFrameRate(demuxer, subsession);
9370
88bd19564b64 Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents: 9250
diff changeset
59 } 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
60 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
61 = mmioFOURCC('m','p','4','v');
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
62 // For the codec to work correctly, it may need a 'VOL Header' to be
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
63 // inserted at the front of the data stream. Construct this from the
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
64 // "config" MIME parameter, which was present (hopefully) in the
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
65 // session's SDP description:
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
66 unsigned configLen;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
67 unsigned char* configData
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
68 = parseGeneralConfigStr(subsession->fmtp_config(), configLen);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
69 insertRTPData(demuxer, demuxer->video, configData, configLen);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
70 needVideoFrameRate(demuxer, subsession);
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
71 } else if (strcmp(subsession->codecName(), "X-QT") == 0 ||
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
72 strcmp(subsession->codecName(), "X-QUICKTIME") == 0) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
73 // QuickTime generic RTP format, as described in
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
74 // http://developer.apple.com/quicktime/icefloe/dispatch026.html
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
75
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
76 // 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
77 // that has QuickTime "sdAtom" information in the header. So, keep
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
78 // reading packets until we get one:
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
79 unsigned char* packetData; unsigned packetDataLen; float pts;
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
80 QuickTimeGenericRTPSource* qtRTPSource
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
81 = (QuickTimeGenericRTPSource*)(subsession->rtpSource());
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
82 unsigned fourcc;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
83 do {
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
84 if (!awaitRTPPacket(demuxer, demuxer->video,
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
85 packetData, packetDataLen, pts)) {
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
86 return;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
87 }
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
88 } while (!parseQTState_video(qtRTPSource->qtState, fourcc));
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
89
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
90 bih->biCompression = sh_video->format = fourcc;
21871
8f5c762ca6d9 add support for avc1 in X-QT over RTSP
gpoirier
parents: 19415
diff changeset
91 bih->biWidth = qtRTPSource->qtState.width;
8f5c762ca6d9 add support for avc1 in X-QT over RTSP
gpoirier
parents: 19415
diff changeset
92 bih->biHeight = qtRTPSource->qtState.height;
8f5c762ca6d9 add support for avc1 in X-QT over RTSP
gpoirier
parents: 19415
diff changeset
93 if (bih->biCompression == mmioFOURCC('a','v','c','1')) {
8f5c762ca6d9 add support for avc1 in X-QT over RTSP
gpoirier
parents: 19415
diff changeset
94 uint8_t *pos = (uint8_t*)qtRTPSource->qtState.sdAtom + 86;
8f5c762ca6d9 add support for avc1 in X-QT over RTSP
gpoirier
parents: 19415
diff changeset
95 uint8_t *endpos = (uint8_t*)qtRTPSource->qtState.sdAtom
8f5c762ca6d9 add support for avc1 in X-QT over RTSP
gpoirier
parents: 19415
diff changeset
96 + qtRTPSource->qtState.sdAtomSize;
8f5c762ca6d9 add support for avc1 in X-QT over RTSP
gpoirier
parents: 19415
diff changeset
97 while (pos+8 < endpos) {
8f5c762ca6d9 add support for avc1 in X-QT over RTSP
gpoirier
parents: 19415
diff changeset
98 unsigned atomLength = pos[0]<<24 | pos[1]<<16 | pos[2]<<8 | pos[3];
8f5c762ca6d9 add support for avc1 in X-QT over RTSP
gpoirier
parents: 19415
diff changeset
99 if (atomLength == 0 || atomLength > endpos-pos) break;
8f5c762ca6d9 add support for avc1 in X-QT over RTSP
gpoirier
parents: 19415
diff changeset
100 if (memcmp(pos+4, "avcC", 4) == 0 &&
8f5c762ca6d9 add support for avc1 in X-QT over RTSP
gpoirier
parents: 19415
diff changeset
101 atomLength > 8 &&
8f5c762ca6d9 add support for avc1 in X-QT over RTSP
gpoirier
parents: 19415
diff changeset
102 atomLength <= INT_MAX-sizeof(BITMAPINFOHEADER)) {
8f5c762ca6d9 add support for avc1 in X-QT over RTSP
gpoirier
parents: 19415
diff changeset
103 bih->biSize = sizeof(BITMAPINFOHEADER)+atomLength-8;
8f5c762ca6d9 add support for avc1 in X-QT over RTSP
gpoirier
parents: 19415
diff changeset
104 sh_video->bih = bih = (BITMAPINFOHEADER*)realloc(bih, bih->biSize);
8f5c762ca6d9 add support for avc1 in X-QT over RTSP
gpoirier
parents: 19415
diff changeset
105 memcpy(bih+1, pos+8, atomLength-8);
8f5c762ca6d9 add support for avc1 in X-QT over RTSP
gpoirier
parents: 19415
diff changeset
106 break;
8f5c762ca6d9 add support for avc1 in X-QT over RTSP
gpoirier
parents: 19415
diff changeset
107 }
8f5c762ca6d9 add support for avc1 in X-QT over RTSP
gpoirier
parents: 19415
diff changeset
108 pos += atomLength;
8f5c762ca6d9 add support for avc1 in X-QT over RTSP
gpoirier
parents: 19415
diff changeset
109 }
8f5c762ca6d9 add support for avc1 in X-QT over RTSP
gpoirier
parents: 19415
diff changeset
110 needVideoFrameRate(demuxer, subsession);
8f5c762ca6d9 add support for avc1 in X-QT over RTSP
gpoirier
parents: 19415
diff changeset
111 }
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
112 } else {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
113 fprintf(stderr,
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
114 "Unknown MPlayer format code for MIME type \"video/%s\"\n",
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
115 subsession->codecName());
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
116 }
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
117 }
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
118
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
119 void rtpCodecInitialize_audio(demuxer_t* demuxer,
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
120 MediaSubsession* subsession,
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
121 unsigned& flags) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
122 flags = 0;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
123 // Create a dummy audio stream header
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
124 // to make the main MPlayer code happy:
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
125 sh_audio_t* sh_audio = new_sh_audio(demuxer,0);
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
126 WAVEFORMATEX* wf = (WAVEFORMATEX*)calloc(1,sizeof(WAVEFORMATEX));
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
127 sh_audio->wf = wf;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
128 demux_stream_t* d_audio = demuxer->audio;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
129 d_audio->sh = sh_audio; sh_audio->ds = d_audio;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
130
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
131 wf->nChannels = subsession->numChannels();
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
132
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
133 // Map known audio MIME types to the WAVEFORMATEX parameters
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
134 // that this program uses. (Note that not all types need all
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
135 // of the parameters to be set.)
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
136 wf->nSamplesPerSec
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
137 = subsession->rtpSource()->timestampFrequency(); // by default
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
138 if (strcmp(subsession->codecName(), "MPA") == 0 ||
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
139 strcmp(subsession->codecName(), "MPA-ROBUST") == 0 ||
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
140 strcmp(subsession->codecName(), "X-MP3-DRAFT-00") == 0) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
141 wf->wFormatTag = sh_audio->format = 0x55;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
142 // 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
143 wf->nSamplesPerSec = 0; // sample rate is deduced from the data
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
144 } else if (strcmp(subsession->codecName(), "AC3") == 0) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
145 wf->wFormatTag = sh_audio->format = 0x2000;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
146 wf->nSamplesPerSec = 0; // sample rate is deduced from the data
10478
b0d0aa726417 Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents: 9910
diff changeset
147 } else if (strcmp(subsession->codecName(), "L16") == 0) {
b0d0aa726417 Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents: 9910
diff changeset
148 wf->wFormatTag = sh_audio->format = 0x736f7774; // "twos"
b0d0aa726417 Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents: 9910
diff changeset
149 wf->nBlockAlign = 1;
b0d0aa726417 Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents: 9910
diff changeset
150 wf->wBitsPerSample = 16;
b0d0aa726417 Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents: 9910
diff changeset
151 wf->cbSize = 0;
b0d0aa726417 Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents: 9910
diff changeset
152 } else if (strcmp(subsession->codecName(), "L8") == 0) {
b0d0aa726417 Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents: 9910
diff changeset
153 wf->wFormatTag = sh_audio->format = 0x20776172; // "raw "
b0d0aa726417 Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents: 9910
diff changeset
154 wf->nBlockAlign = 1;
b0d0aa726417 Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents: 9910
diff changeset
155 wf->wBitsPerSample = 8;
b0d0aa726417 Added support for the "L16" and "L8" (raw PCM audio) RTP payload formats.
rsf
parents: 9910
diff changeset
156 wf->cbSize = 0;
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
157 } else if (strcmp(subsession->codecName(), "PCMU") == 0) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
158 wf->wFormatTag = sh_audio->format = 0x7;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
159 wf->nAvgBytesPerSec = 8000;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
160 wf->nBlockAlign = 1;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
161 wf->wBitsPerSample = 8;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
162 wf->cbSize = 0;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
163 } else if (strcmp(subsession->codecName(), "PCMA") == 0) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
164 wf->wFormatTag = sh_audio->format = 0x6;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
165 wf->nAvgBytesPerSec = 8000;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
166 wf->nBlockAlign = 1;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
167 wf->wBitsPerSample = 8;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
168 wf->cbSize = 0;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
169 } else if (strcmp(subsession->codecName(), "GSM") == 0) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
170 wf->wFormatTag = sh_audio->format = mmioFOURCC('a','g','s','m');
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
171 wf->nAvgBytesPerSec = 1650;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
172 wf->nBlockAlign = 33;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
173 wf->wBitsPerSample = 16;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
174 wf->cbSize = 0;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
175 } else if (strcmp(subsession->codecName(), "QCELP") == 0) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
176 wf->wFormatTag = sh_audio->format = mmioFOURCC('Q','c','l','p');
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
177 wf->nAvgBytesPerSec = 1750;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
178 wf->nBlockAlign = 35;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
179 wf->wBitsPerSample = 16;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
180 wf->cbSize = 0;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
181 } else if (strcmp(subsession->codecName(), "MP4A-LATM") == 0) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
182 wf->wFormatTag = sh_audio->format = mmioFOURCC('m','p','4','a');
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
183 // For the codec to work correctly, it needs "AudioSpecificConfig"
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
184 // data, which is parsed from the "StreamMuxConfig" string that
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
185 // was present (hopefully) in the SDP description:
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
186 unsigned codecdata_len;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
187 sh_audio->codecdata
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
188 = parseStreamMuxConfigStr(subsession->fmtp_config(),
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
189 codecdata_len);
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
190 sh_audio->codecdata_len = codecdata_len;
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
191 } else if (strcmp(subsession->codecName(), "MPEG4-GENERIC") == 0) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
192 wf->wFormatTag = sh_audio->format = mmioFOURCC('m','p','4','a');
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
193 // For the codec to work correctly, it needs "AudioSpecificConfig"
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
194 // data, which was present (hopefully) in the SDP description:
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
195 unsigned codecdata_len;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
196 sh_audio->codecdata
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
197 = parseGeneralConfigStr(subsession->fmtp_config(),
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
198 codecdata_len);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
199 sh_audio->codecdata_len = codecdata_len;
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
200 } else if (strcmp(subsession->codecName(), "X-QT") == 0 ||
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
201 strcmp(subsession->codecName(), "X-QUICKTIME") == 0) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
202 // QuickTime generic RTP format, as described in
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
203 // http://developer.apple.com/quicktime/icefloe/dispatch026.html
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 // 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
206 // that has QuickTime "sdAtom" information in the header. So, keep
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
207 // reading packets until we get one:
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
208 unsigned char* packetData; unsigned packetDataLen; float pts;
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
209 QuickTimeGenericRTPSource* qtRTPSource
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
210 = (QuickTimeGenericRTPSource*)(subsession->rtpSource());
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
211 unsigned fourcc, numChannels;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
212 do {
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
213 if (!awaitRTPPacket(demuxer, demuxer->audio,
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
214 packetData, packetDataLen, pts)) {
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
215 return;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
216 }
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
217 } while (!parseQTState_audio(qtRTPSource->qtState, fourcc, numChannels));
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
218
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
219 wf->wFormatTag = sh_audio->format = fourcc;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
220 wf->nChannels = numChannels;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
221 } else {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
222 fprintf(stderr,
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
223 "Unknown MPlayer format code for MIME type \"audio/%s\"\n",
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
224 subsession->codecName());
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
225 }
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
226 }
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
227
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
228 static void needVideoFrameRate(demuxer_t* demuxer,
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
229 MediaSubsession* subsession) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
230 // For some codecs, MPlayer's decoding software can't (or refuses to :-)
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
231 // figure out the frame rate by itself, so (unless the user specifies
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
232 // it manually, using "-fps") we figure it out ourselves here, using the
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
233 // presentation timestamps in successive packets,
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
234 extern float force_fps; if (force_fps != 0.0) return; // user used "-fps"
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
235
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
236 demux_stream_t* d_video = demuxer->video;
9910
41ed68e3a034 Minor code cleanup.
rsf
parents: 9565
diff changeset
237 sh_video_t* sh_video = (sh_video_t*)(d_video->sh);
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
238
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
239 // If we already know the subsession's video frame rate, use it:
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
240 int fps = (int)(subsession->videoFPS());
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
241 if (fps != 0) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
242 sh_video->fps = fps;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
243 return;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
244 }
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
245
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
246 // Keep looking at incoming frames until we see two with different,
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
247 // non-zero "pts" timestamps:
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
248 unsigned char* packetData; unsigned packetDataLen;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
249 float lastPTS = 0.0, curPTS;
11397
d0db11b74e82 Increased the threshold for how many incoming frames to look at while guessing
rsf
parents: 10478
diff changeset
250 unsigned const maxNumFramesToWaitFor = 300;
21983
a6b624360aef better autodetection of framerate in case of h264; it works correctly with b-frames.
nicodvb
parents: 21911
diff changeset
251 int lastfps = 0;
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
252 for (unsigned i = 0; i < maxNumFramesToWaitFor; ++i) {
9910
41ed68e3a034 Minor code cleanup.
rsf
parents: 9565
diff changeset
253 if (!awaitRTPPacket(demuxer, d_video, packetData, packetDataLen, curPTS)) {
41ed68e3a034 Minor code cleanup.
rsf
parents: 9565
diff changeset
254 break;
41ed68e3a034 Minor code cleanup.
rsf
parents: 9565
diff changeset
255 }
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
256
21983
a6b624360aef better autodetection of framerate in case of h264; it works correctly with b-frames.
nicodvb
parents: 21911
diff changeset
257 if (curPTS != lastPTS && lastPTS != 0.0) {
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
258 // Use the difference between these two "pts"s to guess the frame rate.
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
259 // (should really check that there were no missing frames inbetween)#####
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
260 // Guess the frame rate as an integer. If it's not, use "-fps" instead.
21983
a6b624360aef better autodetection of framerate in case of h264; it works correctly with b-frames.
nicodvb
parents: 21911
diff changeset
261 fps = (int)(1/fabs(curPTS-lastPTS) + 0.5); // rounding
a6b624360aef better autodetection of framerate in case of h264; it works correctly with b-frames.
nicodvb
parents: 21911
diff changeset
262 if (fps == lastfps) {
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
263 fprintf(stderr, "demux_rtp: Guessed the video frame rate as %d frames-per-second.\n\t(If this is wrong, use the \"-fps <frame-rate>\" option instead.)\n", fps);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
264 sh_video->fps = fps;
21983
a6b624360aef better autodetection of framerate in case of h264; it works correctly with b-frames.
nicodvb
parents: 21911
diff changeset
265 sh_video->frametime=1.0f/fps;
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
266 return;
21983
a6b624360aef better autodetection of framerate in case of h264; it works correctly with b-frames.
nicodvb
parents: 21911
diff changeset
267 }
a6b624360aef better autodetection of framerate in case of h264; it works correctly with b-frames.
nicodvb
parents: 21911
diff changeset
268 if (fps>lastfps) lastfps = fps;
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
269 }
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
270 lastPTS = curPTS;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
271 }
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
272 fprintf(stderr, "demux_rtp: Failed to guess the video frame rate\n");
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
273 }
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9370
diff changeset
274
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
275 static Boolean
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
276 parseQTState_video(QuickTimeGenericRTPSource::QTState const& qtState,
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
277 unsigned& fourcc) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
278 // qtState's "sdAtom" field is supposed to contain a QuickTime video
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
279 // '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
280 char const* sdAtom = qtState.sdAtom;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
281 if (sdAtom == NULL || qtState.sdAtomSize < 2*4) return False;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
282
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
283 fourcc = *(unsigned*)(&sdAtom[4]); // put in host order
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
284 return True;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
285 }
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
286
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
287 static Boolean
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
288 parseQTState_audio(QuickTimeGenericRTPSource::QTState const& qtState,
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
289 unsigned& fourcc, unsigned& numChannels) {
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
290 // qtState's "sdAtom" field is supposed to contain a QuickTime audio
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
291 // '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
292 // 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
293 // contain the number of channels ("numChannels") that we want:
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
294 char const* sdAtom = qtState.sdAtom;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
295 if (sdAtom == NULL || qtState.sdAtomSize < 7*4) return False;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
296
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
297 fourcc = *(unsigned*)(&sdAtom[4]); // put in host order
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
298
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
299 char const* word7Ptr = &sdAtom[6*4];
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
300 numChannels = (word7Ptr[0]<<8)|(word7Ptr[1]);
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
301 return True;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents:
diff changeset
302 }