00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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 AVIOContext *pb = s->pb;
00040 int ret, size;
00041 if (url_feof(pb))
00042 return AVERROR(EIO);
00043 size = avio_rb16(pb);
00044 avio_rb16(pb);
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 if (pkt->size > 65535) {
00061 av_log(s, AV_LOG_ERROR,
00062 "Packet size too large for s302m. (%d > 65535)\n", pkt->size);
00063 return -1;
00064 }
00065 avio_wb16(s->pb, pkt->size);
00066 avio_wb16(s->pb, 0x8010);
00067 avio_write(s->pb, pkt->data, pkt->size);
00068 avio_flush(s->pb);
00069 return 0;
00070 }
00071
00072 #if CONFIG_DAUD_DEMUXER
00073 AVInputFormat ff_daud_demuxer = {
00074 "daud",
00075 NULL_IF_CONFIG_SMALL("D-Cinema audio format"),
00076 0,
00077 NULL,
00078 daud_header,
00079 daud_packet,
00080 NULL,
00081 NULL,
00082 .extensions = "302",
00083 };
00084 #endif
00085
00086 #if CONFIG_DAUD_MUXER
00087 AVOutputFormat ff_daud_muxer =
00088 {
00089 "daud",
00090 NULL_IF_CONFIG_SMALL("D-Cinema audio format"),
00091 NULL,
00092 "302",
00093 0,
00094 CODEC_ID_PCM_S24DAUD,
00095 CODEC_ID_NONE,
00096 daud_write_header,
00097 daud_write_packet,
00098 .flags= AVFMT_NOTIMESTAMPS,
00099 };
00100 #endif