~ppsspp/ppsspp/ffmpeg

« back to all changes in this revision

Viewing changes to libavcodec/vda_h264_dec.c

  • Committer: Henrik Rydgård
  • Date: 2014-01-03 10:44:32 UTC
  • Revision ID: git-v1:87c6c126784b1718bfa448ecf2e6a9fef781eb4e
Update our ffmpeg snapshot to a clone of the official repository.

This is because Maxim's at3plus support has been officially merged!

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
    int h264_initialized;
57
57
    struct vda_context vda_ctx;
58
58
    enum AVPixelFormat pix_fmt;
 
59
 
 
60
    /* for backing-up fields set by user.
 
61
     * we have to gain full control of such fields here */
 
62
    void *hwaccel_context;
 
63
    enum AVPixelFormat (*get_format)(struct AVCodecContext *s, const enum AVPixelFormat * fmt);
 
64
    int (*get_buffer2)(struct AVCodecContext *s, AVFrame *frame, int flags);
 
65
#if FF_API_GET_BUFFER
 
66
    int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic);
 
67
#endif
59
68
} VDADecoderContext;
60
69
 
61
70
static enum AVPixelFormat get_format(struct AVCodecContext *avctx,
90
99
    return 0;
91
100
}
92
101
 
 
102
static inline void set_context(AVCodecContext *avctx)
 
103
{
 
104
    VDADecoderContext *ctx = avctx->priv_data;
 
105
    ctx->hwaccel_context = avctx->hwaccel_context;
 
106
    avctx->hwaccel_context = &ctx->vda_ctx;
 
107
    ctx->get_format = avctx->get_format;
 
108
    avctx->get_format = get_format;
 
109
    ctx->get_buffer2 = avctx->get_buffer2;
 
110
    avctx->get_buffer2 = get_buffer2;
 
111
#if FF_API_GET_BUFFER
 
112
    ctx->get_buffer = avctx->get_buffer;
 
113
    avctx->get_buffer = NULL;
 
114
#endif
 
115
}
 
116
 
 
117
static inline void restore_context(AVCodecContext *avctx)
 
118
{
 
119
    VDADecoderContext *ctx = avctx->priv_data;
 
120
    avctx->hwaccel_context = ctx->hwaccel_context;
 
121
    avctx->get_format = ctx->get_format;
 
122
    avctx->get_buffer2 = ctx->get_buffer2;
 
123
#if FF_API_GET_BUFFER
 
124
    avctx->get_buffer = ctx->get_buffer;
 
125
#endif
 
126
}
 
127
 
93
128
static int vdadec_decode(AVCodecContext *avctx,
94
129
        void *data, int *got_frame, AVPacket *avpkt)
95
130
{
97
132
    AVFrame *pic = data;
98
133
    int ret;
99
134
 
 
135
    set_context(avctx);
100
136
    ret = ff_h264_decoder.decode(avctx, data, got_frame, avpkt);
 
137
    restore_context(avctx);
101
138
    if (*got_frame) {
102
139
        AVBufferRef *buffer = pic->buf[0];
103
140
        VDABufferContext *context = av_buffer_get_opaque(buffer);
130
167
    /* release buffers and decoder */
131
168
    ff_vda_destroy_decoder(&ctx->vda_ctx);
132
169
    /* close H.264 decoder */
133
 
    if (ctx->h264_initialized)
 
170
    if (ctx->h264_initialized) {
 
171
        set_context(avctx);
134
172
        ff_h264_decoder.close(avctx);
 
173
        restore_context(avctx);
 
174
    }
135
175
    return 0;
136
176
}
137
177
 
140
180
    VDADecoderContext *ctx = avctx->priv_data;
141
181
    struct vda_context *vda_ctx = &ctx->vda_ctx;
142
182
    OSStatus status;
143
 
    int ret;
 
183
    int ret, i;
144
184
 
145
185
    ctx->h264_initialized = 0;
146
186
 
184
224
                "Failed to init VDA decoder: %d.\n", status);
185
225
        goto failed;
186
226
    }
187
 
    avctx->hwaccel_context = vda_ctx;
188
 
 
189
 
    /* changes callback functions */
190
 
    avctx->get_format = get_format;
191
 
    avctx->get_buffer2 = get_buffer2;
192
 
#if FF_API_GET_BUFFER
193
 
    // force the old get_buffer to be empty
194
 
    avctx->get_buffer = NULL;
195
 
#endif
196
227
 
197
228
    /* init H.264 decoder */
 
229
    set_context(avctx);
198
230
    ret = ff_h264_decoder.init(avctx);
 
231
    restore_context(avctx);
199
232
    if (ret < 0) {
200
233
        av_log(avctx, AV_LOG_ERROR, "Failed to open H.264 decoder.\n");
201
234
        goto failed;
202
235
    }
203
236
    ctx->h264_initialized = 1;
204
237
 
 
238
    for (i = 0; i < MAX_SPS_COUNT; i++) {
 
239
        SPS *sps = ctx->h264ctx.sps_buffers[i];
 
240
        if (sps && (sps->bit_depth_luma != 8 ||
 
241
                sps->chroma_format_idc == 2 ||
 
242
                sps->chroma_format_idc == 3)) {
 
243
            av_log(avctx, AV_LOG_ERROR, "Format is not supported.\n");
 
244
            goto failed;
 
245
        }
 
246
    }
 
247
 
205
248
    return 0;
206
249
 
207
250
failed:
211
254
 
212
255
static void vdadec_flush(AVCodecContext *avctx)
213
256
{
214
 
    return ff_h264_decoder.flush(avctx);
 
257
    set_context(avctx);
 
258
    ff_h264_decoder.flush(avctx);
 
259
    restore_context(avctx);
215
260
}
216
261
 
217
262
AVCodec ff_h264_vda_decoder = {