comparison flacenc.c @ 4577:1cc2041c2e03 libavformat

Separate the raw FLAC muxer from raw.c to its own file, flacenc.c.
author jbr
date Thu, 26 Feb 2009 02:21:43 +0000
parents raw.c@90e0047f90b6
children c05d167a4fe2
comparison
equal deleted inserted replaced
4576:df7cc2eac54f 4577:1cc2041c2e03
1 /*
2 * raw FLAC muxer
3 * Copyright (c) 2006-2009 Justin Ruggles
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
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
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include "avformat.h"
23
24 static int flac_write_header(struct AVFormatContext *s)
25 {
26 static const uint8_t header[8] = {
27 0x66, 0x4C, 0x61, 0x43, 0x80, 0x00, 0x00, 0x22
28 };
29 uint8_t *streaminfo = s->streams[0]->codec->extradata;
30 int len = s->streams[0]->codec->extradata_size;
31 if(streaminfo != NULL && len > 0) {
32 put_buffer(s->pb, header, 8);
33 put_buffer(s->pb, streaminfo, len);
34 }
35 return 0;
36 }
37
38 static int flac_write_trailer(struct AVFormatContext *s)
39 {
40 ByteIOContext *pb = s->pb;
41 uint8_t *streaminfo = s->streams[0]->codec->extradata;
42 int len = s->streams[0]->codec->extradata_size;
43 int64_t file_size;
44
45 if (streaminfo && len > 0 && !url_is_streamed(s->pb)) {
46 file_size = url_ftell(pb);
47 url_fseek(pb, 8, SEEK_SET);
48 put_buffer(pb, streaminfo, len);
49 url_fseek(pb, file_size, SEEK_SET);
50 put_flush_packet(pb);
51 }
52 return 0;
53 }
54
55 static int flac_write_packet(struct AVFormatContext *s, AVPacket *pkt)
56 {
57 put_buffer(s->pb, pkt->data, pkt->size);
58 put_flush_packet(s->pb);
59 return 0;
60 }
61
62 AVOutputFormat flac_muxer = {
63 "flac",
64 NULL_IF_CONFIG_SMALL("raw FLAC"),
65 "audio/x-flac",
66 "flac",
67 0,
68 CODEC_ID_FLAC,
69 CODEC_ID_NONE,
70 flac_write_header,
71 flac_write_packet,
72 flac_write_trailer,
73 .flags= AVFMT_NOTIMESTAMPS,
74 };