Libav
|
00001 /* 00002 * D-Cinema audio demuxer 00003 * Copyright (c) 2005 Reimar Döffinger 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 #include "avformat.h" 00022 00023 static int daud_header(AVFormatContext *s, AVFormatParameters *ap) { 00024 AVStream *st = av_new_stream(s, 0); 00025 if (!st) 00026 return AVERROR(ENOMEM); 00027 st->codec->codec_type = AVMEDIA_TYPE_AUDIO; 00028 st->codec->codec_id = CODEC_ID_PCM_S24DAUD; 00029 st->codec->codec_tag = MKTAG('d', 'a', 'u', 'd'); 00030 st->codec->channels = 6; 00031 st->codec->sample_rate = 96000; 00032 st->codec->bit_rate = 3 * 6 * 96000 * 8; 00033 st->codec->block_align = 3 * 6; 00034 st->codec->bits_per_coded_sample = 24; 00035 return 0; 00036 } 00037 00038 static int daud_packet(AVFormatContext *s, AVPacket *pkt) { 00039 ByteIOContext *pb = s->pb; 00040 int ret, size; 00041 if (url_feof(pb)) 00042 return AVERROR(EIO); 00043 size = get_be16(pb); 00044 get_be16(pb); // unknown 00045 ret = av_get_packet(pb, pkt, size); 00046 pkt->stream_index = 0; 00047 return ret; 00048 } 00049 00050 static int daud_write_header(struct AVFormatContext *s) 00051 { 00052 AVCodecContext *codec = s->streams[0]->codec; 00053 if (codec->channels!=6 || codec->sample_rate!=96000) 00054 return -1; 00055 return 0; 00056 } 00057 00058 static int daud_write_packet(struct AVFormatContext *s, AVPacket *pkt) 00059 { 00060 put_be16(s->pb, pkt->size); 00061 put_be16(s->pb, 0x8010); // unknown 00062 put_buffer(s->pb, pkt->data, pkt->size); 00063 put_flush_packet(s->pb); 00064 return 0; 00065 } 00066 00067 #if CONFIG_DAUD_DEMUXER 00068 AVInputFormat daud_demuxer = { 00069 "daud", 00070 NULL_IF_CONFIG_SMALL("D-Cinema audio format"), 00071 0, 00072 NULL, 00073 daud_header, 00074 daud_packet, 00075 NULL, 00076 NULL, 00077 .extensions = "302", 00078 }; 00079 #endif 00080 00081 #if CONFIG_DAUD_MUXER 00082 AVOutputFormat daud_muxer = 00083 { 00084 "daud", 00085 NULL_IF_CONFIG_SMALL("D-Cinema audio format"), 00086 NULL, 00087 "302", 00088 0, 00089 CODEC_ID_PCM_S24DAUD, 00090 CODEC_ID_NONE, 00091 daud_write_header, 00092 daud_write_packet, 00093 .flags= AVFMT_NOTIMESTAMPS, 00094 }; 00095 #endif