00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "libavcodec/flac.h"
00023 #include "avformat.h"
00024 #include "flacenc.h"
00025
00026 int ff_flac_write_header(ByteIOContext *pb, AVCodecContext *codec)
00027 {
00028 static const uint8_t header[8] = {
00029 0x66, 0x4C, 0x61, 0x43, 0x80, 0x00, 0x00, 0x22
00030 };
00031 uint8_t *streaminfo;
00032 enum FLACExtradataFormat format;
00033
00034 if (!ff_flac_is_extradata_valid(codec, &format, &streaminfo))
00035 return -1;
00036
00037
00038 if (format == FLAC_EXTRADATA_FORMAT_STREAMINFO) {
00039 put_buffer(pb, header, 8);
00040 }
00041
00042
00043 put_buffer(pb, codec->extradata, codec->extradata_size);
00044
00045 return 0;
00046 }
00047
00048 static int flac_write_header(struct AVFormatContext *s)
00049 {
00050 return ff_flac_write_header(s->pb, s->streams[0]->codec);
00051 }
00052
00053 static int flac_write_trailer(struct AVFormatContext *s)
00054 {
00055 ByteIOContext *pb = s->pb;
00056 uint8_t *streaminfo;
00057 enum FLACExtradataFormat format;
00058 int64_t file_size;
00059
00060 if (!ff_flac_is_extradata_valid(s->streams[0]->codec, &format, &streaminfo))
00061 return -1;
00062
00063 if (!url_is_streamed(pb)) {
00064
00065 file_size = url_ftell(pb);
00066 url_fseek(pb, 8, SEEK_SET);
00067 put_buffer(pb, streaminfo, FLAC_STREAMINFO_SIZE);
00068 url_fseek(pb, file_size, SEEK_SET);
00069 put_flush_packet(pb);
00070 } else {
00071 av_log(s, AV_LOG_WARNING, "unable to rewrite FLAC header.\n");
00072 }
00073 return 0;
00074 }
00075
00076 static int flac_write_packet(struct AVFormatContext *s, AVPacket *pkt)
00077 {
00078 put_buffer(s->pb, pkt->data, pkt->size);
00079 put_flush_packet(s->pb);
00080 return 0;
00081 }
00082
00083 AVOutputFormat flac_muxer = {
00084 "flac",
00085 NULL_IF_CONFIG_SMALL("raw FLAC"),
00086 "audio/x-flac",
00087 "flac",
00088 0,
00089 CODEC_ID_FLAC,
00090 CODEC_ID_NONE,
00091 flac_write_header,
00092 flac_write_packet,
00093 flac_write_trailer,
00094 .flags= AVFMT_NOTIMESTAMPS,
00095 };