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

« back to all changes in this revision

Viewing changes to gst-libs/ext/libav/libavcodec/rawenc.c

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2013-09-24 17:07:00 UTC
  • mfrom: (1.1.17) (7.1.9 experimental)
  • Revision ID: package-import@ubuntu.com-20130924170700-4dg62s3pwl0pdakz
Tags: 1.2.0-1
* New upstream stable release:
  + debian/control:
    - Build depend on GStreamer and gst-plugins-base >= 1.2.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
#include "avcodec.h"
28
28
#include "raw.h"
 
29
#include "internal.h"
29
30
#include "libavutil/pixdesc.h"
30
31
#include "libavutil/intreadwrite.h"
 
32
#include "libavutil/internal.h"
31
33
 
32
34
static av_cold int raw_init_encoder(AVCodecContext *avctx)
33
35
{
34
 
    avctx->coded_frame = (AVFrame *)avctx->priv_data;
 
36
    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
 
37
 
 
38
    avctx->coded_frame            = avctx->priv_data;
35
39
    avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
36
40
    avctx->coded_frame->key_frame = 1;
37
 
    avctx->bits_per_coded_sample = av_get_bits_per_pixel(&av_pix_fmt_descriptors[avctx->pix_fmt]);
 
41
    avctx->bits_per_coded_sample = av_get_bits_per_pixel(desc);
38
42
    if(!avctx->codec_tag)
39
43
        avctx->codec_tag = avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt);
40
44
    return 0;
41
45
}
42
46
 
43
 
static int raw_encode(AVCodecContext *avctx,
44
 
                            unsigned char *frame, int buf_size, void *data)
 
47
static int raw_encode(AVCodecContext *avctx, AVPacket *pkt,
 
48
                      const AVFrame *frame, int *got_packet)
45
49
{
46
 
    int ret = avpicture_layout((AVPicture *)data, avctx->pix_fmt, avctx->width,
47
 
                                               avctx->height, frame, buf_size);
 
50
    int ret = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
 
51
 
 
52
    if (ret < 0)
 
53
        return ret;
 
54
 
 
55
    if ((ret = ff_alloc_packet(pkt, ret)) < 0)
 
56
        return ret;
 
57
    if ((ret = avpicture_layout((const AVPicture *)frame, avctx->pix_fmt, avctx->width,
 
58
                                avctx->height, pkt->data, pkt->size)) < 0)
 
59
        return ret;
48
60
 
49
61
    if(avctx->codec_tag == AV_RL32("yuv2") && ret > 0 &&
50
 
       avctx->pix_fmt   == PIX_FMT_YUYV422) {
 
62
       avctx->pix_fmt   == AV_PIX_FMT_YUYV422) {
51
63
        int x;
52
64
        for(x = 1; x < avctx->height*avctx->width*2; x += 2)
53
 
            frame[x] ^= 0x80;
 
65
            pkt->data[x] ^= 0x80;
54
66
    }
55
 
    return ret;
 
67
    pkt->flags |= AV_PKT_FLAG_KEY;
 
68
    *got_packet = 1;
 
69
    return 0;
56
70
}
57
71
 
58
72
AVCodec ff_rawvideo_encoder = {
59
73
    .name           = "rawvideo",
60
74
    .type           = AVMEDIA_TYPE_VIDEO,
61
 
    .id             = CODEC_ID_RAWVIDEO,
 
75
    .id             = AV_CODEC_ID_RAWVIDEO,
62
76
    .priv_data_size = sizeof(AVFrame),
63
77
    .init           = raw_init_encoder,
64
 
    .encode         = raw_encode,
65
 
    .long_name = NULL_IF_CONFIG_SMALL("raw video"),
 
78
    .encode2        = raw_encode,
 
79
    .long_name      = NULL_IF_CONFIG_SMALL("raw video"),
66
80
};