diff options
Diffstat (limited to 'src/gallium/auxiliary/vl')
-rw-r--r-- | src/gallium/auxiliary/vl/vl_decoder.c | 20 | ||||
-rw-r--r-- | src/gallium/auxiliary/vl/vl_decoder.h | 9 | ||||
-rw-r--r-- | src/gallium/auxiliary/vl/vl_mpeg12_decoder.c | 100 | ||||
-rw-r--r-- | src/gallium/auxiliary/vl/vl_mpeg12_decoder.h | 10 | ||||
-rw-r--r-- | src/gallium/auxiliary/vl/vl_video_buffer.c | 29 | ||||
-rw-r--r-- | src/gallium/auxiliary/vl/vl_video_buffer.h | 16 |
6 files changed, 112 insertions, 72 deletions
diff --git a/src/gallium/auxiliary/vl/vl_decoder.c b/src/gallium/auxiliary/vl/vl_decoder.c index 383e02d910c..a88347fca62 100644 --- a/src/gallium/auxiliary/vl/vl_decoder.c +++ b/src/gallium/auxiliary/vl/vl_decoder.c @@ -44,25 +44,13 @@ vl_profile_supported(struct pipe_screen *screen, enum pipe_video_profile profile } } -unsigned -vl_num_buffers_desired(struct pipe_screen *screen, enum pipe_video_profile profile) -{ - assert(screen); - switch (u_reduce_video_profile(profile)) { - case PIPE_VIDEO_CODEC_MPEG12: - return 4; - - default: - return 1; - } -} - struct pipe_video_decoder * vl_create_decoder(struct pipe_context *pipe, enum pipe_video_profile profile, enum pipe_video_entrypoint entrypoint, enum pipe_video_chroma_format chroma_format, - unsigned width, unsigned height, unsigned max_references) + unsigned width, unsigned height, unsigned max_references, + bool expect_chunked_decode) { unsigned buffer_width, buffer_height; bool pot_buffers; @@ -82,7 +70,9 @@ vl_create_decoder(struct pipe_context *pipe, switch (u_reduce_video_profile(profile)) { case PIPE_VIDEO_CODEC_MPEG12: - return vl_create_mpeg12_decoder(pipe, profile, entrypoint, chroma_format, buffer_width, buffer_height, max_references); + return vl_create_mpeg12_decoder(pipe, profile, entrypoint, chroma_format, + buffer_width, buffer_height, max_references, + expect_chunked_decode); default: return NULL; } diff --git a/src/gallium/auxiliary/vl/vl_decoder.h b/src/gallium/auxiliary/vl/vl_decoder.h index a9975169885..8fa6527ce54 100644 --- a/src/gallium/auxiliary/vl/vl_decoder.h +++ b/src/gallium/auxiliary/vl/vl_decoder.h @@ -38,12 +38,6 @@ bool vl_profile_supported(struct pipe_screen *screen, enum pipe_video_profile profile); /** - * the desired number of buffers for optimal operation - */ -unsigned -vl_num_buffers_desired(struct pipe_screen *screen, enum pipe_video_profile profile); - -/** * standard implementation of pipe->create_video_decoder */ struct pipe_video_decoder * @@ -51,6 +45,7 @@ vl_create_decoder(struct pipe_context *pipe, enum pipe_video_profile profile, enum pipe_video_entrypoint entrypoint, enum pipe_video_chroma_format chroma_format, - unsigned width, unsigned height, unsigned max_references); + unsigned width, unsigned height, unsigned max_references, + bool expect_chunked_decode); #endif /* vl_decoder_h */ diff --git a/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c b/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c index 1a3a2a4bb22..cb55fa6f611 100644 --- a/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c +++ b/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c @@ -384,9 +384,25 @@ UploadYcbcrBlocks(struct vl_mpeg12_decoder *dec, } static void +vl_mpeg12_destroy_buffer(void *buffer) +{ + struct vl_mpeg12_buffer *buf = buffer; + + assert(buf); + + cleanup_zscan_buffer(buf); + cleanup_idct_buffer(buf); + cleanup_mc_buffer(buf); + vl_vb_cleanup(&buf->vertex_stream); + + FREE(buf); +} + +static void vl_mpeg12_destroy(struct pipe_video_decoder *decoder) { struct vl_mpeg12_decoder *dec = (struct vl_mpeg12_decoder*)decoder; + unsigned i; assert(decoder); @@ -420,17 +436,28 @@ vl_mpeg12_destroy(struct pipe_video_decoder *decoder) pipe_sampler_view_reference(&dec->zscan_normal, NULL); pipe_sampler_view_reference(&dec->zscan_alternate, NULL); + for (i = 0; i < 4; ++i) + if (dec->dec_buffers[i]) + vl_mpeg12_destroy_buffer(dec->dec_buffers[i]); + FREE(dec); } -static void * -vl_mpeg12_create_buffer(struct pipe_video_decoder *decoder) +static struct vl_mpeg12_buffer * +vl_mpeg12_get_decode_buffer(struct vl_mpeg12_decoder *dec) { - struct vl_mpeg12_decoder *dec = (struct vl_mpeg12_decoder*)decoder; struct vl_mpeg12_buffer *buffer; assert(dec); + buffer = vl_video_buffer_get_associated_data(dec->target, &dec->base); + if (buffer) + return buffer; + + buffer = dec->dec_buffers[dec->current_buffer]; + if (buffer) + return buffer; + buffer = CALLOC_STRUCT(vl_mpeg12_buffer); if (buffer == NULL) return NULL; @@ -451,13 +478,18 @@ vl_mpeg12_create_buffer(struct pipe_video_decoder *decoder) goto error_zscan; if (dec->base.entrypoint == PIPE_VIDEO_ENTRYPOINT_BITSTREAM) - vl_mpg12_bs_init(&buffer->bs, decoder); + vl_mpg12_bs_init(&buffer->bs, &dec->base); + + if (dec->expect_chunked_decode) + vl_video_buffer_set_associated_data(dec->target, &dec->base, + buffer, vl_mpeg12_destroy_buffer); + else + dec->dec_buffers[dec->current_buffer] = buffer; return buffer; error_zscan: - if (dec->base.entrypoint <= PIPE_VIDEO_ENTRYPOINT_IDCT) - cleanup_idct_buffer(buffer); + cleanup_idct_buffer(buffer); error_idct: cleanup_mc_buffer(buffer); @@ -471,36 +503,6 @@ error_vertex_buffer: } static void -vl_mpeg12_destroy_buffer(struct pipe_video_decoder *decoder, void *buffer) -{ - struct vl_mpeg12_decoder *dec = (struct vl_mpeg12_decoder*)decoder; - struct vl_mpeg12_buffer *buf = buffer; - - assert(dec && buf); - - cleanup_zscan_buffer(buf); - - if (dec->base.entrypoint <= PIPE_VIDEO_ENTRYPOINT_IDCT) - cleanup_idct_buffer(buf); - - cleanup_mc_buffer(buf); - - vl_vb_cleanup(&buf->vertex_stream); - - FREE(buf); -} - -static void -vl_mpeg12_set_decode_buffer(struct pipe_video_decoder *decoder, void *buffer) -{ - struct vl_mpeg12_decoder *dec = (struct vl_mpeg12_decoder *)decoder; - - assert(dec && buffer); - - dec->current_buffer = buffer; -} - -static void vl_mpeg12_set_picture_parameters(struct pipe_video_decoder *decoder, struct pipe_picture_desc *picture) { @@ -536,6 +538,7 @@ vl_mpeg12_set_decode_target(struct pipe_video_decoder *decoder, assert(dec); + dec->target = target; surfaces = target->get_surfaces(target); for (i = 0; i < VL_MAX_PLANES; ++i) pipe_surface_reference(&dec->target_surfaces[i], surfaces[i]); @@ -575,9 +578,9 @@ vl_mpeg12_begin_frame(struct pipe_video_decoder *decoder) unsigned i; - assert(dec); + assert(dec && dec->target); - buf = dec->current_buffer; + buf = vl_mpeg12_get_decode_buffer(dec); assert(buf); if (dec->base.entrypoint == PIPE_VIDEO_ENTRYPOINT_BITSTREAM) @@ -634,10 +637,10 @@ vl_mpeg12_decode_macroblock(struct pipe_video_decoder *decoder, unsigned i, j, mv_weights[2]; - assert(dec && dec->current_buffer); + assert(dec && dec->target); assert(macroblocks && macroblocks->codec == PIPE_VIDEO_CODEC_MPEG12); - buf = dec->current_buffer; + buf = vl_mpeg12_get_decode_buffer(dec); assert(buf); for (; num_macroblocks > 0; --num_macroblocks) { @@ -701,9 +704,9 @@ vl_mpeg12_decode_bitstream(struct pipe_video_decoder *decoder, unsigned i; - assert(dec && dec->current_buffer); + assert(dec && dec->target); - buf = dec->current_buffer; + buf = vl_mpeg12_get_decode_buffer(dec); assert(buf); for (i = 0; i < VL_MAX_PLANES; ++i) @@ -724,9 +727,9 @@ vl_mpeg12_end_frame(struct pipe_video_decoder *decoder) unsigned i, j, component; unsigned nr_components; - assert(dec && dec->current_buffer); + assert(dec && dec->target); - buf = dec->current_buffer; + buf = vl_mpeg12_get_decode_buffer(dec); vl_vb_unmap(&buf->vertex_stream, dec->base.context); @@ -785,6 +788,8 @@ vl_mpeg12_end_frame(struct pipe_video_decoder *decoder) vl_mc_render_ycbcr(i ? &dec->mc_c : &dec->mc_y, &buf->mc[i], j, buf->num_ycbcr_blocks[component]); } } + ++dec->current_buffer; + dec->current_buffer %= 4; } static void @@ -1039,7 +1044,8 @@ vl_create_mpeg12_decoder(struct pipe_context *context, enum pipe_video_profile profile, enum pipe_video_entrypoint entrypoint, enum pipe_video_chroma_format chroma_format, - unsigned width, unsigned height, unsigned max_references) + unsigned width, unsigned height, unsigned max_references, + bool expect_chunked_decode) { const unsigned block_size_pixels = BLOCK_WIDTH * BLOCK_HEIGHT; const struct format_config *format_config; @@ -1061,9 +1067,6 @@ vl_create_mpeg12_decoder(struct pipe_context *context, dec->base.max_references = max_references; dec->base.destroy = vl_mpeg12_destroy; - dec->base.create_buffer = vl_mpeg12_create_buffer; - dec->base.destroy_buffer = vl_mpeg12_destroy_buffer; - dec->base.set_decode_buffer = vl_mpeg12_set_decode_buffer; dec->base.set_picture_parameters = vl_mpeg12_set_picture_parameters; dec->base.set_quant_matrix = vl_mpeg12_set_quant_matrix; dec->base.set_decode_target = vl_mpeg12_set_decode_target; @@ -1077,6 +1080,7 @@ vl_create_mpeg12_decoder(struct pipe_context *context, dec->blocks_per_line = MAX2(util_next_power_of_two(dec->base.width) / block_size_pixels, 4); dec->num_blocks = (dec->base.width * dec->base.height) / block_size_pixels; dec->width_in_macroblocks = align(dec->base.width, MACROBLOCK_WIDTH) / MACROBLOCK_WIDTH; + dec->expect_chunked_decode = expect_chunked_decode; /* TODO: Implement 422, 444 */ assert(dec->base.chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420); diff --git a/src/gallium/auxiliary/vl/vl_mpeg12_decoder.h b/src/gallium/auxiliary/vl/vl_mpeg12_decoder.h index 817c1ffd110..c5dff49cd6d 100644 --- a/src/gallium/auxiliary/vl/vl_mpeg12_decoder.h +++ b/src/gallium/auxiliary/vl/vl_mpeg12_decoder.h @@ -50,6 +50,7 @@ struct vl_mpeg12_decoder unsigned blocks_per_line; unsigned num_blocks; unsigned width_in_macroblocks; + bool expect_chunked_decode; enum pipe_format zscan_source_format; @@ -74,11 +75,15 @@ struct vl_mpeg12_decoder void *dsa; - struct vl_mpeg12_buffer *current_buffer; + unsigned current_buffer; + struct vl_mpeg12_buffer *dec_buffers[4]; + struct pipe_mpeg12_picture_desc picture_desc; uint8_t intra_matrix[64]; uint8_t non_intra_matrix[64]; struct pipe_sampler_view *ref_frames[VL_MAX_REF_FRAMES][VL_MAX_PLANES]; + + struct pipe_video_buffer *target; struct pipe_surface *target_surfaces[VL_MAX_PLANES]; }; @@ -111,6 +116,7 @@ vl_create_mpeg12_decoder(struct pipe_context *pipe, enum pipe_video_profile profile, enum pipe_video_entrypoint entrypoint, enum pipe_video_chroma_format chroma_format, - unsigned width, unsigned height, unsigned max_references); + unsigned width, unsigned height, unsigned max_references, + bool expect_chunked_decode); #endif /* vl_mpeg12_decoder_h */ diff --git a/src/gallium/auxiliary/vl/vl_video_buffer.c b/src/gallium/auxiliary/vl/vl_video_buffer.c index 6d714d49f4a..8ceb7138479 100644 --- a/src/gallium/auxiliary/vl/vl_video_buffer.c +++ b/src/gallium/auxiliary/vl/vl_video_buffer.c @@ -98,6 +98,34 @@ vl_video_buffer_max_size(struct pipe_screen *screen) return 1 << (max_2d_texture_level-1); } +void +vl_video_buffer_set_associated_data(struct pipe_video_buffer *vbuf, + struct pipe_video_decoder *vdec, + void *associated_data, + void (*destroy_associated_data)(void *)) +{ + vbuf->decoder = vdec; + + if (vbuf->associated_data == associated_data) + return; + + if (vbuf->associated_data) + vbuf->destroy_associated_data(vbuf->associated_data); + + vbuf->associated_data = associated_data; + vbuf->destroy_associated_data = destroy_associated_data; +} + +void * +vl_video_buffer_get_associated_data(struct pipe_video_buffer *vbuf, + struct pipe_video_decoder *vdec) +{ + if (vbuf->decoder == vdec) + return vbuf->associated_data; + else + return NULL; +} + static void vl_video_buffer_destroy(struct pipe_video_buffer *buffer) { @@ -112,6 +140,7 @@ vl_video_buffer_destroy(struct pipe_video_buffer *buffer) pipe_sampler_view_reference(&buf->sampler_view_components[i], NULL); pipe_resource_reference(&buf->resources[i], NULL); } + vl_video_buffer_set_associated_data(buffer, NULL, NULL, NULL); FREE(buffer); } diff --git a/src/gallium/auxiliary/vl/vl_video_buffer.h b/src/gallium/auxiliary/vl/vl_video_buffer.h index 8c80b36fbf2..e096ccdaac2 100644 --- a/src/gallium/auxiliary/vl/vl_video_buffer.h +++ b/src/gallium/auxiliary/vl/vl_video_buffer.h @@ -69,6 +69,22 @@ vl_video_buffer_is_format_supported(struct pipe_screen *screen, enum pipe_format format, enum pipe_video_profile profile); +/* + * set the associated data for the given video buffer + */ +void +vl_video_buffer_set_associated_data(struct pipe_video_buffer *vbuf, + struct pipe_video_decoder *vdec, + void *associated_data, + void (*destroy_associated_data)(void *)); + +/* + * get the associated data for the given video buffer + */ +void * +vl_video_buffer_get_associated_data(struct pipe_video_buffer *vbuf, + struct pipe_video_decoder *vdec); + /** * creates a video buffer, can be used as a standard implementation for pipe->create_video_buffer */ |