comparison flvdec.c @ 5066:2bc8a9853970 libavformat

flvdec: Build a Speex header during FLV demuxing using required and default values. This is needed because FLV files with Speex do not contain a Speex header, which is necessary for stream copy.
author jbr
date Wed, 24 Jun 2009 22:10:53 +0000
parents 3550a49d6255
children 7f17519bfa37
comparison
equal deleted inserted replaced
5065:4c7f6c2d0e0e 5066:2bc8a9853970
22 * You should have received a copy of the GNU Lesser General Public 22 * You should have received a copy of the GNU Lesser General Public
23 * License along with FFmpeg; if not, write to the Free Software 23 * License along with FFmpeg; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 */ 25 */
26 26
27 #include "libavcodec/bytestream.h"
27 #include "libavcodec/mpeg4audio.h" 28 #include "libavcodec/mpeg4audio.h"
28 #include "avformat.h" 29 #include "avformat.h"
29 #include "flv.h" 30 #include "flv.h"
30 31
31 typedef struct { 32 typedef struct {
39 d = p->buf; 40 d = p->buf;
40 if (d[0] == 'F' && d[1] == 'L' && d[2] == 'V' && d[3] < 5 && d[5]==0) { 41 if (d[0] == 'F' && d[1] == 'L' && d[2] == 'V' && d[3] < 5 && d[5]==0) {
41 return AVPROBE_SCORE_MAX; 42 return AVPROBE_SCORE_MAX;
42 } 43 }
43 return 0; 44 return 0;
45 }
46
47 /**
48 * Builds a Speex header.
49 * This is not needed for the libavcodec libspeex decoder, but is needed for
50 * stream copy and for decoders which require a header.
51 */
52 static void flv_build_speex_header(uint8_t *extradata)
53 {
54 memset(extradata, 0, 80);
55 bytestream_put_buffer(&extradata, "Speex ", 8); // speex_string
56 bytestream_put_buffer(&extradata, "1.2rc1", 6); // speex_version
57 extradata += 14; // speex_version padding
58 bytestream_put_le32(&extradata, 1); // speex_version_id
59 bytestream_put_le32(&extradata, 80); // header_size
60 bytestream_put_le32(&extradata, 16000); // rate
61 bytestream_put_le32(&extradata, 1); // mode
62 bytestream_put_le32(&extradata, 4); // mode_bitstream_version
63 bytestream_put_le32(&extradata, 1); // nb_channels
64 bytestream_put_le32(&extradata, -1); // bitrate
65 bytestream_put_le32(&extradata, 320); // frame_size
66 // vbr = 0
67 // frames_per_packet = 0
68 // extra_headers = 0
69 // reserved1 = 0
70 // reserved2 = 0
44 } 71 }
45 72
46 static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream, int flv_codecid) { 73 static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream, int flv_codecid) {
47 AVCodecContext *acodec = astream->codec; 74 AVCodecContext *acodec = astream->codec;
48 switch(flv_codecid) { 75 switch(flv_codecid) {
60 case FLV_CODECID_AAC : acodec->codec_id = CODEC_ID_AAC; break; 87 case FLV_CODECID_AAC : acodec->codec_id = CODEC_ID_AAC; break;
61 case FLV_CODECID_ADPCM: acodec->codec_id = CODEC_ID_ADPCM_SWF; break; 88 case FLV_CODECID_ADPCM: acodec->codec_id = CODEC_ID_ADPCM_SWF; break;
62 case FLV_CODECID_SPEEX: 89 case FLV_CODECID_SPEEX:
63 acodec->codec_id = CODEC_ID_SPEEX; 90 acodec->codec_id = CODEC_ID_SPEEX;
64 acodec->sample_rate = 16000; 91 acodec->sample_rate = 16000;
92 acodec->extradata = av_mallocz(80 + FF_INPUT_BUFFER_PADDING_SIZE);
93 if (acodec->extradata) {
94 acodec->extradata_size = 80;
95 flv_build_speex_header(acodec->extradata);
96 } else {
97 av_log(s, AV_LOG_WARNING, "Unable to create Speex extradata\n");
98 }
65 break; 99 break;
66 case FLV_CODECID_MP3 : acodec->codec_id = CODEC_ID_MP3 ; astream->need_parsing = AVSTREAM_PARSE_FULL; break; 100 case FLV_CODECID_MP3 : acodec->codec_id = CODEC_ID_MP3 ; astream->need_parsing = AVSTREAM_PARSE_FULL; break;
67 case FLV_CODECID_NELLYMOSER_8KHZ_MONO: 101 case FLV_CODECID_NELLYMOSER_8KHZ_MONO:
68 acodec->sample_rate = 8000; //in case metadata does not otherwise declare samplerate 102 acodec->sample_rate = 8000; //in case metadata does not otherwise declare samplerate
69 case FLV_CODECID_NELLYMOSER: 103 case FLV_CODECID_NELLYMOSER: