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 = avformat_new_stream(s, NULL);
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 .name = "daud",
00075 .long_name = NULL_IF_CONFIG_SMALL("D-Cinema audio format"),
00076 .read_header = daud_header,
00077 .read_packet = daud_packet,
00078 .extensions = "302",
00079 };
00080 #endif
00081
00082 #if CONFIG_DAUD_MUXER
00083 AVOutputFormat ff_daud_muxer = {
00084 .name = "daud",
00085 .long_name = NULL_IF_CONFIG_SMALL("D-Cinema audio format"),
00086 .extensions = "302",
00087 .audio_codec = CODEC_ID_PCM_S24DAUD,
00088 .video_codec = CODEC_ID_NONE,
00089 .write_header = daud_write_header,
00090 .write_packet = daud_write_packet,
00091 .flags = AVFMT_NOTIMESTAMPS,
00092 };
00093 #endif