2009-07-01 17:55:12 +00:00
|
|
|
/* Schrodinger
|
|
|
|
* Copyright (C) 2008 David Schleef <ds@schleef.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2010-03-21 20:39:18 +00:00
|
|
|
#include "gstschroutils.h"
|
|
|
|
|
2009-07-01 17:55:12 +00:00
|
|
|
//#define SCHRO_ENABLE_UNSTABLE_API
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <gst/video/video.h>
|
|
|
|
#include <schroedinger/schro.h>
|
|
|
|
#include <schroedinger/schrobitstream.h>
|
|
|
|
#include <schroedinger/schrovirtframe.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_EXTERN (schro_debug);
|
|
|
|
#define GST_CAT_DEFAULT schro_debug
|
|
|
|
|
2012-05-28 14:42:08 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GstBuffer *buf;
|
|
|
|
GstMapInfo info;
|
|
|
|
} FrameData;
|
2009-07-01 17:55:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_schro_frame_free (SchroFrame * frame, void *priv)
|
|
|
|
{
|
2012-05-28 14:42:08 +00:00
|
|
|
FrameData *data = priv;
|
|
|
|
|
|
|
|
gst_buffer_unmap (data->buf, &data->info);
|
|
|
|
gst_buffer_unref (data->buf);
|
|
|
|
|
|
|
|
g_slice_free (FrameData, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
GstBuffer *
|
|
|
|
gst_schro_frame_get_buffer (SchroFrame * frame)
|
|
|
|
{
|
|
|
|
if (frame->priv)
|
|
|
|
return gst_buffer_ref (((FrameData *) frame->priv)->buf);
|
|
|
|
|
|
|
|
return NULL;
|
2009-07-01 17:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SchroFrame *
|
|
|
|
gst_schro_buffer_wrap (GstBuffer * buf, GstVideoFormat format, int width,
|
|
|
|
int height)
|
|
|
|
{
|
|
|
|
SchroFrame *frame;
|
2012-05-28 14:42:08 +00:00
|
|
|
GstMapInfo info;
|
|
|
|
FrameData *data;
|
|
|
|
|
|
|
|
if (!gst_buffer_map (buf, &info, GST_MAP_READ))
|
|
|
|
return NULL;
|
2009-07-01 17:55:12 +00:00
|
|
|
|
|
|
|
switch (format) {
|
|
|
|
case GST_VIDEO_FORMAT_I420:
|
2012-05-28 14:42:08 +00:00
|
|
|
frame = schro_frame_new_from_data_I420 (info.data, width, height);
|
2009-07-01 17:55:12 +00:00
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_YV12:
|
2012-05-28 14:42:08 +00:00
|
|
|
frame = schro_frame_new_from_data_YV12 (info.data, width, height);
|
2009-07-01 17:55:12 +00:00
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_YUY2:
|
2012-05-28 14:42:08 +00:00
|
|
|
frame = schro_frame_new_from_data_YUY2 (info.data, width, height);
|
2009-07-01 17:55:12 +00:00
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_UYVY:
|
2012-05-28 14:42:08 +00:00
|
|
|
frame = schro_frame_new_from_data_UYVY (info.data, width, height);
|
2009-07-01 17:55:12 +00:00
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_AYUV:
|
2012-05-28 14:42:08 +00:00
|
|
|
frame = schro_frame_new_from_data_AYUV (info.data, width, height);
|
2009-07-01 17:55:12 +00:00
|
|
|
break;
|
2012-01-23 17:02:37 +00:00
|
|
|
#if SCHRO_CHECK_VERSION(1,0,12)
|
|
|
|
case GST_VIDEO_FORMAT_ARGB:
|
2012-05-28 14:42:08 +00:00
|
|
|
frame = schro_frame_new_from_data_ARGB (info.data, width, height);
|
2012-01-23 17:02:37 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2012-02-01 01:13:48 +00:00
|
|
|
#if SCHRO_CHECK_VERSION(1,0,11)
|
2012-01-22 23:48:28 +00:00
|
|
|
case GST_VIDEO_FORMAT_Y42B:
|
2012-05-28 14:42:08 +00:00
|
|
|
frame = schro_frame_new_from_data_Y42B (info.data, width, height);
|
2012-01-22 23:48:28 +00:00
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_Y444:
|
2012-05-28 14:42:08 +00:00
|
|
|
frame = schro_frame_new_from_data_Y444 (info.data, width, height);
|
2012-01-22 23:48:28 +00:00
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_v210:
|
2012-05-28 14:42:08 +00:00
|
|
|
frame = schro_frame_new_from_data_v210 (info.data, width, height);
|
2012-01-22 23:48:28 +00:00
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_v216:
|
2012-05-28 14:42:08 +00:00
|
|
|
frame = schro_frame_new_from_data_v216 (info.data, width, height);
|
2012-01-22 23:48:28 +00:00
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_AYUV64:
|
2012-05-28 14:42:08 +00:00
|
|
|
frame = schro_frame_new_from_data_AY64 (info.data, width, height);
|
2012-01-22 23:48:28 +00:00
|
|
|
break;
|
2009-07-01 17:55:12 +00:00
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
2011-01-08 03:12:11 +00:00
|
|
|
return NULL;
|
2009-07-01 17:55:12 +00:00
|
|
|
}
|
2012-05-28 14:42:08 +00:00
|
|
|
|
|
|
|
data = g_slice_new0 (FrameData);
|
|
|
|
data->buf = buf;
|
|
|
|
data->info = info;
|
|
|
|
schro_frame_set_free_callback (frame, gst_schro_frame_free, data);
|
2009-07-01 17:55:12 +00:00
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
schro_buf_free_func (gpointer priv)
|
|
|
|
{
|
|
|
|
SchroBuffer *buffer = (SchroBuffer *) priv;
|
|
|
|
|
|
|
|
schro_buffer_unref (buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* takes the reference */
|
|
|
|
GstBuffer *
|
|
|
|
gst_schro_wrap_schro_buffer (SchroBuffer * buffer)
|
|
|
|
{
|
2012-05-28 14:42:08 +00:00
|
|
|
GstMemory *mem;
|
|
|
|
GstBuffer *buf;
|
2012-02-22 10:44:23 +00:00
|
|
|
|
2012-05-28 14:42:08 +00:00
|
|
|
mem =
|
|
|
|
gst_memory_new_wrapped (0, buffer->data, buffer->length, 0,
|
|
|
|
buffer->length, buffer, schro_buf_free_func);
|
|
|
|
buf = gst_buffer_new ();
|
|
|
|
gst_buffer_append_memory (buf, mem);
|
|
|
|
|
|
|
|
return buf;
|
2009-07-01 17:55:12 +00:00
|
|
|
}
|
|
|
|
|
2012-05-28 14:42:08 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GstMemory *mem;
|
|
|
|
GstMapInfo info;
|
|
|
|
} BufferData;
|
|
|
|
|
2009-07-01 17:55:12 +00:00
|
|
|
static void
|
|
|
|
gst_schro_buffer_free (SchroBuffer * buffer, void *priv)
|
|
|
|
{
|
2012-05-28 14:42:08 +00:00
|
|
|
BufferData *data = priv;
|
|
|
|
|
|
|
|
gst_memory_unmap (data->mem, &data->info);
|
|
|
|
gst_memory_unref (data->mem);
|
|
|
|
g_slice_free (BufferData, priv);
|
2009-07-01 17:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SchroBuffer *
|
|
|
|
gst_schro_wrap_gst_buffer (GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
SchroBuffer *schrobuf;
|
2012-05-28 14:42:08 +00:00
|
|
|
GstMemory *mem;
|
|
|
|
GstMapInfo info;
|
|
|
|
BufferData *data;
|
|
|
|
|
|
|
|
mem = gst_buffer_get_all_memory (buffer);
|
|
|
|
if (!gst_memory_map (mem, &info, GST_MAP_READ)) {
|
|
|
|
GST_ERROR ("Couldn't get readable memory from gstbuffer");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME : We can't control if data won't be read/write outside
|
|
|
|
* of schro ... */
|
|
|
|
data = g_slice_new0 (BufferData);
|
|
|
|
data->info = info;
|
|
|
|
data->mem = mem;
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2012-05-28 14:42:08 +00:00
|
|
|
schrobuf = schro_buffer_new_with_data (info.data, info.size);
|
2009-07-01 17:55:12 +00:00
|
|
|
schrobuf->free = gst_schro_buffer_free;
|
2012-05-28 14:42:08 +00:00
|
|
|
schrobuf->priv = data;
|
2009-07-01 17:55:12 +00:00
|
|
|
|
|
|
|
return schrobuf;
|
|
|
|
}
|