Originally committed as revision 3285 to svn://svn.ffmpeg.org/ffmpeg/trunk
Michael Niedermayer authored on 2004/07/03 04:26:51... | ... |
@@ -34,6 +34,45 @@ static void put_be24(ByteIOContext *pb, int value) |
34 | 34 |
put_byte(pb, (value>> 0) & 0xFF ); |
35 | 35 |
} |
36 | 36 |
|
37 |
+static int get_audio_flags(AVCodecContext *enc){ |
|
38 |
+ int flags = 0x02; |
|
39 |
+ |
|
40 |
+ switch (enc->sample_rate) { |
|
41 |
+ case 44100: |
|
42 |
+ flags |= 0x0C; |
|
43 |
+ break; |
|
44 |
+ case 22050: |
|
45 |
+ flags |= 0x08; |
|
46 |
+ break; |
|
47 |
+ case 11025: |
|
48 |
+ flags |= 0x04; |
|
49 |
+ break; |
|
50 |
+ case 8000: //nellymoser only |
|
51 |
+ case 5512: //not mp3 |
|
52 |
+ flags |= 0x00; |
|
53 |
+ break; |
|
54 |
+ default: |
|
55 |
+ return -1; |
|
56 |
+ } |
|
57 |
+ |
|
58 |
+ if (enc->channels > 1) { |
|
59 |
+ flags |= 0x01; |
|
60 |
+ } |
|
61 |
+ |
|
62 |
+ switch(enc->codec_id){ |
|
63 |
+ case CODEC_ID_MP3: |
|
64 |
+ flags |= 0x20; |
|
65 |
+ break; |
|
66 |
+ case 0: |
|
67 |
+ flags |= enc->codec_tag<<4; |
|
68 |
+ break; |
|
69 |
+ default: |
|
70 |
+ return -1; |
|
71 |
+ } |
|
72 |
+ |
|
73 |
+ return flags; |
|
74 |
+} |
|
75 |
+ |
|
37 | 76 |
static int flv_write_header(AVFormatContext *s) |
38 | 77 |
{ |
39 | 78 |
ByteIOContext *pb = &s->pb; |
... | ... |
@@ -60,6 +99,8 @@ static int flv_write_header(AVFormatContext *s) |
60 | 60 |
put_be32(pb,11); // size |
61 | 61 |
flv->reserved=5; |
62 | 62 |
} |
63 |
+ if(enc->codec_type == CODEC_TYPE_AUDIO && get_audio_flags(enc)<0) |
|
64 |
+ return -1; |
|
63 | 65 |
} |
64 | 66 |
|
65 | 67 |
return 0; |
... | ... |
@@ -99,41 +140,8 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) |
99 | 99 |
flv->hasVideo = 1; |
100 | 100 |
} else { |
101 | 101 |
assert(enc->codec_type == CODEC_TYPE_AUDIO); |
102 |
- flags = 0x02; |
|
103 |
- |
|
104 |
- switch (enc->sample_rate) { |
|
105 |
- case 44100: |
|
106 |
- flags |= 0x0C; |
|
107 |
- break; |
|
108 |
- case 22050: |
|
109 |
- flags |= 0x08; |
|
110 |
- break; |
|
111 |
- case 11025: |
|
112 |
- flags |= 0x04; |
|
113 |
- break; |
|
114 |
- case 8000: //nellymoser only |
|
115 |
- case 5512: //not mp3 |
|
116 |
- flags |= 0x00; |
|
117 |
- break; |
|
118 |
- default: |
|
119 |
- assert(0); |
|
120 |
- } |
|
121 |
- |
|
122 |
- if (enc->channels > 1) { |
|
123 |
- flags |= 0x01; |
|
124 |
- } |
|
102 |
+ flags = get_audio_flags(enc); |
|
125 | 103 |
|
126 |
- switch(enc->codec_id){ |
|
127 |
- case CODEC_ID_MP3: |
|
128 |
- flags |= 0x20; |
|
129 |
- break; |
|
130 |
- case 0: |
|
131 |
- flags |= enc->codec_tag<<4; |
|
132 |
- break; |
|
133 |
- default: |
|
134 |
- assert(0); |
|
135 |
- } |
|
136 |
- |
|
137 | 104 |
assert(size); |
138 | 105 |
|
139 | 106 |
put_byte(pb, 8); |