~ubuntu-branches/ubuntu/saucy/gst-libav1.0/saucy-proposed

« back to all changes in this revision

Viewing changes to gst-libs/ext/libav/libavformat/rawvideodec.c

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2013-07-30 09:00:15 UTC
  • mfrom: (1.1.16) (7.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20130730090015-sc1ou2yssu7q5w4e
Tags: 1.1.3-1
* New upstream development snapshot:
  + debian/control:
    - Build depend on GStreamer and gst-plugins-base >= 1.1.3.

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 "libavutil/parseutils.h"
 
23
#include "libavutil/pixdesc.h"
 
24
#include "libavutil/opt.h"
 
25
#include "internal.h"
22
26
#include "avformat.h"
23
 
#include "rawdec.h"
 
27
 
 
28
typedef struct RawVideoDemuxerContext {
 
29
    const AVClass *class;     /**< Class for private options. */
 
30
    char *video_size;         /**< String describing video size, set by a private option. */
 
31
    char *pixel_format;       /**< Set by a private option. */
 
32
    char *framerate;          /**< String describing framerate, set by a private option. */
 
33
} RawVideoDemuxerContext;
 
34
 
 
35
 
 
36
static int rawvideo_read_header(AVFormatContext *ctx)
 
37
{
 
38
    RawVideoDemuxerContext *s = ctx->priv_data;
 
39
    int width = 0, height = 0, ret = 0;
 
40
    enum AVPixelFormat pix_fmt;
 
41
    AVRational framerate;
 
42
    AVStream *st;
 
43
 
 
44
    st = avformat_new_stream(ctx, NULL);
 
45
    if (!st)
 
46
        return AVERROR(ENOMEM);
 
47
 
 
48
    st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
 
49
 
 
50
    st->codec->codec_id = ctx->iformat->raw_codec_id;
 
51
 
 
52
    if (s->video_size &&
 
53
        (ret = av_parse_video_size(&width, &height, s->video_size)) < 0) {
 
54
        av_log(ctx, AV_LOG_ERROR, "Couldn't parse video size.\n");
 
55
        return ret;
 
56
    }
 
57
 
 
58
    if ((pix_fmt = av_get_pix_fmt(s->pixel_format)) == AV_PIX_FMT_NONE) {
 
59
        av_log(ctx, AV_LOG_ERROR, "No such pixel format: %s.\n",
 
60
               s->pixel_format);
 
61
        return AVERROR(EINVAL);
 
62
    }
 
63
 
 
64
    if ((ret = av_parse_video_rate(&framerate, s->framerate)) < 0) {
 
65
        av_log(ctx, AV_LOG_ERROR, "Could not parse framerate: %s.\n",
 
66
               s->framerate);
 
67
        return ret;
 
68
    }
 
69
 
 
70
    avpriv_set_pts_info(st, 64, framerate.den, framerate.num);
 
71
 
 
72
    st->codec->width  = width;
 
73
    st->codec->height = height;
 
74
    st->codec->pix_fmt = pix_fmt;
 
75
 
 
76
    return 0;
 
77
}
 
78
 
24
79
 
25
80
static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
26
81
{
34
89
    if (packet_size < 0)
35
90
        return -1;
36
91
 
37
 
    ret= av_get_packet(s->pb, pkt, packet_size);
38
 
    pkt->pts=
39
 
    pkt->dts= pkt->pos / packet_size;
 
92
    ret = av_get_packet(s->pb, pkt, packet_size);
 
93
    pkt->pts = pkt->dts = pkt->pos / packet_size;
40
94
 
41
95
    pkt->stream_index = 0;
42
96
    if (ret < 0)
44
98
    return 0;
45
99
}
46
100
 
47
 
#define OFFSET(x) offsetof(FFRawVideoDemuxerContext, x)
 
101
#define OFFSET(x) offsetof(RawVideoDemuxerContext, x)
48
102
#define DEC AV_OPT_FLAG_DECODING_PARAM
49
103
static const AVOption rawvideo_options[] = {
50
104
    { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
62
116
 
63
117
AVInputFormat ff_rawvideo_demuxer = {
64
118
    .name           = "rawvideo",
65
 
    .long_name      = NULL_IF_CONFIG_SMALL("raw video format"),
66
 
    .priv_data_size = sizeof(FFRawVideoDemuxerContext),
67
 
    .read_header    = ff_raw_read_header,
 
119
    .long_name      = NULL_IF_CONFIG_SMALL("raw video"),
 
120
    .priv_data_size = sizeof(RawVideoDemuxerContext),
 
121
    .read_header    = rawvideo_read_header,
68
122
    .read_packet    = rawvideo_read_packet,
69
 
    .flags= AVFMT_GENERIC_INDEX,
70
 
    .extensions = "yuv,cif,qcif,rgb",
71
 
    .value = CODEC_ID_RAWVIDEO,
72
 
    .priv_class = &rawvideo_demuxer_class,
 
123
    .flags          = AVFMT_GENERIC_INDEX,
 
124
    .extensions     = "yuv,cif,qcif,rgb",
 
125
    .raw_codec_id   = AV_CODEC_ID_RAWVIDEO,
 
126
    .priv_class     = &rawvideo_demuxer_class,
73
127
};