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

« back to all changes in this revision

Viewing changes to gst-libs/ext/libav/libavcodec/dpxenc.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:
19
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
20
 */
21
21
 
 
22
#include "libavutil/common.h"
22
23
#include "libavutil/intreadwrite.h"
23
24
#include "libavutil/imgutils.h"
24
25
#include "avcodec.h"
 
26
#include "internal.h"
25
27
 
26
28
typedef struct DPXContext {
27
29
    AVFrame picture;
43
45
    s->descriptor         = 50; /* RGB */
44
46
 
45
47
    switch (avctx->pix_fmt) {
46
 
    case PIX_FMT_RGB24:
 
48
    case AV_PIX_FMT_RGB24:
47
49
        break;
48
 
    case PIX_FMT_RGBA:
 
50
    case AV_PIX_FMT_RGBA:
49
51
        s->descriptor = 51; /* RGBA */
50
52
        break;
51
 
    case PIX_FMT_RGB48LE:
 
53
    case AV_PIX_FMT_RGB48LE:
52
54
        s->big_endian = 0;
53
 
    case PIX_FMT_RGB48BE:
 
55
    case AV_PIX_FMT_RGB48BE:
54
56
        s->bits_per_component = avctx->bits_per_raw_sample ? avctx->bits_per_raw_sample : 16;
55
57
        break;
56
58
    default:
99
101
    }
100
102
}
101
103
 
102
 
static int encode_frame(AVCodecContext *avctx, unsigned char *buf,
103
 
                        int buf_size, void *data)
 
104
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
 
105
                        const AVFrame *frame, int *got_packet)
104
106
{
105
107
    DPXContext *s = avctx->priv_data;
106
 
    int size;
 
108
    int size, ret;
 
109
    uint8_t *buf;
107
110
 
108
111
#define HEADER_SIZE 1664  /* DPX Generic header */
109
 
    if (buf_size < HEADER_SIZE)
110
 
        return -1;
 
112
    if (s->bits_per_component == 10)
 
113
        size = avctx->height * avctx->width * 4;
 
114
    else
 
115
        size = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
 
116
    if ((ret = ff_alloc_packet(pkt, size + HEADER_SIZE)) < 0) {
 
117
        av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
 
118
        return ret;
 
119
    }
 
120
    buf = pkt->data;
111
121
 
112
122
    memset(buf, 0, HEADER_SIZE);
113
123
 
117
127
    memcpy (buf +   8, "V1.0", 4);
118
128
    write32(buf +  20, 1); /* new image */
119
129
    write32(buf +  24, HEADER_SIZE);
120
 
    memcpy (buf + 160, LIBAVCODEC_IDENT, FFMIN(sizeof(LIBAVCODEC_IDENT), 100));
 
130
    if (!(avctx->flags & CODEC_FLAG_BITEXACT))
 
131
        memcpy (buf + 160, LIBAVCODEC_IDENT, FFMIN(sizeof(LIBAVCODEC_IDENT), 100));
121
132
    write32(buf + 660, 0xFFFFFFFF); /* unencrypted */
122
133
 
123
134
    /* Image information header */
138
149
    switch (s->bits_per_component) {
139
150
    case 8:
140
151
    case 16:
141
 
        size = avpicture_layout(data, avctx->pix_fmt,
 
152
        size = avpicture_layout((const AVPicture*)frame, avctx->pix_fmt,
142
153
                                avctx->width, avctx->height,
143
 
                                buf + HEADER_SIZE, buf_size - HEADER_SIZE);
 
154
                                buf + HEADER_SIZE, pkt->size - HEADER_SIZE);
144
155
        if (size < 0)
145
156
            return size;
146
157
        break;
147
158
    case 10:
148
 
        size = avctx->height * avctx->width * 4;
149
 
        if (buf_size < HEADER_SIZE + size)
150
 
            return -1;
151
 
        encode_rgb48_10bit(avctx, data, buf + HEADER_SIZE);
 
159
        encode_rgb48_10bit(avctx, (const AVPicture*)frame, buf + HEADER_SIZE);
152
160
        break;
153
161
    default:
154
162
        av_log(avctx, AV_LOG_ERROR, "Unsupported bit depth: %d\n", s->bits_per_component);
158
166
    size += HEADER_SIZE;
159
167
 
160
168
    write32(buf + 16, size); /* file size */
161
 
    return size;
 
169
 
 
170
    pkt->flags |= AV_PKT_FLAG_KEY;
 
171
    *got_packet = 1;
 
172
 
 
173
    return 0;
162
174
}
163
175
 
164
176
AVCodec ff_dpx_encoder = {
165
177
    .name = "dpx",
166
178
    .type = AVMEDIA_TYPE_VIDEO,
167
 
    .id   = CODEC_ID_DPX,
 
179
    .id   = AV_CODEC_ID_DPX,
168
180
    .priv_data_size = sizeof(DPXContext),
169
181
    .init   = encode_init,
170
 
    .encode = encode_frame,
171
 
    .pix_fmts = (const enum PixelFormat[]){
172
 
        PIX_FMT_RGB24,
173
 
        PIX_FMT_RGBA,
174
 
        PIX_FMT_RGB48LE,
175
 
        PIX_FMT_RGB48BE,
176
 
        PIX_FMT_NONE},
 
182
    .encode2 = encode_frame,
 
183
    .pix_fmts = (const enum AVPixelFormat[]){
 
184
        AV_PIX_FMT_RGB24,
 
185
        AV_PIX_FMT_RGBA,
 
186
        AV_PIX_FMT_RGB48LE,
 
187
        AV_PIX_FMT_RGB48BE,
 
188
        AV_PIX_FMT_NONE},
177
189
    .long_name = NULL_IF_CONFIG_SMALL("DPX image"),
178
190
};