Libav
eacdata.c
Go to the documentation of this file.
1 /*
2  * Electronic Arts .cdata file Demuxer
3  * Copyright (c) 2007 Peter Ross
4  *
5  * This file is part of Libav.
6  *
7  * Libav is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * Libav is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
31 #include "avformat.h"
32 #include "internal.h"
33 
34 typedef struct {
35  unsigned int channels;
36  unsigned int audio_pts;
38 
39 static int cdata_probe(AVProbeData *p)
40 {
41  const uint8_t *b = p->buf;
42 
43  if (b[0] == 0x04 && (b[1] == 0x00 || b[1] == 0x04 || b[1] == 0x0C))
44  return AVPROBE_SCORE_MAX/8;
45  return 0;
46 }
47 
49 {
50  CdataDemuxContext *cdata = s->priv_data;
51  AVIOContext *pb = s->pb;
52  unsigned int sample_rate, header;
53  AVStream *st;
54 
55  header = avio_rb16(pb);
56  switch (header) {
57  case 0x0400: cdata->channels = 1; break;
58  case 0x0404: cdata->channels = 2; break;
59  case 0x040C: cdata->channels = 4; break;
60  default:
61  av_log(s, AV_LOG_INFO, "unknown header 0x%04x\n", header);
62  return -1;
63  };
64 
65  sample_rate = avio_rb16(pb);
66  avio_skip(pb, 12);
67 
68  st = avformat_new_stream(s, NULL);
69  if (!st)
70  return AVERROR(ENOMEM);
72  st->codec->codec_tag = 0; /* no fourcc */
74  st->codec->channels = cdata->channels;
75  st->codec->sample_rate = sample_rate;
76  avpriv_set_pts_info(st, 64, 1, sample_rate);
77 
78  cdata->audio_pts = 0;
79  return 0;
80 }
81 
83 {
84  CdataDemuxContext *cdata = s->priv_data;
85  int packet_size = 76*cdata->channels;
86 
87  int ret = av_get_packet(s->pb, pkt, packet_size);
88  if (ret < 0)
89  return ret;
90  pkt->pts = cdata->audio_pts++;
91  return 0;
92 }
93 
95  .name = "ea_cdata",
96  .long_name = NULL_IF_CONFIG_SMALL("Electronic Arts cdata"),
97  .priv_data_size = sizeof(CdataDemuxContext),
101  .extensions = "cdata",
102 };
Bytestream IO Context.
Definition: avio.h:68
static int cdata_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: eacdata.c:82
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: utils.c:3208
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:574
Format I/O context.
Definition: avformat.h:871
uint8_t
#define b
Definition: input.c:52
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
Allocate and read the payload of a packet and initialize its fields with default values.
Definition: utils.c:118
unsigned int audio_pts
Definition: eacdata.c:36
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:142
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:148
AVStream * avformat_new_stream(AVFormatContext *s, AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:2662
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:702
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:390
static int read_probe(AVProbeData *pd)
Definition: jvdec.c:55
static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: avio.h:210
AVInputFormat ff_ea_cdata_demuxer
Definition: eacdata.c:94
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:536
Stream structure.
Definition: avformat.h:683
NULL
Definition: eval.c:55
#define AV_LOG_INFO
Standard information.
Definition: log.h:134
enum AVMediaType codec_type
Definition: avcodec.h:1062
enum AVCodecID codec_id
Definition: avcodec.h:1065
int sample_rate
samples per second
Definition: avcodec.h:1779
AVIOContext * pb
I/O context.
Definition: avformat.h:913
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:1080
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
Definition: libcdio.c:114
This structure contains the data a format has to probe a file.
Definition: avformat.h:388
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:395
Main libavformat public API header.
int channels
number of audio channels
Definition: avcodec.h:1780
unsigned int channels
Definition: eacdata.c:35
void * priv_data
Format private data.
Definition: avformat.h:899
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:516
static int cdata_probe(AVProbeData *p)
Definition: eacdata.c:39
This structure stores compressed data.
Definition: avcodec.h:950
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:966
static int cdata_read_header(AVFormatContext *s)
Definition: eacdata.c:48