FFmpeg
Loading...
Searching...
No Matches
act.c
Go to the documentation of this file.
1/*
2 * ACT file format demuxer
3 * Copyright (c) 2007-2008 Vladimir Voroshilov
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg 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 * FFmpeg 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 FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
23#include "avformat.h"
24#include "avio_internal.h"
25#include "demux.h"
26#include "riff.h"
27#include "internal.h"
28
29#define CHUNK_SIZE 512
30#define RIFF_TAG MKTAG('R','I','F','F')
31#define WAVE_TAG MKTAG('W','A','V','E')
32
33typedef struct{
35 uint8_t audio_buffer[22];///< temporary buffer for ACT frame
36 char second_packet; ///< 1 - if temporary buffer contains valid (second) G.729 packet
38
39static int probe(const AVProbeData *p)
40{
41 int i;
42
43 if ((AV_RL32(&p->buf[0]) != RIFF_TAG) ||
44 (AV_RL32(&p->buf[8]) != WAVE_TAG) ||
45 (AV_RL32(&p->buf[16]) != 16))
46 return 0;
47
48 //We can't be sure that this is ACT and not regular WAV
49 if (p->buf_size<512)
50 return 0;
51
52 for(i=44; i<256; i++)
53 if(p->buf[i])
54 return 0;
55
56 if(p->buf[256]!=0x84)
57 return 0;
58
59 for(i=264; i<512; i++)
60 if(p->buf[i])
61 return 0;
62
63 return AVPROBE_SCORE_MAX;
64}
65
67{
68 ACTContext* ctx = s->priv_data;
69 AVIOContext *pb = s->pb;
70 int size;
71 AVStream* st;
72 int ret;
73
74 int min,sec,msec;
75
77 if (!st)
78 return AVERROR(ENOMEM);
79
80 avio_skip(pb, 16);
81 size=avio_rl32(pb);
82 ret = ff_get_wav_header(s, pb, st->codecpar, size, 0);
83 if (ret < 0)
84 return ret;
85
86 /*
87 8000Hz (Fine-rec) file format has 10 bytes long
88 packets with 10ms of sound data in them
89 */
90 if (st->codecpar->sample_rate != 8000) {
91 av_log(s, AV_LOG_ERROR, "Sample rate %d is not supported.\n", st->codecpar->sample_rate);
93 }
94
95 st->codecpar->frame_size=80;
97 avpriv_set_pts_info(st, 64, 1, 100);
98
100
101 avio_seek(pb, 257, SEEK_SET);
102 msec=avio_rl16(pb);
103 sec=avio_r8(pb);
104 min=avio_rl32(pb);
105
106 st->duration = av_rescale(1000*(min*60+sec)+msec, st->codecpar->sample_rate, 1000 * st->codecpar->frame_size);
107
108 ctx->bytes_left_in_chunk=CHUNK_SIZE;
109
110 avio_seek(pb, 512, SEEK_SET);
111
112 return 0;
113}
114
115
117 AVPacket *pkt)
118{
119 ACTContext *ctx = s->priv_data;
120 AVIOContext *pb = s->pb;
121 int ret;
122 int frame_size=s->streams[0]->codecpar->sample_rate==8000?10:22;
123
124
125 if(s->streams[0]->codecpar->sample_rate==8000)
126 ret=av_new_packet(pkt, 10);
127 else
128 ret=av_new_packet(pkt, 11);
129
130 if(ret)
131 return ret;
132
133 if(s->streams[0]->codecpar->sample_rate==4400 && !ctx->second_packet)
134 {
135 ret = ffio_read_size(pb, ctx->audio_buffer, frame_size);
136
137 if(ret<0)
138 return ret;
139
140 pkt->data[0]=ctx->audio_buffer[11];
141 pkt->data[1]=ctx->audio_buffer[0];
142 pkt->data[2]=ctx->audio_buffer[12];
143 pkt->data[3]=ctx->audio_buffer[1];
144 pkt->data[4]=ctx->audio_buffer[13];
145 pkt->data[5]=ctx->audio_buffer[2];
146 pkt->data[6]=ctx->audio_buffer[14];
147 pkt->data[7]=ctx->audio_buffer[3];
148 pkt->data[8]=ctx->audio_buffer[15];
149 pkt->data[9]=ctx->audio_buffer[4];
150 pkt->data[10]=ctx->audio_buffer[16];
151
152 ctx->second_packet=1;
153 }
154 else if(s->streams[0]->codecpar->sample_rate==4400 && ctx->second_packet)
155 {
156 pkt->data[0]=ctx->audio_buffer[5];
157 pkt->data[1]=ctx->audio_buffer[17];
158 pkt->data[2]=ctx->audio_buffer[6];
159 pkt->data[3]=ctx->audio_buffer[18];
160 pkt->data[4]=ctx->audio_buffer[7];
161 pkt->data[5]=ctx->audio_buffer[19];
162 pkt->data[6]=ctx->audio_buffer[8];
163 pkt->data[7]=ctx->audio_buffer[20];
164 pkt->data[8]=ctx->audio_buffer[9];
165 pkt->data[9]=ctx->audio_buffer[21];
166 pkt->data[10]=ctx->audio_buffer[10];
167
168 ctx->second_packet=0;
169 }
170 else // 8000 Hz
171 {
172 ret = ffio_read_size(pb, ctx->audio_buffer, frame_size);
173
174 if(ret<0)
175 return ret;
176
177 pkt->data[0]=ctx->audio_buffer[5];
178 pkt->data[1]=ctx->audio_buffer[0];
179 pkt->data[2]=ctx->audio_buffer[6];
180 pkt->data[3]=ctx->audio_buffer[1];
181 pkt->data[4]=ctx->audio_buffer[7];
182 pkt->data[5]=ctx->audio_buffer[2];
183 pkt->data[6]=ctx->audio_buffer[8];
184 pkt->data[7]=ctx->audio_buffer[3];
185 pkt->data[8]=ctx->audio_buffer[9];
186 pkt->data[9]=ctx->audio_buffer[4];
187 }
188
189 ctx->bytes_left_in_chunk -= frame_size;
190
191 if(ctx->bytes_left_in_chunk < frame_size)
192 {
193 avio_skip(pb, ctx->bytes_left_in_chunk);
194 ctx->bytes_left_in_chunk=CHUNK_SIZE;
195 }
196
197 pkt->duration=1;
198
199 return ret;
200}
201
203 .p.name = "act",
204 .p.long_name = "ACT Voice file format",
205 .priv_data_size = sizeof(ACTContext),
206 .read_probe = probe,
209};
const FFInputFormat ff_act_demuxer
Definition act.c:202
static int read_packet(AVFormatContext *s, AVPacket *pkt)
Definition act.c:116
#define WAVE_TAG
Definition act.c:31
static int read_header(AVFormatContext *s)
Definition act.c:66
#define CHUNK_SIZE
Definition act.c:29
static int probe(const AVProbeData *p)
Definition act.c:39
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition avformat.c:834
Main libavformat public API header.
#define AVPROBE_SCORE_MAX
maximum score
Definition avformat.h:483
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition aviobuf.c:236
unsigned int avio_rl16(AVIOContext *s)
Definition aviobuf.c:717
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition aviobuf.c:321
unsigned int avio_rl32(AVIOContext *s)
Definition aviobuf.c:733
int avio_r8(AVIOContext *s)
Definition aviobuf.c:606
int ffio_read_size(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition aviobuf.c:665
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
static int read_probe(const AVProbeData *p)
Definition cdg.c:30
#define NULL
Definition coverity.c:32
#define min(a, b)
static AVPacket * pkt
static int read_header(FFV1Context *f, RangeCoder *c)
Definition ffv1dec.c:578
static const uint8_t frame_size[4]
Definition g723_1.h:222
@ AV_CODEC_ID_G729
Definition codec_id.h:506
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition packet.c:98
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
#define AV_RL32(p)
#define RIFF_TAG
Definition 4xm.c:39
internal header for RIFF based (de)muxers do NOT include this in end user applications
int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par, int size, int big_endian)
Definition riffdec.c:141
char second_packet
1 - if temporary buffer contains valid (second) G.729 packet
Definition act.c:36
int bytes_left_in_chunk
Definition act.c:34
uint8_t audio_buffer[22]
temporary buffer for ACT frame
Definition act.c:35
int nb_channels
Number of channels in this layout.
int frame_size
Audio frame size, if known.
Definition codec_par.h:227
AVChannelLayout ch_layout
The channel layout and number of channels.
Definition codec_par.h:207
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition codec_par.h:57
int sample_rate
The number of audio samples per second.
Definition codec_par.h:213
Format I/O context.
Definition avformat.h:1333
Bytestream IO Context.
Definition avio.h:160
This structure stores compressed data.
Definition packet.h:580
This structure contains the data a format has to probe a file.
Definition avformat.h:471
Stream structure.
Definition avformat.h:766
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:789
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition avformat.h:825
#define av_log(a,...)
static AVFormatContext * ctx
Definition movenc.c:49
int size