FFmpeg
Main Page
Related Pages
Modules
Namespaces
Data Structures
Files
Examples
File List
Globals
•
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
libavformat
adxdec.c
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2011 Justin Ruggles
3
*
4
* This file is part of FFmpeg.
5
*
6
* FFmpeg is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Lesser General Public
8
* License as published by the Free Software Foundation; either
9
* version 2.1 of the License, or (at your option) any later version.
10
*
11
* FFmpeg is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Lesser General Public License for more details.
15
*
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with FFmpeg; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
*/
20
21
/**
22
* @file
23
* CRI ADX demuxer
24
*/
25
26
#include "
libavutil/intreadwrite.h
"
27
#include "
libavcodec/adx.h
"
28
#include "
avformat.h
"
29
#include "
internal.h
"
30
31
#define BLOCK_SIZE 18
32
#define BLOCK_SAMPLES 32
33
34
typedef
struct
ADXDemuxerContext
{
35
int
header_size
;
36
}
ADXDemuxerContext
;
37
38
static
int
adx_read_packet
(
AVFormatContext
*
s
,
AVPacket
*
pkt
)
39
{
40
ADXDemuxerContext
*
c
= s->
priv_data
;
41
AVCodecContext
*avctx = s->
streams
[0]->
codec
;
42
int
ret
,
size
;
43
44
size =
BLOCK_SIZE
* avctx->
channels
;
45
46
pkt->
pos
=
avio_tell
(s->
pb
);
47
pkt->
stream_index
= 0;
48
49
ret =
av_get_packet
(s->
pb
, pkt, size);
50
if
(ret != size) {
51
av_free_packet
(pkt);
52
return
ret < 0 ? ret :
AVERROR
(EIO);
53
}
54
if
(
AV_RB16
(pkt->
data
) & 0x8000) {
55
av_free_packet
(pkt);
56
return
AVERROR_EOF
;
57
}
58
pkt->
size
=
size
;
59
pkt->
duration
= 1;
60
pkt->
pts
= (pkt->
pos
- c->
header_size
) / size;
61
62
return
0;
63
}
64
65
static
int
adx_read_header
(
AVFormatContext
*
s
)
66
{
67
ADXDemuxerContext
*
c
= s->
priv_data
;
68
AVCodecContext
*avctx;
69
int
ret
;
70
71
AVStream
*st =
avformat_new_stream
(s, NULL);
72
if
(!st)
73
return
AVERROR
(ENOMEM);
74
avctx = s->
streams
[0]->
codec
;
75
76
if
(
avio_rb16
(s->
pb
) != 0x8000)
77
return
AVERROR_INVALIDDATA
;
78
c->
header_size
=
avio_rb16
(s->
pb
) + 4;
79
avio_seek
(s->
pb
, -4, SEEK_CUR);
80
81
if
(
ff_get_extradata
(avctx, s->
pb
, c->
header_size
) < 0)
82
return
AVERROR
(ENOMEM);
83
84
ret =
avpriv_adx_decode_header
(avctx, avctx->
extradata
,
85
avctx->
extradata_size
, &c->
header_size
,
86
NULL);
87
if
(ret)
88
return
ret
;
89
90
st->
codec
->
codec_type
=
AVMEDIA_TYPE_AUDIO
;
91
st->
codec
->
codec_id
= s->
iformat
->
raw_codec_id
;
92
93
avpriv_set_pts_info
(st, 64,
BLOCK_SAMPLES
, avctx->
sample_rate
);
94
95
return
0;
96
}
97
98
AVInputFormat
ff_adx_demuxer
= {
99
.
name
=
"adx"
,
100
.long_name =
NULL_IF_CONFIG_SMALL
(
"CRI ADX"
),
101
.priv_data_size =
sizeof
(
ADXDemuxerContext
),
102
.
read_header
=
adx_read_header
,
103
.
read_packet
=
adx_read_packet
,
104
.extensions =
"adx"
,
105
.raw_codec_id =
AV_CODEC_ID_ADPCM_ADX
,
106
.
flags
=
AVFMT_GENERIC_INDEX
,
107
};
Generated on Sun Mar 23 2014 23:49:51 for FFmpeg by
1.8.2