summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmeric Grange <emeric.grange@gmail.com>2011-11-13 18:29:02 +0100
committerEmeric Grange <emeric.grange@gmail.com>2012-06-24 16:57:31 +0200
commit29a4ffa5fb154b0c8dd402843197694a7fd94e7a (patch)
treef4c3898a1a028f6d81f0253613e128b373291ef2
parentd18a278d06dfd432d2d0173928b2a5a220a0d4b3 (diff)
g3dvl: Rename some functions from the VP8 decoder, move some code around
Signed-off-by: Emeric Grange <emeric.grange@gmail.com>
-rw-r--r--src/gallium/auxiliary/vl/vl_vp8_decoder.c60
-rw-r--r--src/gallium/auxiliary/vl/vl_vp8_decoder.h3
-rw-r--r--src/gallium/auxiliary/vl/vp8/common/onyxd.h17
-rw-r--r--src/gallium/auxiliary/vl/vp8/decoder/decodeframe.c39
-rw-r--r--src/gallium/auxiliary/vl/vp8/decoder/onyxd_if.c138
-rw-r--r--src/gallium/auxiliary/vl/vp8/decoder/onyxd_int.h2
6 files changed, 144 insertions, 115 deletions
diff --git a/src/gallium/auxiliary/vl/vl_vp8_decoder.c b/src/gallium/auxiliary/vl/vl_vp8_decoder.c
index a299378fe4..31a48272af 100644
--- a/src/gallium/auxiliary/vl/vl_vp8_decoder.c
+++ b/src/gallium/auxiliary/vl/vl_vp8_decoder.c
@@ -78,7 +78,7 @@ vl_vp8_destroy(struct pipe_video_decoder *decoder)
dec->base.context->delete_depth_stencil_alpha_state(dec->base.context, dec->dsa);
dec->base.context->delete_sampler_state(dec->base.context, dec->sampler_ycbcr);
- vp8dx_remove_decompressor(dec->vp8_dec);
+ vp8_decoder_remove(dec->vp8_dec);
FREE(dec);
}
@@ -191,6 +191,9 @@ vl_vp8_begin_frame(struct pipe_video_decoder *decoder)
buf = dec->current_buffer;
assert(buf);
+
+ dec->startcode = 0;
+ dec->img_ready = 0;
}
static void
@@ -227,23 +230,46 @@ vl_vp8_decode_bitstream(struct pipe_video_decoder *decoder,
buf = dec->current_buffer;
assert(buf);
+ assert(data);
+
//vl_vp8_bs_decode(&buf->bs, num_bytes, data);
- const uint8_t *datab;
- datab = (const uint8_t *)data;
- assert(datab);
+ if (num_bytes == 0)
+ {
+ printf("[G3DVL] Error : no data !\n");
+ //((VP8_COMMON *)((VP8D_COMP *)(dec->vp8_dec))->common)->show_frame = 0;
+ return;
+ }
- if (datab[0] == 0x9D &&
- datab[1] == 0x01 &&
- datab[2] == 0x2A)
+ if (dec->startcode)
{
- /*printf("[G3DVL] buffer start_code [%02X %02X %02X]\n", datab[0], datab[1], datab[2]);*/
+ //printf("[0]frame_type = %u \n", dec->picture_desc.key_frame);
+ //printf("[0]version = %u \n", dec->picture_desc.base.profile);
+ //printf("[0]show_frame = %u \n", dec->picture_desc.show_frame);
+ //printf("[0]first_partition_size = %u \n \n", dec->picture_desc.first_partition_size);
+
+ if (vp8_decoder_start(dec->vp8_dec, &(dec->picture_desc), data, num_bytes, 0))
+ {
+ printf("[G3DVL] Error : not a valid VP8 VDPAU frame !\n");
+ dec->img_ready = 0;
+ }
+ else
+ {
+ dec->img_ready = 1;
+ }
}
else
{
- if (vp8dx_receive_compressed_data(dec->vp8_dec, data, num_bytes, 0))
+ const uint8_t *datab = (const uint8_t *)data;
+
+ if (datab[0] == 0x9D &&
+ datab[1] == 0x01 &&
+ datab[2] == 0x2A)
{
- printf("[G3DVL] Error : not a valid VP8 VDPAU frame !\n");
+ //printf("[G3DVL] buffer start_code [9D 01 2A] is present\n");
+ dec->startcode = 1;
+
+ //TODO handle the startcode presence on the same buffer than the data
}
}
}
@@ -280,7 +306,7 @@ vl_vp8_end_frame(struct pipe_video_decoder *decoder)
}
// Get the decoded frame
- if (vp8dx_get_raw_frame(dec->vp8_dec, &dec->img_yv12, &timestamp, &timestamp_end)) {
+ if (vp8_decoder_getframe(dec->vp8_dec, &dec->img_yv12, &timestamp, &timestamp_end)) {
printf("[end_frame] No image to output !\n");
return;
}
@@ -389,11 +415,11 @@ find_format_config(struct vl_vp8_decoder *dec,
screen = dec->base.context->screen;
for (i = 0; i < num_configs; ++i) {
- if (!screen->is_format_supported(screen,
- configs[i].loopfilter_source_format,
- PIPE_TEXTURE_2D,
- 1, PIPE_BIND_SAMPLER_VIEW))
- continue;
+ if (!screen->is_format_supported(screen,
+ configs[i].loopfilter_source_format,
+ PIPE_TEXTURE_2D,
+ 1, PIPE_BIND_SAMPLER_VIEW))
+ continue;
return &configs[i];
}
@@ -471,7 +497,7 @@ vl_create_vp8_decoder(struct pipe_context *context,
goto error_pipe_state;
// Initialize the vp8 decoder instance
- dec->vp8_dec = vp8dx_create_decompressor();
+ dec->vp8_dec = vp8_decoder_create();
if (!dec->vp8_dec)
goto error_vp8_dec;
diff --git a/src/gallium/auxiliary/vl/vl_vp8_decoder.h b/src/gallium/auxiliary/vl/vl_vp8_decoder.h
index 5ac2a36eb9..3922c03f07 100644
--- a/src/gallium/auxiliary/vl/vl_vp8_decoder.h
+++ b/src/gallium/auxiliary/vl/vl_vp8_decoder.h
@@ -66,6 +66,9 @@ struct vl_vp8_decoder
// VP8 decoder context
VP8D_PTR vp8_dec;
YV12_BUFFER_CONFIG img_yv12;
+
+ unsigned startcode;
+ unsigned img_ready;
};
struct vl_vp8_buffer
diff --git a/src/gallium/auxiliary/vl/vp8/common/onyxd.h b/src/gallium/auxiliary/vl/vp8/common/onyxd.h
index f1da5d3039..69ee63a58b 100644
--- a/src/gallium/auxiliary/vl/vp8/common/onyxd.h
+++ b/src/gallium/auxiliary/vl/vp8/common/onyxd.h
@@ -19,21 +19,22 @@ extern "C"
#include <stdint.h>
+#include "pipe/p_video_decoder.h"
#include "../vp8_debug.h"
#include "yv12utils.h"
-typedef void *VP8D_PTR;
+typedef void* VP8D_PTR;
-VP8D_PTR vp8dx_create_decompressor();
+VP8D_PTR vp8_decoder_create();
-void vp8dx_remove_decompressor(VP8D_PTR comp);
+int vp8_decoder_start(VP8D_PTR comp, struct pipe_vp8_picture_desc *frame_header,
+ const unsigned char *data, unsigned data_size,
+ int64_t timestamp_deadline);
-int vp8dx_receive_compressed_data(VP8D_PTR comp,
- const unsigned char *data, unsigned data_size,
- int64_t timestamp_deadline);
+int vp8_decoder_getframe(VP8D_PTR comp, YV12_BUFFER_CONFIG *sd,
+ int64_t *timestamp, int64_t *timestamp_end);
-int vp8dx_get_raw_frame(VP8D_PTR comp, YV12_BUFFER_CONFIG *sd,
- int64_t *timestamp, int64_t *timestamp_end);
+void vp8_decoder_remove(VP8D_PTR comp);
#ifdef __cplusplus
}
diff --git a/src/gallium/auxiliary/vl/vp8/decoder/decodeframe.c b/src/gallium/auxiliary/vl/vp8/decoder/decodeframe.c
index f400c4f486..3b7a193370 100644
--- a/src/gallium/auxiliary/vl/vp8/decoder/decodeframe.c
+++ b/src/gallium/auxiliary/vl/vp8/decoder/decodeframe.c
@@ -514,12 +514,12 @@ static void vp8_frame_init(VP8D_COMP *pbi)
xd->corrupted = 0; /* init without corruption */
}
-int vp8_frame_decode(VP8D_COMP *pbi)
+int vp8_frame_decode(VP8D_COMP *pbi, struct pipe_vp8_picture_desc *frame_header)
{
vp8_reader *const bc = &pbi->bc;
VP8_COMMON *const pc = &pbi->common;
MACROBLOCKD *const xd = &pbi->mb;
- const unsigned char *data = (const unsigned char *)pbi->data;
+ const unsigned char *data = pbi->data;
const unsigned char *data_end = data + pbi->data_size;
ptrdiff_t first_partition_length_in_bytes = 0;
@@ -530,11 +530,36 @@ int vp8_frame_decode(VP8D_COMP *pbi)
xd->corrupted = 0;
pc->yv12_fb[pc->new_fb_idx].corrupted = 0;
- if (data_end - data < 3)
+/*
{
- vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME, "Truncated packet");
+ pc->frame_type = (FRAME_TYPE)frame_header->key_frame;
+ pc->version = frame_header->base.profile;
+ pc->show_frame = frame_header->show_frame;
+ first_partition_length_in_bytes = frame_header->first_partition_size;
+ data += 3;
+
+ vp8_setup_version(pc);
+
+ if (pc->frame_type == KEY_FRAME)
+ {
+ if (pc->Width != frame_header->width ||
+ pc->Height != frame_header->height)
+ {
+ if (vp8_alloc_frame_buffers(pc, frame_header->width, frame_header->height))
+ {
+ vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
+ "Failed to allocate frame buffers");
+ }
+ }
+
+ pc->Width = frame_header->width;
+ pc->horiz_scale = frame_header->horizontal_scale;
+ pc->Height = frame_header->height;
+ pc->vert_scale = frame_header->vertical_scale;
+ data += 7;
+ }
}
- else
+*/
{
pc->frame_type = (FRAME_TYPE)(data[0] & 1);
pc->version = (data[0] >> 1) & 7;
@@ -556,14 +581,14 @@ int vp8_frame_decode(VP8D_COMP *pbi)
const int Width = pc->Width;
const int Height = pc->Height;
- /* vet via sync code */
+ // Set via sync code
/* When error concealment is enabled we should only check the sync
* code if we have enough bits available
*/
if (data + 3 < data_end)
{
if (data[0] != 0x9d || data[1] != 0x01 || data[2] != 0x2a)
- vpx_internal_error(&pc->error, VPX_CODEC_UNSUP_BITSTREAM, "Invalid frame sync code");
+ vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME, "Invalid frame sync code");
}
/* If error concealment is enabled we should only parse the new size
diff --git a/src/gallium/auxiliary/vl/vp8/decoder/onyxd_if.c b/src/gallium/auxiliary/vl/vp8/decoder/onyxd_if.c
index 1526d06ff9..eb924ccf00 100644
--- a/src/gallium/auxiliary/vl/vp8/decoder/onyxd_if.c
+++ b/src/gallium/auxiliary/vl/vp8/decoder/onyxd_if.c
@@ -23,54 +23,6 @@
#include "../common/quant_common.h"
#include "detokenize.h"
-static int get_free_fb(VP8_COMMON *cm);
-static void ref_cnt_fb(int *buf, int *idx, int new_idx);
-
-VP8D_PTR vp8dx_create_decompressor()
-{
- VP8D_COMP *pbi = vpx_memalign(32, sizeof(VP8D_COMP));
-
- if (!pbi)
- return NULL;
-
- memset(pbi, 0, sizeof(VP8D_COMP));
-
- if (setjmp(pbi->common.error.jmp))
- {
- pbi->common.error.setjmp = 0;
- vp8dx_remove_decompressor(pbi);
- return 0;
- }
-
- pbi->common.error.setjmp = 1;
- vp8_initialize_common();
-
- vp8_create_common(&pbi->common);
-
- pbi->common.current_video_frame = 0;
- pbi->ready_for_new_data = 1;
-
- vp8_initialize_dequantizer(&pbi->common);
-
- // vp8_loop_filter_init(&pbi->common);
-
- pbi->common.error.setjmp = 0;
-
- return (VP8D_PTR)pbi;
-}
-
-void vp8dx_remove_decompressor(VP8D_PTR ptr)
-{
- VP8D_COMP *pbi = (VP8D_COMP *)ptr;
-
- if (!pbi)
- return;
-
- vp8_remove_common(&pbi->common);
- vpx_free(pbi->mbc);
- vpx_free(pbi);
-}
-
static int get_free_fb(VP8_COMMON *cm)
{
int i;
@@ -80,6 +32,7 @@ static int get_free_fb(VP8_COMMON *cm)
assert(i < NUM_YV12_BUFFERS);
cm->fb_idx_ref_cnt[i] = 1;
+
return i;
}
@@ -152,45 +105,54 @@ static int swap_frame_buffers(VP8_COMMON *cm)
return err;
}
-int vp8dx_receive_compressed_data(VP8D_PTR ptr,
- const unsigned char *data, unsigned data_size,
- int64_t timestamp_deadline)
+VP8D_PTR vp8_decoder_create()
{
- VP8D_COMP *pbi = (VP8D_COMP *)ptr;
- VP8_COMMON *cm = &pbi->common;
- int retcode = 0;
+ VP8D_COMP *pbi = vpx_memalign(32, sizeof(VP8D_COMP));
- /*if(pbi->ready_for_new_data == 0)
- return -1;*/
+ if (!pbi)
+ return NULL;
+
+ memset(pbi, 0, sizeof(VP8D_COMP));
- if (ptr == 0)
+ if (setjmp(pbi->common.error.jmp))
{
- return -1;
+ pbi->common.error.setjmp = 0;
+ vp8_decoder_remove(pbi);
+ return 0;
}
+ pbi->common.error.setjmp = 1;
+ vp8_initialize_common();
+
+ vp8_create_common(&pbi->common);
+
+ pbi->common.current_video_frame = 0;
+ pbi->common.show_frame = 0;
+ pbi->ready_for_new_data = 1;
+
+ vp8_initialize_dequantizer(&pbi->common);
+
+ // vp8_loop_filter_init(&pbi->common);
+
+ pbi->common.error.setjmp = 0;
+
+ return (VP8D_PTR)pbi;
+}
+
+int vp8_decoder_start(VP8D_PTR ptr, struct pipe_vp8_picture_desc *frame_header,
+ const unsigned char *data, unsigned data_size,
+ int64_t timestamp_deadline)
+{
+ VP8D_COMP *pbi = (VP8D_COMP *)ptr;
+ VP8_COMMON *cm = &pbi->common;
+ int retcode = 0;
+
pbi->common.error.error_code = VPX_CODEC_OK;
{
pbi->data = data;
pbi->data_size = data_size;
- if (pbi->data_size == 0)
- {
- /* This is used to signal that we are missing frames.
- * We do not know if the missing frame(s) was supposed to update
- * any of the reference buffers, but we act conservative and
- * mark only the last buffer as corrupted. */
- cm->yv12_fb[cm->lst_fb_idx].corrupted = 1;
-
- /* If error concealment is disabled we won't signal missing frames to
- * the decoder. */
- {
- /* Signal that we have no frame to show. */
- cm->show_frame = 0;
- return 0;
- }
- }
-
cm->new_fb_idx = get_free_fb(cm);
if (setjmp(pbi->common.error.jmp))
@@ -211,7 +173,7 @@ int vp8dx_receive_compressed_data(VP8D_PTR ptr,
pbi->common.error.setjmp = 1;
}
- retcode = vp8_frame_decode(pbi);
+ retcode = vp8_frame_decode(pbi, frame_header);
if (retcode < 0)
{
@@ -254,10 +216,10 @@ int vp8dx_receive_compressed_data(VP8D_PTR ptr,
return retcode;
}
-int vp8dx_get_raw_frame(VP8D_PTR ptr,
- YV12_BUFFER_CONFIG *sd,
- int64_t *timestamp,
- int64_t *timestamp_end)
+int vp8_decoder_getframe(VP8D_PTR ptr,
+ YV12_BUFFER_CONFIG *sd,
+ int64_t *timestamp,
+ int64_t *timestamp_end)
{
int ret = -1;
VP8D_COMP *pbi = (VP8D_COMP *)ptr;
@@ -273,14 +235,14 @@ int vp8dx_get_raw_frame(VP8D_PTR ptr,
*timestamp = pbi->last_time_stamp;
*timestamp_end = 0;
- sd->clrtype = pbi->common.clr_type;
-
if (pbi->common.frame_to_show)
{
*sd = *pbi->common.frame_to_show;
+ sd->clrtype = pbi->common.clr_type;
sd->y_width = pbi->common.Width;
sd->y_height = pbi->common.Height;
sd->uv_height = pbi->common.Height / 2;
+
ret = 0;
}
else
@@ -290,3 +252,15 @@ int vp8dx_get_raw_frame(VP8D_PTR ptr,
return ret;
}
+
+void vp8_decoder_remove(VP8D_PTR ptr)
+{
+ VP8D_COMP *pbi = (VP8D_COMP *)ptr;
+
+ if (!pbi)
+ return;
+
+ vp8_remove_common(&pbi->common);
+ vpx_free(pbi->mbc);
+ vpx_free(pbi);
+}
diff --git a/src/gallium/auxiliary/vl/vp8/decoder/onyxd_int.h b/src/gallium/auxiliary/vl/vp8/decoder/onyxd_int.h
index 721682b43b..4d4457e4cc 100644
--- a/src/gallium/auxiliary/vl/vp8/decoder/onyxd_int.h
+++ b/src/gallium/auxiliary/vl/vp8/decoder/onyxd_int.h
@@ -53,7 +53,7 @@ typedef struct
} VP8D_COMP;
-int vp8_frame_decode(VP8D_COMP *cpi);
+int vp8_frame_decode(VP8D_COMP *cpi, struct pipe_vp8_picture_desc *frame_header);
#if CONFIG_DEBUG
#define CHECK_MEM_ERROR(lval,expr) do { \