}
#endif
+/**
+ * reset the CPB handling
+ */
+static void reset_cpb(struct rvce_encoder *enc)
+{
+ unsigned i;
+
+ LIST_INITHEAD(&enc->cpb_slots);
+ for (i = 0; i < RVCE_NUM_CPB_FRAMES; ++i) {
+ struct rvce_cpb_slot *slot = &enc->cpb_array[i];
+ slot->index = i;
+ slot->picture_type = PIPE_H264_ENC_PICTURE_TYPE_SKIP;
+ slot->frame_num = 0;
+ slot->pic_order_cnt = 0;
+ LIST_ADDTAIL(&slot->list, &enc->cpb_slots);
+ }
+}
+
+/**
+ * sort l0 and l1 to the top of the list
+ */
+static void sort_cpb(struct rvce_encoder *enc)
+{
+ struct rvce_cpb_slot *i, *l0 = NULL, *l1 = NULL;
+
+ LIST_FOR_EACH_ENTRY(i, &enc->cpb_slots, list) {
+ if (i->frame_num == enc->pic.ref_idx_l0)
+ l0 = i;
+
+ if (i->frame_num == enc->pic.ref_idx_l1)
+ l1 = i;
+
+ if (enc->pic.picture_type == PIPE_H264_ENC_PICTURE_TYPE_P && l0)
+ break;
+
+ if (enc->pic.picture_type == PIPE_H264_ENC_PICTURE_TYPE_B &&
+ l0 && l1)
+ break;
+ }
+
+ if (l1) {
+ LIST_DEL(&l1->list);
+ LIST_ADD(&l1->list, &enc->cpb_slots);
+ }
+
+ if (l0) {
+ LIST_DEL(&l0->list);
+ LIST_ADD(&l0->list, &enc->cpb_slots);
+ }
+}
+
/**
* destroy this video encoder
*/
}
rvid_destroy_buffer(&enc->cpb);
enc->ws->cs_destroy(enc->cs);
+ FREE(enc->cpb_array);
FREE(enc);
}
enc->get_buffer(vid_buf->resources[0], &enc->handle, &enc->luma);
enc->get_buffer(vid_buf->resources[1], NULL, &enc->chroma);
+
+ if (pic->picture_type == PIPE_H264_ENC_PICTURE_TYPE_IDR)
+ reset_cpb(enc);
+ else if (pic->picture_type == PIPE_H264_ENC_PICTURE_TYPE_P ||
+ pic->picture_type == PIPE_H264_ENC_PICTURE_TYPE_B)
+ sort_cpb(enc);
if (!enc->stream_handle) {
struct rvid_buffer fb;
struct pipe_picture_desc *picture)
{
struct rvce_encoder *enc = (struct rvce_encoder*)encoder;
+ struct rvce_cpb_slot *slot = LIST_ENTRY(
+ struct rvce_cpb_slot, enc->cpb_slots.prev, list);
+
flush(enc);
+
+ /* update the CPB backtrack with the just encoded frame */
+ LIST_DEL(&slot->list);
+ slot->picture_type = enc->pic.picture_type;
+ slot->frame_num = enc->pic.frame_num;
+ slot->pic_order_cnt = enc->pic.pic_order_cnt;
+ LIST_ADD(&slot->list, &enc->cpb_slots);
}
static void rvce_get_feedback(struct pipe_video_codec *encoder,
struct rvce_encoder *enc;
struct pipe_video_buffer *tmp_buf, templat = {};
struct radeon_surface *tmp_surf;
- unsigned pitch, vpitch;
+ unsigned cpb_size;
if (!rscreen->info.vce_fw_version) {
RVID_ERR("Kernel doesn't supports VCE!\n");
}
get_buffer(((struct vl_video_buffer *)tmp_buf)->resources[0], NULL, &tmp_surf);
- pitch = align(tmp_surf->level[0].pitch_bytes, 128);
- vpitch = align(tmp_surf->npix_y, 16);
+ cpb_size = align(tmp_surf->level[0].pitch_bytes, 128);
+ cpb_size = cpb_size * align(tmp_surf->npix_y, 16);
+ cpb_size = cpb_size * 3 / 2;
+ cpb_size = cpb_size * RVCE_NUM_CPB_FRAMES;
tmp_buf->destroy(tmp_buf);
- if (!rvid_create_buffer(enc->ws, &enc->cpb,
- pitch * vpitch * 1.5 * RVCE_NUM_CPB_FRAMES,
- RADEON_DOMAIN_VRAM)) {
+ if (!rvid_create_buffer(enc->ws, &enc->cpb, cpb_size, RADEON_DOMAIN_VRAM)) {
RVID_ERR("Can't create CPB buffer.\n");
goto error;
}
+ enc->cpb_array = CALLOC(RVCE_NUM_CPB_FRAMES, sizeof(struct rvce_cpb_slot));
+ if (!enc->cpb_array)
+ goto error;
+
+ reset_cpb(enc);
+
radeon_vce_40_2_2_init(enc);
return &enc->base;
rvid_destroy_buffer(&enc->cpb);
+ FREE(enc->cpb_array);
FREE(enc);
return NULL;
}
#ifndef RADEON_VCE_H
#define RADEON_VCE_H
+#include "util/u_double_list.h"
+
#define RVCE_RELOC(buf, usage, domain) (enc->ws->cs_add_reloc(enc->cs, (buf), (usage), domain, RADEON_PRIO_MIN))
#define RVCE_CS(value) (enc->cs->buf[enc->cs->cdw++] = (value))
struct radeon_winsys_cs_handle **handle,
struct radeon_surface **surface);
+/* Coded picture buffer slot */
+struct rvce_cpb_slot {
+ struct list_head list;
+
+ unsigned index;
+ enum pipe_h264_enc_picture_type picture_type;
+ unsigned frame_num;
+ unsigned pic_order_cnt;
+};
+
/* VCE encoder representation */
struct rvce_encoder {
struct pipe_video_codec base;
struct radeon_winsys_cs_handle* bs_handle;
unsigned bs_size;
+ struct rvce_cpb_slot *cpb_array;
+ struct list_head cpb_slots;
+
struct rvid_buffer *fb;
struct rvid_buffer cpb;
struct pipe_h264_enc_picture_desc pic;
#include "radeon_video.h"
#include "radeon_vce.h"
+static struct rvce_cpb_slot *current_slot(struct rvce_encoder *enc)
+{
+ return LIST_ENTRY(struct rvce_cpb_slot, enc->cpb_slots.prev, list);
+}
+
+static struct rvce_cpb_slot *l0_slot(struct rvce_encoder *enc)
+{
+ return LIST_ENTRY(struct rvce_cpb_slot, enc->cpb_slots.next, list);
+}
+
+static void frame_offset(struct rvce_encoder *enc, struct rvce_cpb_slot *slot,
+ unsigned *luma_offset, unsigned *chroma_offset)
+{
+ unsigned pitch = align(enc->luma->level[0].pitch_bytes, 128);
+ unsigned vpitch = align(enc->luma->npix_y, 16);
+ unsigned fsize = pitch * (vpitch + vpitch / 2);
+
+ *luma_offset = slot->index * fsize;
+ *chroma_offset = *luma_offset + pitch * vpitch;
+}
+
static void session(struct rvce_encoder *enc)
{
RVCE_BEGIN(0x00000001); // session cmd
RVCE_END();
}
-static void frame_offset(struct rvce_encoder *enc, unsigned frame_num,
- unsigned *luma_offset, unsigned *chroma_offset)
-{
- unsigned pitch = align(enc->luma->level[0].pitch_bytes, 128);
- unsigned vpitch = align(enc->luma->npix_y, 16);
- unsigned fsize = pitch * (vpitch + vpitch / 2);
-
- *luma_offset = (frame_num % RVCE_NUM_CPB_FRAMES) * fsize;
- *chroma_offset = *luma_offset + pitch * vpitch;
-}
-
static void encode(struct rvce_encoder *enc)
{
int i;
RVCE_CS(0xffffffff); // chromaOffset
}
else if(enc->pic.picture_type == PIPE_H264_ENC_PICTURE_TYPE_P) {
- frame_offset(enc, enc->pic.ref_idx_l0, &luma_offset, &chroma_offset);
- RVCE_CS(0x00000000); // encPicType
- // TODO: Stores these in the CPB backtrack
- RVCE_CS(enc->pic.frame_num - 1); // frameNumber
- RVCE_CS(enc->pic.frame_num - 1); // pictureOrderCount
+ struct rvce_cpb_slot *l0 = l0_slot(enc);
+ frame_offset(enc, l0, &luma_offset, &chroma_offset);
+ RVCE_CS(l0->picture_type); // encPicType
+ RVCE_CS(l0->frame_num); // frameNumber
+ RVCE_CS(l0->pic_order_cnt); // pictureOrderCount
RVCE_CS(luma_offset); // lumaOffset
RVCE_CS(chroma_offset); // chromaOffset
}
RVCE_CS(0xffffffff); // chromaOffset
}
- frame_offset(enc, enc->pic.frame_num, &luma_offset, &chroma_offset);
+ frame_offset(enc, current_slot(enc), &luma_offset, &chroma_offset);
RVCE_CS(luma_offset); // encReconstructedLumaOffset
RVCE_CS(chroma_offset); // encReconstructedChromaOffset
RVCE_CS(0x00000000); // encColocBufferOffset