Statistics
| Branch: | Revision:

ffmpeg / libavformat / oggparseskeleton.c @ 32ad8692

History | View | Annotate | Download (2.77 KB)

1
/*
2
 * Copyright (C) 2010 David Conrad
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
#include "libavcodec/bytestream.h"
22
#include "avformat.h"
23
#include "oggdec.h"
24

    
25
static int skeleton_header(AVFormatContext *s, int idx)
26
{
27
    struct ogg *ogg = s->priv_data;
28
    struct ogg_stream *os = ogg->streams + idx;
29
    AVStream *st = s->streams[idx];
30
    uint8_t *buf = os->buf + os->pstart;
31
    int version_major, version_minor;
32
    int64_t start_num, start_den, start_granule;
33
    int target_idx, start_time;
34

    
35
    strcpy(st->codec->codec_name, "skeleton");
36
    st->codec->codec_type = CODEC_TYPE_DATA;
37

    
38
    if (os->psize < 8)
39
        return -1;
40

    
41
    if (!strncmp(buf, "fishead", 8)) {
42
        if (os->psize < 64)
43
            return -1;
44

    
45
        version_major = AV_RL16(buf+8);
46
        version_minor = AV_RL16(buf+10);
47

    
48
        if (version_major != 3) {
49
            av_log(s, AV_LOG_WARNING, "Unknown skeleton version %d.%d\n",
50
                   version_major, version_minor);
51
            return -1;
52
        }
53

    
54
        // This is the overall start time. We use it for the start time of
55
        // of the skeleton stream since if left unset lavf assumes 0,
56
        // which we don't want since skeleton is timeless
57
        // FIXME: the real meaning of this field is "start playback at
58
        // this time which can be in the middle of a packet
59
        start_num = AV_RL64(buf+12);
60
        start_den = AV_RL64(buf+20);
61

    
62
        if (start_den) {
63
            av_reduce(&start_time, &st->time_base.den, start_num, start_den, INT_MAX);
64
            st->time_base.num = 1;
65
            st->start_time = start_time;
66
        }
67
    } else if (!strncmp(buf, "fisbone", 8)) {
68
        if (os->psize < 52)
69
            return -1;
70

    
71
        target_idx = ogg_find_stream(ogg, AV_RL32(buf+12));
72
        start_granule = AV_RL64(buf+36);
73
        if (target_idx >= 0 && start_granule != -1) {
74
            s->streams[target_idx]->start_time = ogg_gptopts(s, target_idx, start_granule, NULL);
75
        }
76
    }
77

    
78
    return 1;
79
}
80

    
81
const struct ogg_codec ff_skeleton_codec = {
82
    .magic = "fishead",
83
    .magicsize = 8,
84
    .header = skeleton_header,
85
};