applemedia: corevideobuffer: make mapping the CVPixelBuffer in CPU optional

Mapping is not necessary and impacts performance when doing texture sharing with
downstream
This commit is contained in:
Alessandro Decina 2015-01-22 13:17:11 +11:00
parent c7284a6390
commit e91989136a
5 changed files with 22 additions and 13 deletions

View file

@ -59,7 +59,8 @@ gst_core_video_meta_get_info (void)
} }
GstBuffer * GstBuffer *
gst_core_video_buffer_new (CVBufferRef cvbuf, GstVideoInfo * vinfo) gst_core_video_buffer_new (CVBufferRef cvbuf, GstVideoInfo * vinfo,
gboolean map)
{ {
CVPixelBufferRef pixbuf = NULL; CVPixelBufferRef pixbuf = NULL;
GstBuffer *buf; GstBuffer *buf;
@ -74,7 +75,7 @@ gst_core_video_buffer_new (CVBufferRef cvbuf, GstVideoInfo * vinfo)
pixbuf = (CVPixelBufferRef) cvbuf; pixbuf = (CVPixelBufferRef) cvbuf;
if (CVPixelBufferLockBaseAddress (pixbuf, 0) != kCVReturnSuccess) { if (map && CVPixelBufferLockBaseAddress (pixbuf, 0) != kCVReturnSuccess) {
goto error; goto error;
} }
@ -101,11 +102,13 @@ gst_core_video_buffer_new (CVBufferRef cvbuf, GstVideoInfo * vinfo)
offset[i] = off; offset[i] = off;
off += size; off += size;
if (map) {
gst_buffer_append_memory (buf, gst_buffer_append_memory (buf,
gst_memory_new_wrapped (GST_MEMORY_FLAG_NO_SHARE, gst_memory_new_wrapped (GST_MEMORY_FLAG_NO_SHARE,
CVPixelBufferGetBaseAddressOfPlane (pixbuf, i), size, 0, size, CVPixelBufferGetBaseAddressOfPlane (pixbuf, i), size, 0, size,
NULL, NULL)); NULL, NULL));
} }
}
} else { } else {
int size; int size;
@ -114,10 +117,12 @@ gst_core_video_buffer_new (CVBufferRef cvbuf, GstVideoInfo * vinfo)
offset[0] = 0; offset[0] = 0;
size = stride[0] * CVPixelBufferGetHeight (pixbuf); size = stride[0] * CVPixelBufferGetHeight (pixbuf);
if (map) {
gst_buffer_append_memory (buf, gst_buffer_append_memory (buf,
gst_memory_new_wrapped (GST_MEMORY_FLAG_NO_SHARE, gst_memory_new_wrapped (GST_MEMORY_FLAG_NO_SHARE,
CVPixelBufferGetBaseAddress (pixbuf), size, 0, size, NULL, NULL)); CVPixelBufferGetBaseAddress (pixbuf), size, 0, size, NULL, NULL));
} }
}
if (vinfo) { if (vinfo) {
GstVideoMeta *video_meta; GstVideoMeta *video_meta;

View file

@ -41,7 +41,8 @@ typedef struct _GstCoreVideoMeta
} GstCoreVideoMeta; } GstCoreVideoMeta;
GstBuffer * gst_core_video_buffer_new (CVBufferRef cvbuf, GstBuffer * gst_core_video_buffer_new (CVBufferRef cvbuf,
GstVideoInfo *info); GstVideoInfo *info,
gboolean map);
GType gst_core_video_meta_api_get_type (void); GType gst_core_video_meta_api_get_type (void);
G_END_DECLS G_END_DECLS

View file

@ -434,7 +434,7 @@ openFailed:
[queueLock unlockWithCondition: [queueLock unlockWithCondition:
([queue count] == 0) ? NO_FRAMES : HAS_FRAME_OR_STOP_REQUEST]; ([queue count] == 0) ? NO_FRAMES : HAS_FRAME_OR_STOP_REQUEST];
*buf = gst_core_video_buffer_new ((CVBufferRef)frame, NULL); *buf = gst_core_video_buffer_new ((CVBufferRef)frame, NULL, TRUE);
CVBufferRelease (frame); CVBufferRelease (frame);
[self timestampBuffer:*buf]; [self timestampBuffer:*buf];

View file

@ -640,7 +640,9 @@ gst_vtdec_session_output_callback (void *decompression_output_ref_con,
* segment.format being undefined */ * segment.format being undefined */
goto release; goto release;
} }
buf = gst_core_video_buffer_new (image_buffer, &state->info); buf =
gst_core_video_buffer_new (image_buffer, &state->info,
vtdec->texture_cache == NULL);
gst_video_codec_state_unref (state); gst_video_codec_state_unref (state);
gst_buffer_copy_into (buf, frame->input_buffer, gst_buffer_copy_into (buf, frame->input_buffer,

View file

@ -1098,7 +1098,8 @@ gst_vtenc_encode_frame (GstVTEnc * self, GstVideoCodecFrame * frame)
goto cv_error; goto cv_error;
} }
outbuf = gst_core_video_buffer_new ((CVBufferRef) pbuf, &self->video_info); outbuf =
gst_core_video_buffer_new ((CVBufferRef) pbuf, &self->video_info, TRUE);
if (!gst_video_frame_map (&outframe, &self->video_info, outbuf, if (!gst_video_frame_map (&outframe, &self->video_info, outbuf,
GST_MAP_WRITE)) { GST_MAP_WRITE)) {
gst_video_frame_unmap (&inframe); gst_video_frame_unmap (&inframe);