static SchroFrame * gst_schro_wrap_frame (GstSchroDec *schro_dec, GstBuffer *buffer) { SchroFrame *frame; switch (schro_dec->fourcc) { case GST_MAKE_FOURCC('I','4','2','0'): frame = schro_frame_new_from_data_I420 (GST_BUFFER_DATA (buffer), schro_dec->width, schro_dec->height); break; case GST_MAKE_FOURCC('Y','U','Y','2'): frame = schro_frame_new_from_data_YUY2 (GST_BUFFER_DATA (buffer), schro_dec->width, schro_dec->height); break; case GST_MAKE_FOURCC('A','Y','U','V'): frame = schro_frame_new_from_data_AYUV (GST_BUFFER_DATA (buffer), schro_dec->width, schro_dec->height); break; default: g_assert_not_reached(); break; } schro_frame_set_free_callback (frame, gst_schro_frame_free, buffer); return frame; }
SchroFrame *ff_create_schro_frame(AVCodecContext *avctx, SchroFrameFormat schro_frame_fmt) { AVFrame *p_pic; SchroFrame *p_frame; int y_width, uv_width; int y_height, uv_height; int i; y_width = avctx->width; y_height = avctx->height; uv_width = y_width >> (SCHRO_FRAME_FORMAT_H_SHIFT(schro_frame_fmt)); uv_height = y_height >> (SCHRO_FRAME_FORMAT_V_SHIFT(schro_frame_fmt)); p_pic = av_frame_alloc(); if (!p_pic) return NULL; if (ff_get_buffer(avctx, p_pic, AV_GET_BUFFER_FLAG_REF) < 0) { av_frame_free(&p_pic); av_log(avctx, AV_LOG_ERROR, "Unable to allocate buffer\n"); return NULL; } p_frame = schro_frame_new(); p_frame->format = schro_frame_fmt; p_frame->width = y_width; p_frame->height = y_height; schro_frame_set_free_callback(p_frame, free_schro_frame, (void *)p_pic); for (i = 0; i < 3; ++i) { p_frame->components[i].width = i ? uv_width : y_width; p_frame->components[i].stride = p_pic->linesize[i]; p_frame->components[i].height = i ? uv_height : y_height; p_frame->components[i].length = p_frame->components[i].stride * p_frame->components[i].height; p_frame->components[i].data = p_pic->data[i]; if (i) { p_frame->components[i].v_shift = SCHRO_FRAME_FORMAT_V_SHIFT(p_frame->format); p_frame->components[i].h_shift = SCHRO_FRAME_FORMAT_H_SHIFT(p_frame->format); } } return p_frame; }
SchroFrame *ff_create_schro_frame(AVCodecContext *avctx, SchroFrameFormat schro_frame_fmt) { AVPicture *p_pic; SchroFrame *p_frame; int y_width, uv_width; int y_height, uv_height; int i; y_width = avctx->width; y_height = avctx->height; uv_width = y_width >> (SCHRO_FRAME_FORMAT_H_SHIFT(schro_frame_fmt)); uv_height = y_height >> (SCHRO_FRAME_FORMAT_V_SHIFT(schro_frame_fmt)); p_pic = av_mallocz(sizeof(AVPicture)); if (!p_pic || avpicture_alloc(p_pic, avctx->pix_fmt, y_width, y_height) < 0) { av_free(p_pic); return NULL; } p_frame = schro_frame_new(); p_frame->format = schro_frame_fmt; p_frame->width = y_width; p_frame->height = y_height; schro_frame_set_free_callback(p_frame, free_schro_frame, (void *)p_pic); for (i = 0; i < 3; ++i) { p_frame->components[i].width = i ? uv_width : y_width; p_frame->components[i].stride = p_pic->linesize[i]; p_frame->components[i].height = i ? uv_height : y_height; p_frame->components[i].length = p_frame->components[i].stride * p_frame->components[i].height; p_frame->components[i].data = p_pic->data[i]; if (i) { p_frame->components[i].v_shift = SCHRO_FRAME_FORMAT_V_SHIFT(p_frame->format); p_frame->components[i].h_shift = SCHRO_FRAME_FORMAT_H_SHIFT(p_frame->format); } } return p_frame; }
SchroFrame * gst_schro_buffer_wrap (GstBuffer * buf, GstVideoFormat format, int width, int height) { SchroFrame *frame; switch (format) { case GST_VIDEO_FORMAT_I420: frame = schro_frame_new_from_data_I420 (GST_BUFFER_DATA (buf), width, height); break; case GST_VIDEO_FORMAT_YV12: frame = schro_frame_new_from_data_YV12 (GST_BUFFER_DATA (buf), width, height); break; case GST_VIDEO_FORMAT_YUY2: frame = schro_frame_new_from_data_YUY2 (GST_BUFFER_DATA (buf), width, height); break; case GST_VIDEO_FORMAT_UYVY: frame = schro_frame_new_from_data_UYVY (GST_BUFFER_DATA (buf), width, height); break; case GST_VIDEO_FORMAT_AYUV: frame = schro_frame_new_from_data_AYUV (GST_BUFFER_DATA (buf), width, height); break; #if SCHRO_CHECK_VERSION(1,0,12) case GST_VIDEO_FORMAT_ARGB: frame = schro_frame_new_from_data_ARGB (GST_BUFFER_DATA (buf), width, height); break; #endif #if SCHRO_CHECK_VERSION(1,0,11) case GST_VIDEO_FORMAT_Y42B: frame = schro_frame_new_from_data_Y42B (GST_BUFFER_DATA (buf), width, height); break; case GST_VIDEO_FORMAT_Y444: frame = schro_frame_new_from_data_Y444 (GST_BUFFER_DATA (buf), width, height); break; case GST_VIDEO_FORMAT_v210: frame = schro_frame_new_from_data_v210 (GST_BUFFER_DATA (buf), width, height); break; case GST_VIDEO_FORMAT_v216: frame = schro_frame_new_from_data_v216 (GST_BUFFER_DATA (buf), width, height); break; case GST_VIDEO_FORMAT_AYUV64: frame = schro_frame_new_from_data_AY64 (GST_BUFFER_DATA (buf), width, height); break; #endif default: g_assert_not_reached (); return NULL; } schro_frame_set_free_callback (frame, gst_schro_frame_free, buf); return frame; }