comparison flacenc.c @ 4578:c05d167a4fe2 libavformat

Use a shared function to validate FLAC extradata.
author jbr
date Thu, 26 Feb 2009 02:29:24 +0000
parents 1cc2041c2e03
children e5fca5c56cb2
comparison
equal deleted inserted replaced
4577:1cc2041c2e03 4578:c05d167a4fe2
17 * You should have received a copy of the GNU Lesser General Public 17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software 18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */ 20 */
21 21
22 #include "libavcodec/flac.h"
22 #include "avformat.h" 23 #include "avformat.h"
23 24
24 static int flac_write_header(struct AVFormatContext *s) 25 static int flac_write_header(struct AVFormatContext *s)
25 { 26 {
26 static const uint8_t header[8] = { 27 static const uint8_t header[8] = {
27 0x66, 0x4C, 0x61, 0x43, 0x80, 0x00, 0x00, 0x22 28 0x66, 0x4C, 0x61, 0x43, 0x80, 0x00, 0x00, 0x22
28 }; 29 };
29 uint8_t *streaminfo = s->streams[0]->codec->extradata; 30 AVCodecContext *codec = s->streams[0]->codec;
31 uint8_t *streaminfo;
30 int len = s->streams[0]->codec->extradata_size; 32 int len = s->streams[0]->codec->extradata_size;
31 if(streaminfo != NULL && len > 0) { 33 enum FLACExtradataFormat format;
34
35 if (!ff_flac_is_extradata_valid(codec, &format, &streaminfo))
36 return -1;
37
38 if (format == FLAC_EXTRADATA_FORMAT_STREAMINFO) {
32 put_buffer(s->pb, header, 8); 39 put_buffer(s->pb, header, 8);
33 put_buffer(s->pb, streaminfo, len); 40 put_buffer(s->pb, streaminfo, len);
34 } 41 }
35 return 0; 42 return 0;
36 } 43 }
37 44
38 static int flac_write_trailer(struct AVFormatContext *s) 45 static int flac_write_trailer(struct AVFormatContext *s)
39 { 46 {
40 ByteIOContext *pb = s->pb; 47 ByteIOContext *pb = s->pb;
41 uint8_t *streaminfo = s->streams[0]->codec->extradata; 48 uint8_t *streaminfo;
42 int len = s->streams[0]->codec->extradata_size; 49 enum FLACExtradataFormat format;
43 int64_t file_size; 50 int64_t file_size;
44 51
45 if (streaminfo && len > 0 && !url_is_streamed(s->pb)) { 52 if (!ff_flac_is_extradata_valid(s->streams[0]->codec, &format, &streaminfo))
53 return -1;
54
55 if (!url_is_streamed(pb)) {
56 /* rewrite the STREAMINFO header block data */
46 file_size = url_ftell(pb); 57 file_size = url_ftell(pb);
47 url_fseek(pb, 8, SEEK_SET); 58 url_fseek(pb, 8, SEEK_SET);
48 put_buffer(pb, streaminfo, len); 59 put_buffer(pb, streaminfo, FLAC_STREAMINFO_SIZE);
49 url_fseek(pb, file_size, SEEK_SET); 60 url_fseek(pb, file_size, SEEK_SET);
50 put_flush_packet(pb); 61 put_flush_packet(pb);
62 } else {
63 av_log(s, AV_LOG_WARNING, "unable to rewrite FLAC header.\n");
51 } 64 }
52 return 0; 65 return 0;
53 } 66 }
54 67
55 static int flac_write_packet(struct AVFormatContext *s, AVPacket *pkt) 68 static int flac_write_packet(struct AVFormatContext *s, AVPacket *pkt)