• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavformat/flacenc.c

Go to the documentation of this file.
00001 /*
00002  * raw FLAC muxer
00003  * Copyright (c) 2006-2009 Justin Ruggles
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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     /* write "fLaC" stream marker and first metadata block header if needed */
00038     if (format == FLAC_EXTRADATA_FORMAT_STREAMINFO) {
00039         put_buffer(pb, header, 8);
00040     }
00041 
00042     /* write STREAMINFO or full header */
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         /* rewrite the STREAMINFO header block data */
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 };

Generated on Tue Nov 4 2014 12:59:21 for ffmpeg by  doxygen 1.7.1