utvideoenc: optimize and simplify mangle_rgb_planes
[ffmpeg.git] / libavformat / eacdata.c
index 809b190..be31d00 100644 (file)
@@ -29,6 +29,7 @@
  */
 
 #include "avformat.h"
+#include "internal.h"
 
 typedef struct {
   unsigned int channels;
@@ -39,40 +40,44 @@ static int cdata_probe(AVProbeData *p)
 {
     const uint8_t *b = p->buf;
 
-    if (b[0] == 0x04 && (b[1] == 0x00 || b[1] == 0x04 || b[1] == 0x0C))
+    if (b[0] == 0x04 && (b[1] == 0x00 || b[1] == 0x04 || b[1] == 0x0C || b[1] == 0x14))
         return AVPROBE_SCORE_MAX/8;
     return 0;
 }
 
-static int cdata_read_header(AVFormatContext *s, AVFormatParameters *ap)
+static int cdata_read_header(AVFormatContext *s)
 {
     CdataDemuxContext *cdata = s->priv_data;
-    ByteIOContext *pb = s->pb;
+    AVIOContext *pb = s->pb;
     unsigned int sample_rate, header;
     AVStream *st;
+    int64_t channel_layout = 0;
 
-    header = get_be16(pb);
+    header = avio_rb16(pb);
     switch (header) {
         case 0x0400: cdata->channels = 1; break;
         case 0x0404: cdata->channels = 2; break;
-        case 0x040C: cdata->channels = 4; break;
+        case 0x040C: cdata->channels = 4; channel_layout = AV_CH_LAYOUT_QUAD;         break;
+        case 0x0414: cdata->channels = 6; channel_layout = AV_CH_LAYOUT_5POINT1_BACK; break;
         default:
             av_log(s, AV_LOG_INFO, "unknown header 0x%04x\n", header);
             return -1;
     };
 
-    sample_rate = get_be16(pb);
-    url_fskip(pb, 12);
+    sample_rate = avio_rb16(pb);
+    avio_skip(pb, (avio_r8(pb) & 0x20) ? 15 : 11);
 
-    st = av_new_stream(s, 0);
+    st = avformat_new_stream(s, NULL);
     if (!st)
         return AVERROR(ENOMEM);
     st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
     st->codec->codec_tag = 0; /* no fourcc */
-    st->codec->codec_id = CODEC_ID_ADPCM_EA_XAS;
+    st->codec->codec_id = AV_CODEC_ID_ADPCM_EA_XAS;
     st->codec->channels = cdata->channels;
+    st->codec->channel_layout = channel_layout;
     st->codec->sample_rate = sample_rate;
-    av_set_pts_info(st, 64, 1, sample_rate);
+    st->codec->sample_fmt = AV_SAMPLE_FMT_S16;
+    avpriv_set_pts_info(st, 64, 1, sample_rate);
 
     cdata->audio_pts = 0;
     return 0;
@@ -91,11 +96,11 @@ static int cdata_read_packet(AVFormatContext *s, AVPacket *pkt)
 }
 
 AVInputFormat ff_ea_cdata_demuxer = {
-    "ea_cdata",
-    NULL_IF_CONFIG_SMALL("Electronic Arts cdata"),
-    sizeof(CdataDemuxContext),
-    cdata_probe,
-    cdata_read_header,
-    cdata_read_packet,
+    .name           = "ea_cdata",
+    .long_name      = NULL_IF_CONFIG_SMALL("Electronic Arts cdata"),
+    .priv_data_size = sizeof(CdataDemuxContext),
+    .read_probe     = cdata_probe,
+    .read_header    = cdata_read_header,
+    .read_packet    = cdata_read_packet,
     .extensions = "cdata",
 };