Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2047)

Side by Side Diff: source/libvpx/vp9/vp9_dx_iface.c

Issue 375983002: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/vp9/vp9_cx_iface.c ('k') | source/libvpx/vp9/vp9_iface_common.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 void *decrypt_state, 310 void *decrypt_state,
311 const uint8_t *data) { 311 const uint8_t *data) {
312 if (decrypt_cb) { 312 if (decrypt_cb) {
313 uint8_t marker; 313 uint8_t marker;
314 decrypt_cb(decrypt_state, data, &marker, 1); 314 decrypt_cb(decrypt_state, data, &marker, 1);
315 return marker; 315 return marker;
316 } 316 }
317 return *data; 317 return *data;
318 } 318 }
319 319
320 static void parse_superframe_index(const uint8_t *data, size_t data_sz, 320 static vpx_codec_err_t parse_superframe_index(const uint8_t *data,
321 uint32_t sizes[8], int *count, 321 size_t data_sz,
322 vpx_decrypt_cb decrypt_cb, 322 uint32_t sizes[8], int *count,
323 void *decrypt_state) { 323 vpx_decrypt_cb decrypt_cb,
324 void *decrypt_state) {
325 // A chunk ending with a byte matching 0xc0 is an invalid chunk unless
326 // it is a super frame index. If the last byte of real video compression
327 // data is 0xc0 the encoder must add a 0 byte. If we have the marker but
328 // not the associated matching marker byte at the front of the index we have
329 // an invalid bitstream and need to return an error.
330
324 uint8_t marker; 331 uint8_t marker;
325 332
326 assert(data_sz); 333 assert(data_sz);
327 marker = read_marker(decrypt_cb, decrypt_state, data + data_sz - 1); 334 marker = read_marker(decrypt_cb, decrypt_state, data + data_sz - 1);
328 *count = 0; 335 *count = 0;
329 336
330 if ((marker & 0xe0) == 0xc0) { 337 if ((marker & 0xe0) == 0xc0) {
331 const uint32_t frames = (marker & 0x7) + 1; 338 const uint32_t frames = (marker & 0x7) + 1;
332 const uint32_t mag = ((marker >> 3) & 0x3) + 1; 339 const uint32_t mag = ((marker >> 3) & 0x3) + 1;
333 const size_t index_sz = 2 + mag * frames; 340 const size_t index_sz = 2 + mag * frames;
334 341
335 if (data_sz >= index_sz) { 342 // This chunk is marked as having a superframe index but doesn't have
336 uint8_t marker2 = read_marker(decrypt_cb, decrypt_state, 343 // enough data for it, thus it's an invalid superframe index.
337 data + data_sz - index_sz); 344 if (data_sz < index_sz)
345 return VPX_CODEC_CORRUPT_FRAME;
338 346
339 if (marker == marker2) { 347 {
340 // Found a valid superframe index. 348 const uint8_t marker2 = read_marker(decrypt_cb, decrypt_state,
341 uint32_t i, j; 349 data + data_sz - index_sz);
342 const uint8_t *x = &data[data_sz - index_sz + 1];
343 350
344 // Frames has a maximum of 8 and mag has a maximum of 4. 351 // This chunk is marked as having a superframe index but doesn't have
345 uint8_t clear_buffer[32]; 352 // the matching marker byte at the front of the index therefore it's an
346 assert(sizeof(clear_buffer) >= frames * mag); 353 // invalid chunk.
347 if (decrypt_cb) { 354 if (marker != marker2)
348 decrypt_cb(decrypt_state, x, clear_buffer, frames * mag); 355 return VPX_CODEC_CORRUPT_FRAME;
349 x = clear_buffer; 356 }
350 }
351 357
352 for (i = 0; i < frames; ++i) { 358 {
353 uint32_t this_sz = 0; 359 // Found a valid superframe index.
360 uint32_t i, j;
361 const uint8_t *x = &data[data_sz - index_sz + 1];
354 362
355 for (j = 0; j < mag; ++j) 363 // Frames has a maximum of 8 and mag has a maximum of 4.
356 this_sz |= (*x++) << (j * 8); 364 uint8_t clear_buffer[32];
357 sizes[i] = this_sz; 365 assert(sizeof(clear_buffer) >= frames * mag);
358 } 366 if (decrypt_cb) {
367 decrypt_cb(decrypt_state, x, clear_buffer, frames * mag);
368 x = clear_buffer;
369 }
359 370
360 *count = frames; 371 for (i = 0; i < frames; ++i) {
372 uint32_t this_sz = 0;
373
374 for (j = 0; j < mag; ++j)
375 this_sz |= (*x++) << (j * 8);
376 sizes[i] = this_sz;
361 } 377 }
378 *count = frames;
362 } 379 }
363 } 380 }
381 return VPX_CODEC_OK;
364 } 382 }
365 383
366 static vpx_codec_err_t decoder_decode(vpx_codec_alg_priv_t *ctx, 384 static vpx_codec_err_t decoder_decode(vpx_codec_alg_priv_t *ctx,
367 const uint8_t *data, unsigned int data_sz, 385 const uint8_t *data, unsigned int data_sz,
368 void *user_priv, long deadline) { 386 void *user_priv, long deadline) {
369 const uint8_t *data_start = data; 387 const uint8_t *data_start = data;
370 const uint8_t * const data_end = data + data_sz; 388 const uint8_t * const data_end = data + data_sz;
371 vpx_codec_err_t res; 389 vpx_codec_err_t res;
372 uint32_t frame_sizes[8]; 390 uint32_t frame_sizes[8];
373 int frame_count; 391 int frame_count;
374 392
375 if (data == NULL || data_sz == 0) 393 if (data == NULL || data_sz == 0)
376 return VPX_CODEC_INVALID_PARAM; 394 return VPX_CODEC_INVALID_PARAM;
377 395
378 parse_superframe_index(data, data_sz, frame_sizes, &frame_count, 396 res = parse_superframe_index(data, data_sz, frame_sizes, &frame_count,
379 ctx->decrypt_cb, ctx->decrypt_state); 397 ctx->decrypt_cb, ctx->decrypt_state);
398 if (res != VPX_CODEC_OK)
399 return res;
380 400
381 if (ctx->frame_parallel_decode) { 401 if (ctx->frame_parallel_decode) {
382 // Decode in frame parallel mode. When decoding in this mode, the frame 402 // Decode in frame parallel mode. When decoding in this mode, the frame
383 // passed to the decoder must be either a normal frame or a superframe with 403 // passed to the decoder must be either a normal frame or a superframe with
384 // superframe index so the decoder could get each frame's start position 404 // superframe index so the decoder could get each frame's start position
385 // in the superframe. 405 // in the superframe.
386 if (frame_count > 0) { 406 if (frame_count > 0) {
387 int i; 407 int i;
388 408
389 for (i = 0; i < frame_count; ++i) { 409 for (i = 0; i < frame_count; ++i) {
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 { // NOLINT 696 { // NOLINT
677 NOT_IMPLEMENTED, // vpx_codec_enc_cfg_map_t 697 NOT_IMPLEMENTED, // vpx_codec_enc_cfg_map_t
678 NOT_IMPLEMENTED, // vpx_codec_encode_fn_t 698 NOT_IMPLEMENTED, // vpx_codec_encode_fn_t
679 NOT_IMPLEMENTED, // vpx_codec_get_cx_data_fn_t 699 NOT_IMPLEMENTED, // vpx_codec_get_cx_data_fn_t
680 NOT_IMPLEMENTED, // vpx_codec_enc_config_set_fn_t 700 NOT_IMPLEMENTED, // vpx_codec_enc_config_set_fn_t
681 NOT_IMPLEMENTED, // vpx_codec_get_global_headers_fn_t 701 NOT_IMPLEMENTED, // vpx_codec_get_global_headers_fn_t
682 NOT_IMPLEMENTED, // vpx_codec_get_preview_frame_fn_t 702 NOT_IMPLEMENTED, // vpx_codec_get_preview_frame_fn_t
683 NOT_IMPLEMENTED // vpx_codec_enc_mr_get_mem_loc_fn_t 703 NOT_IMPLEMENTED // vpx_codec_enc_mr_get_mem_loc_fn_t
684 } 704 }
685 }; 705 };
OLDNEW
« no previous file with comments | « source/libvpx/vp9/vp9_cx_iface.c ('k') | source/libvpx/vp9/vp9_iface_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698