~ubuntu-branches/ubuntu/vivid/ffmpeg/vivid

« back to all changes in this revision

Viewing changes to libavformat/rpl.c

  • Committer: Package Import Robot
  • Author(s): Andreas Cadhalpun
  • Date: 2014-11-05 01:18:23 UTC
  • mfrom: (0.2.17 sid)
  • Revision ID: package-import@ubuntu.com-20141105011823-xsbeceffs43wtkn7
Tags: 7:2.4.3-1
* Import new upstream bugfix release 2.4.3.
   - Refresh Change-symbol-versioning.patch.
   - Add new symbols to the libavdevice symbols file.
* Enable libbs2b on arm64, since it is now available.
* Disable frei0r and libx264 on x32, libsoxr and openal on sparc64
  and libopencv on m68k, sh4, sparc64 and x32, because they are not
  (yet) avialable there.
* Disable assembler optimizations on x32, as they wouldn't work there.
* Include config.log in the build-log, when compiling fails.
* Add fix-hppa-tests.patch to work around a gcc bug on hppa.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
20
 */
21
21
 
 
22
#include <inttypes.h>
 
23
#include <stdlib.h>
 
24
 
22
25
#include "libavutil/avstring.h"
 
26
#include "libavutil/dict.h"
23
27
#include "avformat.h"
24
 
#include <stdlib.h>
 
28
#include "internal.h"
25
29
 
26
30
#define RPL_SIGNATURE "ARMovie\x0A"
27
31
#define RPL_SIGNATURE_SIZE 8
47
51
    uint32_t frame_in_part;
48
52
} RPLContext;
49
53
 
50
 
static int read_line(ByteIOContext * pb, char* line, int bufsize)
 
54
static int read_line(AVIOContext * pb, char* line, int bufsize)
51
55
{
52
56
    int i;
53
57
    for (i = 0; i < bufsize - 1; i++) {
54
 
        int b = get_byte(pb);
 
58
        int b = avio_r8(pb);
55
59
        if (b == 0)
56
60
            break;
57
61
        if (b == '\n') {
58
62
            line[i] = '\0';
59
 
            return 0;
 
63
            return avio_feof(pb) ? -1 : 0;
60
64
        }
61
65
        line[i] = b;
62
66
    }
76
80
    return result;
77
81
}
78
82
 
79
 
static int32_t read_line_and_int(ByteIOContext * pb, int* error)
 
83
static int32_t read_line_and_int(AVIOContext * pb, int* error)
80
84
{
81
85
    char line[RPL_LINE_LENGTH];
82
86
    const char *endptr;
108
112
    return result;
109
113
}
110
114
 
111
 
static int rpl_read_header(AVFormatContext *s, AVFormatParameters *ap)
 
115
static int rpl_read_header(AVFormatContext *s)
112
116
{
113
 
    ByteIOContext *pb = s->pb;
 
117
    AVIOContext *pb = s->pb;
114
118
    RPLContext *rpl = s->priv_data;
115
119
    AVStream *vst = NULL, *ast = NULL;
116
120
    int total_audio_size;
131
135
    // for the text in a few cases; samples needed.)
132
136
    error |= read_line(pb, line, sizeof(line));      // ARMovie
133
137
    error |= read_line(pb, line, sizeof(line));      // movie name
134
 
    av_metadata_set2(&s->metadata, "title"    , line, 0);
 
138
    av_dict_set(&s->metadata, "title"    , line, 0);
135
139
    error |= read_line(pb, line, sizeof(line));      // date/copyright
136
 
    av_metadata_set2(&s->metadata, "copyright", line, 0);
 
140
    av_dict_set(&s->metadata, "copyright", line, 0);
137
141
    error |= read_line(pb, line, sizeof(line));      // author and other
138
 
    av_metadata_set2(&s->metadata, "author"   , line, 0);
 
142
    av_dict_set(&s->metadata, "author"   , line, 0);
139
143
 
140
144
    // video headers
141
 
    vst = av_new_stream(s, 0);
 
145
    vst = avformat_new_stream(s, NULL);
142
146
    if (!vst)
143
147
        return AVERROR(ENOMEM);
144
148
    vst->codec->codec_type      = AVMEDIA_TYPE_VIDEO;
148
152
    vst->codec->bits_per_coded_sample = read_line_and_int(pb, &error);  // video bits per sample
149
153
    error |= read_line(pb, line, sizeof(line));                   // video frames per second
150
154
    fps = read_fps(line, &error);
151
 
    av_set_pts_info(vst, 32, fps.den, fps.num);
 
155
    avpriv_set_pts_info(vst, 32, fps.den, fps.num);
152
156
 
153
157
    // Figure out the video codec
154
158
    switch (vst->codec->codec_tag) {
155
159
#if 0
156
160
        case 122:
157
 
            vst->codec->codec_id = CODEC_ID_ESCAPE122;
 
161
            vst->codec->codec_id = AV_CODEC_ID_ESCAPE122;
158
162
            break;
159
163
#endif
160
164
        case 124:
161
 
            vst->codec->codec_id = CODEC_ID_ESCAPE124;
 
165
            vst->codec->codec_id = AV_CODEC_ID_ESCAPE124;
162
166
            // The header is wrong here, at least sometimes
163
167
            vst->codec->bits_per_coded_sample = 16;
164
168
            break;
165
 
#if 0
166
169
        case 130:
167
 
            vst->codec->codec_id = CODEC_ID_ESCAPE130;
 
170
            vst->codec->codec_id = AV_CODEC_ID_ESCAPE130;
168
171
            break;
169
 
#endif
170
172
        default:
171
 
            av_log(s, AV_LOG_WARNING,
172
 
                   "RPL video format %i not supported yet!\n",
173
 
                   vst->codec->codec_tag);
174
 
            vst->codec->codec_id = CODEC_ID_NONE;
 
173
            avpriv_report_missing_feature(s, "Video format %i",
 
174
                                          vst->codec->codec_tag);
 
175
            vst->codec->codec_id = AV_CODEC_ID_NONE;
175
176
    }
176
177
 
177
178
    // Audio headers
180
181
    // samples, though. This code will ignore additional tracks.
181
182
    audio_format = read_line_and_int(pb, &error);  // audio format ID
182
183
    if (audio_format) {
183
 
        ast = av_new_stream(s, 0);
 
184
        ast = avformat_new_stream(s, NULL);
184
185
        if (!ast)
185
186
            return AVERROR(ENOMEM);
186
187
        ast->codec->codec_type      = AVMEDIA_TYPE_AUDIO;
197
198
                               ast->codec->bits_per_coded_sample *
198
199
                               ast->codec->channels;
199
200
 
200
 
        ast->codec->codec_id = CODEC_ID_NONE;
 
201
        ast->codec->codec_id = AV_CODEC_ID_NONE;
201
202
        switch (audio_format) {
202
203
            case 1:
203
204
                if (ast->codec->bits_per_coded_sample == 16) {
204
205
                    // 16-bit audio is always signed
205
 
                    ast->codec->codec_id = CODEC_ID_PCM_S16LE;
 
206
                    ast->codec->codec_id = AV_CODEC_ID_PCM_S16LE;
206
207
                    break;
207
208
                }
208
209
                // There are some other formats listed as legal per the spec;
212
213
                if (ast->codec->bits_per_coded_sample == 8) {
213
214
                    // The samples with this kind of audio that I have
214
215
                    // are all unsigned.
215
 
                    ast->codec->codec_id = CODEC_ID_PCM_U8;
 
216
                    ast->codec->codec_id = AV_CODEC_ID_PCM_U8;
216
217
                    break;
217
218
                } else if (ast->codec->bits_per_coded_sample == 4) {
218
 
                    ast->codec->codec_id = CODEC_ID_ADPCM_IMA_EA_SEAD;
 
219
                    ast->codec->codec_id = AV_CODEC_ID_ADPCM_IMA_EA_SEAD;
219
220
                    break;
220
221
                }
221
222
                break;
222
223
        }
223
 
        if (ast->codec->codec_id == CODEC_ID_NONE) {
224
 
            av_log(s, AV_LOG_WARNING,
225
 
                   "RPL audio format %i not supported yet!\n",
226
 
                   audio_format);
227
 
        }
228
 
        av_set_pts_info(ast, 32, 1, ast->codec->bit_rate);
 
224
        if (ast->codec->codec_id == AV_CODEC_ID_NONE)
 
225
            avpriv_request_sample(s, "Audio format %"PRId32,
 
226
                                  audio_format);
 
227
        avpriv_set_pts_info(ast, 32, 1, ast->codec->bit_rate);
229
228
    } else {
230
229
        for (i = 0; i < 3; i++)
231
230
            error |= read_line(pb, line, sizeof(line));
250
249
    error |= read_line(pb, line, sizeof(line));  // offset to key frame list
251
250
 
252
251
    // Read the index
253
 
    url_fseek(pb, chunk_catalog_offset, SEEK_SET);
 
252
    avio_seek(pb, chunk_catalog_offset, SEEK_SET);
254
253
    total_audio_size = 0;
255
 
    for (i = 0; i < number_of_chunks; i++) {
 
254
    for (i = 0; !error && i < number_of_chunks; i++) {
256
255
        int64_t offset, video_size, audio_size;
257
256
        error |= read_line(pb, line, sizeof(line));
258
 
        if (3 != sscanf(line, "%"PRId64" , %"PRId64" ; %"PRId64,
259
 
                        &offset, &video_size, &audio_size))
 
257
        if (3 != sscanf(line, "%"SCNd64" , %"SCNd64" ; %"SCNd64,
 
258
                        &offset, &video_size, &audio_size)) {
260
259
            error = -1;
 
260
            continue;
 
261
        }
261
262
        av_add_index_entry(vst, offset, i * rpl->frames_per_chunk,
262
263
                           video_size, rpl->frames_per_chunk, 0);
263
264
        if (ast)
274
275
static int rpl_read_packet(AVFormatContext *s, AVPacket *pkt)
275
276
{
276
277
    RPLContext *rpl = s->priv_data;
277
 
    ByteIOContext *pb = s->pb;
 
278
    AVIOContext *pb = s->pb;
278
279
    AVStream* stream;
279
280
    AVIndexEntry* index_entry;
280
281
    uint32_t ret;
287
288
    stream = s->streams[rpl->chunk_part];
288
289
 
289
290
    if (rpl->chunk_number >= stream->nb_index_entries)
290
 
        return -1;
 
291
        return AVERROR_EOF;
291
292
 
292
293
    index_entry = &stream->index_entries[rpl->chunk_number];
293
294
 
294
295
    if (rpl->frame_in_part == 0)
295
 
        if (url_fseek(pb, index_entry->pos, SEEK_SET) < 0)
 
296
        if (avio_seek(pb, index_entry->pos, SEEK_SET) < 0)
296
297
            return AVERROR(EIO);
297
298
 
298
299
    if (stream->codec->codec_type == AVMEDIA_TYPE_VIDEO &&
299
300
        stream->codec->codec_tag == 124) {
300
301
        // We have to split Escape 124 frames because there are
301
302
        // multiple frames per chunk in Escape 124 samples.
302
 
        uint32_t frame_size, frame_flags;
 
303
        uint32_t frame_size;
303
304
 
304
 
        frame_flags = get_le32(pb);
305
 
        frame_size = get_le32(pb);
306
 
        if (url_fseek(pb, -8, SEEK_CUR) < 0)
 
305
        avio_skip(pb, 4); /* flags */
 
306
        frame_size = avio_rl32(pb);
 
307
        if (avio_seek(pb, -8, SEEK_CUR) < 0)
307
308
            return AVERROR(EIO);
308
309
 
309
310
        ret = av_get_packet(pb, pkt, frame_size);
349
350
    return ret;
350
351
}
351
352
 
352
 
AVInputFormat rpl_demuxer = {
353
 
    "rpl",
354
 
    NULL_IF_CONFIG_SMALL("RPL/ARMovie format"),
355
 
    sizeof(RPLContext),
356
 
    rpl_probe,
357
 
    rpl_read_header,
358
 
    rpl_read_packet,
 
353
AVInputFormat ff_rpl_demuxer = {
 
354
    .name           = "rpl",
 
355
    .long_name      = NULL_IF_CONFIG_SMALL("RPL / ARMovie"),
 
356
    .priv_data_size = sizeof(RPLContext),
 
357
    .read_probe     = rpl_probe,
 
358
    .read_header    = rpl_read_header,
 
359
    .read_packet    = rpl_read_packet,
359
360
};