2004-06-15 09:11:06 +00:00
|
|
|
/* GStreamer
|
|
|
|
*
|
|
|
|
* v4lmjpegsrc_calls.c: functions for hardware MJPEG video source
|
|
|
|
*
|
2002-01-31 22:22:42 +00:00
|
|
|
* Copyright (C) 2001-2002 Ronald Bultje <rbultje@ronald.bitfreak.net>
|
2001-12-23 15:31:15 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2003-03-09 15:07:53 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include "v4lmjpegsrc_calls.h"
|
|
|
|
|
|
|
|
/* On some systems MAP_FAILED seems to be missing */
|
|
|
|
#ifndef MAP_FAILED
|
|
|
|
#define MAP_FAILED ( (caddr_t) -1 )
|
|
|
|
#endif
|
|
|
|
|
2003-05-21 06:33:18 +00:00
|
|
|
#define MIN_BUFFERS_QUEUED 2
|
|
|
|
|
2004-06-15 09:11:06 +00:00
|
|
|
GST_DEBUG_CATEGORY_EXTERN (v4lmjpegsrc_debug);
|
|
|
|
#define GST_CAT_DEFAULT v4lmjpegsrc_debug
|
2002-09-09 07:12:29 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
enum
|
|
|
|
{
|
2003-05-21 06:33:18 +00:00
|
|
|
QUEUE_STATE_ERROR = -1,
|
|
|
|
QUEUE_STATE_READY_FOR_QUEUE,
|
|
|
|
QUEUE_STATE_QUEUED,
|
|
|
|
QUEUE_STATE_SYNCED,
|
|
|
|
};
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4lmjpegsrc_queue_frame():
|
|
|
|
* queue a frame for capturing
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_v4lmjpegsrc_queue_frame (GstV4lMjpegSrc * v4lmjpegsrc, gint num)
|
2001-12-23 15:31:15 +00:00
|
|
|
{
|
2004-06-15 09:11:06 +00:00
|
|
|
GST_DEBUG_OBJECT (v4lmjpegsrc, "queueing frame %d", num);
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2003-05-21 06:33:18 +00:00
|
|
|
if (v4lmjpegsrc->frame_queue_state[num] != QUEUE_STATE_READY_FOR_QUEUE) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
if (ioctl (GST_V4LELEMENT (v4lmjpegsrc)->video_fd, MJPIOC_QBUF_CAPT,
|
2004-03-15 19:32:28 +00:00
|
|
|
&num) < 0) {
|
2004-02-02 17:23:33 +00:00
|
|
|
GST_ELEMENT_ERROR (v4lmjpegsrc, RESOURCE, READ, (NULL),
|
2004-03-15 19:32:28 +00:00
|
|
|
("Error queueing a buffer (%d): %s", num, g_strerror (errno)));
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-05-21 06:33:18 +00:00
|
|
|
v4lmjpegsrc->frame_queue_state[num] = QUEUE_STATE_QUEUED;
|
|
|
|
v4lmjpegsrc->num_queued++;
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4lmjpegsrc_sync_next_frame():
|
|
|
|
* sync on the next frame for capturing
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_v4lmjpegsrc_sync_next_frame (GstV4lMjpegSrc * v4lmjpegsrc, gint * num)
|
2001-12-23 15:31:15 +00:00
|
|
|
{
|
2004-06-15 09:11:06 +00:00
|
|
|
GST_DEBUG_OBJECT (v4lmjpegsrc, "syncing on next frame");
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2003-05-21 06:33:18 +00:00
|
|
|
if (v4lmjpegsrc->num_queued <= 0) {
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
while (ioctl (GST_V4LELEMENT (v4lmjpegsrc)->video_fd,
|
2004-03-15 19:32:28 +00:00
|
|
|
MJPIOC_SYNC, &(v4lmjpegsrc->bsync)) < 0) {
|
2003-05-21 06:33:18 +00:00
|
|
|
if (errno != EINTR) {
|
2004-02-27 23:36:43 +00:00
|
|
|
GST_ELEMENT_ERROR (v4lmjpegsrc, RESOURCE, SYNC, (NULL), GST_ERROR_SYSTEM);
|
2003-05-21 06:33:18 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-06-15 09:11:06 +00:00
|
|
|
GST_DEBUG_OBJECT (v4lmjpegsrc, "Sync got interrupted");
|
2003-05-21 06:33:18 +00:00
|
|
|
}
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
*num = v4lmjpegsrc->bsync.frame;
|
|
|
|
|
2003-05-21 06:33:18 +00:00
|
|
|
v4lmjpegsrc->frame_queue_state[*num] = QUEUE_STATE_SYNCED;
|
|
|
|
v4lmjpegsrc->num_queued--;
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4lmjpegsrc_set_buffer():
|
|
|
|
* set buffer parameters (size/count)
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_v4lmjpegsrc_set_buffer (GstV4lMjpegSrc * v4lmjpegsrc,
|
|
|
|
gint numbufs, gint bufsize)
|
2001-12-23 15:31:15 +00:00
|
|
|
{
|
2004-06-15 09:11:06 +00:00
|
|
|
GST_DEBUG_OBJECT (v4lmjpegsrc,
|
|
|
|
"setting buffer info to numbufs = %d, bufsize = %d KB", numbufs, bufsize);
|
2004-03-14 22:34:34 +00:00
|
|
|
GST_V4L_CHECK_OPEN (GST_V4LELEMENT (v4lmjpegsrc));
|
|
|
|
GST_V4L_CHECK_NOT_ACTIVE (GST_V4LELEMENT (v4lmjpegsrc));
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2001-12-24 21:43:31 +00:00
|
|
|
v4lmjpegsrc->breq.size = bufsize * 1024;
|
2001-12-23 15:31:15 +00:00
|
|
|
v4lmjpegsrc->breq.count = numbufs;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4lmjpegsrc_set_capture():
|
|
|
|
* set capture parameters (simple)
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_v4lmjpegsrc_set_capture (GstV4lMjpegSrc * v4lmjpegsrc,
|
|
|
|
gint decimation, gint quality)
|
2001-12-23 15:31:15 +00:00
|
|
|
{
|
|
|
|
int norm, input, mw;
|
|
|
|
struct mjpeg_params bparm;
|
|
|
|
|
2004-06-15 09:11:06 +00:00
|
|
|
GST_DEBUG_OBJECT (v4lmjpegsrc, "setting decimation = %d, quality = %d",
|
|
|
|
decimation, quality);
|
2004-03-14 22:34:34 +00:00
|
|
|
GST_V4L_CHECK_OPEN (GST_V4LELEMENT (v4lmjpegsrc));
|
|
|
|
GST_V4L_CHECK_NOT_ACTIVE (GST_V4LELEMENT (v4lmjpegsrc));
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_v4l_get_chan_norm (GST_V4LELEMENT (v4lmjpegsrc), &input, &norm);
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
/* Query params for capture */
|
2004-03-14 22:34:34 +00:00
|
|
|
if (ioctl (GST_V4LELEMENT (v4lmjpegsrc)->video_fd, MJPIOC_G_PARAMS,
|
2004-03-15 19:32:28 +00:00
|
|
|
&bparm) < 0) {
|
2004-02-27 23:36:43 +00:00
|
|
|
GST_ELEMENT_ERROR (v4lmjpegsrc, RESOURCE, SETTINGS, (NULL),
|
2004-03-15 19:32:28 +00:00
|
|
|
GST_ERROR_SYSTEM);
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bparm.decimation = decimation;
|
|
|
|
bparm.quality = quality;
|
|
|
|
bparm.norm = norm;
|
|
|
|
bparm.input = input;
|
2004-03-15 19:32:28 +00:00
|
|
|
bparm.APP_len = 0; /* no JPEG markers - TODO: this is definately not right for decimation==1 */
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
mw = GST_V4LELEMENT (v4lmjpegsrc)->vcap.maxwidth;
|
|
|
|
if (mw != 768 && mw != 640) {
|
2001-12-23 15:31:15 +00:00
|
|
|
if (decimation == 1)
|
|
|
|
mw = 720;
|
|
|
|
else
|
|
|
|
mw = 704;
|
|
|
|
}
|
|
|
|
v4lmjpegsrc->end_width = mw / decimation;
|
2004-03-14 22:34:34 +00:00
|
|
|
v4lmjpegsrc->end_height = (norm == VIDEO_MODE_NTSC ? 480 : 576) / decimation;
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
/* TODO: interlacing */
|
|
|
|
|
|
|
|
/* Set params for capture */
|
2004-03-14 22:34:34 +00:00
|
|
|
if (ioctl (GST_V4LELEMENT (v4lmjpegsrc)->video_fd, MJPIOC_S_PARAMS,
|
2004-03-15 19:32:28 +00:00
|
|
|
&bparm) < 0) {
|
2004-02-27 23:36:43 +00:00
|
|
|
GST_ELEMENT_ERROR (v4lmjpegsrc, RESOURCE, SETTINGS, (NULL),
|
2004-03-15 19:32:28 +00:00
|
|
|
GST_ERROR_SYSTEM);
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4lmjpegsrc_set_capture_m():
|
|
|
|
* set capture parameters (advanced)
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
gboolean
|
|
|
|
gst_v4lmjpegsrc_set_capture_m (GstV4lMjpegSrc * v4lmjpegsrc,
|
|
|
|
gint x_offset,
|
|
|
|
gint y_offset,
|
|
|
|
gint width, gint height, gint h_decimation, gint v_decimation, gint quality)
|
2001-12-23 15:31:15 +00:00
|
|
|
{
|
|
|
|
gint norm, input;
|
|
|
|
gint maxwidth;
|
|
|
|
struct mjpeg_params bparm;
|
|
|
|
|
2004-06-15 09:11:06 +00:00
|
|
|
GST_DEBUG_OBJECT (v4lmjpegsrc, "setting x_offset = %d, y_offset = %d, "
|
2004-03-14 22:34:34 +00:00
|
|
|
"width = %d, height = %d, h_decimation = %d, v_decimation = %d, quality = %d\n",
|
|
|
|
x_offset, y_offset, width, height, h_decimation, v_decimation, quality);
|
|
|
|
GST_V4L_CHECK_OPEN (GST_V4LELEMENT (v4lmjpegsrc));
|
|
|
|
GST_V4L_CHECK_NOT_ACTIVE (GST_V4LELEMENT (v4lmjpegsrc));
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_v4l_get_chan_norm (GST_V4LELEMENT (v4lmjpegsrc), &input, &norm);
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
if (GST_V4LELEMENT (v4lmjpegsrc)->vcap.maxwidth != 768 &&
|
|
|
|
GST_V4LELEMENT (v4lmjpegsrc)->vcap.maxwidth != 640)
|
2001-12-23 15:31:15 +00:00
|
|
|
maxwidth = 720;
|
|
|
|
else
|
2004-03-14 22:34:34 +00:00
|
|
|
maxwidth = GST_V4LELEMENT (v4lmjpegsrc)->vcap.maxwidth;
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
/* Query params for capture */
|
2004-03-14 22:34:34 +00:00
|
|
|
if (ioctl (GST_V4LELEMENT (v4lmjpegsrc)->video_fd, MJPIOC_G_PARAMS,
|
2004-03-15 19:32:28 +00:00
|
|
|
&bparm) < 0) {
|
2004-02-27 23:36:43 +00:00
|
|
|
GST_ELEMENT_ERROR (v4lmjpegsrc, RESOURCE, SETTINGS, (NULL),
|
2004-03-15 19:32:28 +00:00
|
|
|
GST_ERROR_SYSTEM);
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bparm.decimation = 0;
|
|
|
|
bparm.quality = quality;
|
|
|
|
bparm.norm = norm;
|
|
|
|
bparm.input = input;
|
2004-03-15 19:32:28 +00:00
|
|
|
bparm.APP_len = 0; /* no JPEG markers - TODO: this is definately
|
|
|
|
* not right for decimation==1 */
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
if (width <= 0) {
|
|
|
|
if (x_offset < 0)
|
|
|
|
x_offset = 0;
|
|
|
|
width = (maxwidth == 720
|
2004-03-15 19:32:28 +00:00
|
|
|
&& h_decimation != 1) ? 704 : maxwidth - 2 * x_offset;
|
2004-03-14 22:34:34 +00:00
|
|
|
} else {
|
2001-12-23 15:31:15 +00:00
|
|
|
if (x_offset < 0)
|
2004-03-14 22:34:34 +00:00
|
|
|
x_offset = (maxwidth - width) / 2;
|
2001-12-23 15:31:15 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
if (height <= 0) {
|
2001-12-23 15:31:15 +00:00
|
|
|
if (y_offset < 0)
|
2004-03-14 22:34:34 +00:00
|
|
|
y_offset = 0;
|
|
|
|
height = (norm == VIDEO_MODE_NTSC) ? 480 : 576 - 2 * y_offset;
|
|
|
|
} else {
|
|
|
|
if (y_offset < 0)
|
|
|
|
y_offset = ((norm == VIDEO_MODE_NTSC) ? 480 : 576 - height) / 2;
|
2001-12-23 15:31:15 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
if (width + x_offset > maxwidth) {
|
2004-02-27 23:36:43 +00:00
|
|
|
GST_ELEMENT_ERROR (v4lmjpegsrc, RESOURCE, TOO_LAZY, (NULL),
|
2004-03-15 19:32:28 +00:00
|
|
|
("Image width+offset (%d) bigger than maximum (%d)",
|
|
|
|
width + x_offset, maxwidth));
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
if ((width % (bparm.HorDcm * 16)) != 0) {
|
2004-02-27 23:36:43 +00:00
|
|
|
GST_ELEMENT_ERROR (v4lmjpegsrc, STREAM, FORMAT, (NULL),
|
2004-03-15 19:32:28 +00:00
|
|
|
("Image width (%d) not multiple of %d (required for JPEG)",
|
|
|
|
width, bparm.HorDcm * 16));
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
if (height + y_offset > (norm == VIDEO_MODE_NTSC ? 480 : 576)) {
|
2004-02-27 23:36:43 +00:00
|
|
|
GST_ELEMENT_ERROR (v4lmjpegsrc, RESOURCE, TOO_LAZY, (NULL),
|
2004-03-15 19:32:28 +00:00
|
|
|
("Image height+offset (%d) bigger than maximum (%d)",
|
|
|
|
height + y_offset, (norm == VIDEO_MODE_NTSC ? 480 : 576)));
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
/* RJ: Image height must only be a multiple of 8, but geom_height
|
|
|
|
* is double the field height
|
|
|
|
*/
|
2004-03-14 22:34:34 +00:00
|
|
|
if ((height % (bparm.VerDcm * 16)) != 0) {
|
2004-02-27 23:36:43 +00:00
|
|
|
GST_ELEMENT_ERROR (v4lmjpegsrc, STREAM, FORMAT, (NULL),
|
2004-03-15 19:32:28 +00:00
|
|
|
("Image height (%d) not multiple of %d (required for JPEG)",
|
|
|
|
height, bparm.VerDcm * 16));
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bparm.img_x = x_offset;
|
|
|
|
bparm.img_width = width;
|
|
|
|
bparm.img_y = y_offset;
|
|
|
|
bparm.img_height = height;
|
|
|
|
bparm.HorDcm = h_decimation;
|
2004-03-14 22:34:34 +00:00
|
|
|
bparm.VerDcm = (v_decimation == 4) ? 2 : 1;
|
|
|
|
bparm.TmpDcm = (v_decimation == 1) ? 1 : 2;
|
|
|
|
bparm.field_per_buff = (v_decimation == 1) ? 2 : 1;
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
v4lmjpegsrc->end_width = width / h_decimation;
|
|
|
|
v4lmjpegsrc->end_width = height / v_decimation;
|
|
|
|
|
|
|
|
/* TODO: interlacing */
|
|
|
|
|
|
|
|
/* Set params for capture */
|
2004-03-14 22:34:34 +00:00
|
|
|
if (ioctl (GST_V4LELEMENT (v4lmjpegsrc)->video_fd, MJPIOC_S_PARAMS,
|
2004-03-15 19:32:28 +00:00
|
|
|
&bparm) < 0) {
|
2004-02-27 23:36:43 +00:00
|
|
|
GST_ELEMENT_ERROR (v4lmjpegsrc, RESOURCE, SETTINGS, (NULL),
|
2004-03-15 19:32:28 +00:00
|
|
|
GST_ERROR_SYSTEM);
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4lmjpegsrc_capture_init():
|
|
|
|
* initialize the capture system
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_v4lmjpegsrc_capture_init (GstV4lMjpegSrc * v4lmjpegsrc)
|
2001-12-23 15:31:15 +00:00
|
|
|
{
|
2004-06-15 09:11:06 +00:00
|
|
|
GST_DEBUG_OBJECT (v4lmjpegsrc, "initting capture subsystem");
|
2004-03-14 22:34:34 +00:00
|
|
|
GST_V4L_CHECK_OPEN (GST_V4LELEMENT (v4lmjpegsrc));
|
|
|
|
GST_V4L_CHECK_NOT_ACTIVE (GST_V4LELEMENT (v4lmjpegsrc));
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
/* Request buffers */
|
2004-03-14 22:34:34 +00:00
|
|
|
if (ioctl (GST_V4LELEMENT (v4lmjpegsrc)->video_fd,
|
2004-03-15 19:32:28 +00:00
|
|
|
MJPIOC_REQBUFS, &(v4lmjpegsrc->breq)) < 0) {
|
2004-02-27 23:36:43 +00:00
|
|
|
GST_ELEMENT_ERROR (v4lmjpegsrc, RESOURCE, READ, (NULL), GST_ERROR_SYSTEM);
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
if (v4lmjpegsrc->breq.count < MIN_BUFFERS_QUEUED) {
|
2004-02-27 23:36:43 +00:00
|
|
|
GST_ELEMENT_ERROR (v4lmjpegsrc, RESOURCE, READ, (NULL),
|
2004-03-15 19:32:28 +00:00
|
|
|
("Too little buffers. We got %ld, we want at least %d",
|
|
|
|
v4lmjpegsrc->breq.count, MIN_BUFFERS_QUEUED));
|
2003-05-02 21:16:55 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-06-15 09:11:06 +00:00
|
|
|
GST_INFO_OBJECT (v4lmjpegsrc, "Got %ld buffers of size %ld KB",
|
2004-03-14 22:34:34 +00:00
|
|
|
v4lmjpegsrc->breq.count, v4lmjpegsrc->breq.size / 1024);
|
2003-05-21 06:33:18 +00:00
|
|
|
|
|
|
|
/* keep track of queued buffers */
|
|
|
|
v4lmjpegsrc->frame_queue_state = (gint8 *)
|
2004-03-14 22:34:34 +00:00
|
|
|
g_malloc (sizeof (gint8) * v4lmjpegsrc->breq.count);
|
2003-05-21 06:33:18 +00:00
|
|
|
|
|
|
|
/* track how often to use each frame */
|
|
|
|
v4lmjpegsrc->use_num_times = (gint *)
|
2004-03-14 22:34:34 +00:00
|
|
|
g_malloc (sizeof (gint) * v4lmjpegsrc->breq.count);
|
2003-05-21 06:33:18 +00:00
|
|
|
|
|
|
|
/* lock for the frame_state */
|
2004-03-14 22:34:34 +00:00
|
|
|
v4lmjpegsrc->mutex_queue_state = g_mutex_new ();
|
|
|
|
v4lmjpegsrc->cond_queue_state = g_cond_new ();
|
2003-05-21 06:33:18 +00:00
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
/* Map the buffers */
|
2004-03-14 22:34:34 +00:00
|
|
|
GST_V4LELEMENT (v4lmjpegsrc)->buffer = mmap (0,
|
|
|
|
v4lmjpegsrc->breq.count * v4lmjpegsrc->breq.size,
|
|
|
|
PROT_READ | PROT_WRITE, MAP_SHARED,
|
|
|
|
GST_V4LELEMENT (v4lmjpegsrc)->video_fd, 0);
|
|
|
|
if (GST_V4LELEMENT (v4lmjpegsrc)->buffer == MAP_FAILED) {
|
2004-02-27 23:36:43 +00:00
|
|
|
GST_ELEMENT_ERROR (v4lmjpegsrc, RESOURCE, TOO_LAZY, (NULL),
|
2004-03-15 19:32:28 +00:00
|
|
|
("Error mapping video buffers: %s", g_strerror (errno)));
|
2004-03-14 22:34:34 +00:00
|
|
|
GST_V4LELEMENT (v4lmjpegsrc)->buffer = NULL;
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4lmjpegsrc_capture_start():
|
|
|
|
* start streaming capture
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_v4lmjpegsrc_capture_start (GstV4lMjpegSrc * v4lmjpegsrc)
|
2001-12-23 15:31:15 +00:00
|
|
|
{
|
|
|
|
int n;
|
|
|
|
|
2004-06-15 09:11:06 +00:00
|
|
|
GST_DEBUG_OBJECT (v4lmjpegsrc, "starting capture");
|
2004-03-14 22:34:34 +00:00
|
|
|
GST_V4L_CHECK_OPEN (GST_V4LELEMENT (v4lmjpegsrc));
|
|
|
|
GST_V4L_CHECK_ACTIVE (GST_V4LELEMENT (v4lmjpegsrc));
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
g_mutex_lock (v4lmjpegsrc->mutex_queue_state);
|
2003-05-21 06:33:18 +00:00
|
|
|
|
|
|
|
v4lmjpegsrc->quit = FALSE;
|
|
|
|
v4lmjpegsrc->num_queued = 0;
|
|
|
|
v4lmjpegsrc->queue_frame = 0;
|
|
|
|
|
|
|
|
/* set all buffers ready to queue , this starts streaming capture */
|
2004-03-14 22:34:34 +00:00
|
|
|
for (n = 0; n < v4lmjpegsrc->breq.count; n++) {
|
2003-05-21 06:33:18 +00:00
|
|
|
v4lmjpegsrc->frame_queue_state[n] = QUEUE_STATE_READY_FOR_QUEUE;
|
2004-03-14 22:34:34 +00:00
|
|
|
if (!gst_v4lmjpegsrc_queue_frame (v4lmjpegsrc, n)) {
|
|
|
|
g_mutex_unlock (v4lmjpegsrc->mutex_queue_state);
|
|
|
|
gst_v4lmjpegsrc_capture_stop (v4lmjpegsrc);
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
2003-05-21 06:33:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
ext/ogg/gstoggmux.c: Basic pad template which accepts OGM tracks, speex, flac, vorbis and theora. Any is incorrect.
Original commit message from CVS:
* ext/ogg/gstoggmux.c:
Basic pad template which accepts OGM tracks, speex, flac, vorbis
and theora. Any is incorrect.
* gst/asfdemux/gstasfmux.c: (gst_asfmux_vidsink_link):
Fix caps.
* sys/v4l/gstv4lmjpegsink.c: (gst_v4lmjpegsink_base_init):
* sys/v4l/gstv4lmjpegsrc.c: (gst_v4lmjpegsrc_base_init),
(gst_v4lmjpegsrc_init), (gst_v4lmjpegsrc_srcconnect),
(gst_v4lmjpegsrc_getcaps), (gst_v4lmjpegsrc_change_state):
* sys/v4l/gstv4lmjpegsrc.h:
* sys/v4l/gstv4lsrc.c: (gst_v4lsrc_src_link), (gst_v4lsrc_getcaps),
(gst_v4lsrc_change_state):
* sys/v4l/v4lmjpegsrc_calls.c: (gst_v4lmjpegsrc_capture_start),
(gst_v4lmjpegsrc_capture_stop):
Fix caps. Keep track of internal state. Work.
2004-10-24 13:41:18 +00:00
|
|
|
v4lmjpegsrc->is_capturing = TRUE;
|
2004-03-14 22:34:34 +00:00
|
|
|
g_mutex_unlock (v4lmjpegsrc->mutex_queue_state);
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4lmjpegsrc_grab_frame():
|
|
|
|
* grab one frame during streaming capture
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_v4lmjpegsrc_grab_frame (GstV4lMjpegSrc * v4lmjpegsrc,
|
|
|
|
gint * num, gint * size)
|
2001-12-23 15:31:15 +00:00
|
|
|
{
|
2004-06-15 09:11:06 +00:00
|
|
|
GST_DEBUG_OBJECT (v4lmjpegsrc, "grabbing frame");
|
2004-03-14 22:34:34 +00:00
|
|
|
GST_V4L_CHECK_OPEN (GST_V4LELEMENT (v4lmjpegsrc));
|
|
|
|
GST_V4L_CHECK_ACTIVE (GST_V4LELEMENT (v4lmjpegsrc));
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
g_mutex_lock (v4lmjpegsrc->mutex_queue_state);
|
2003-05-21 06:33:18 +00:00
|
|
|
|
|
|
|
/* do we have enough frames? */
|
|
|
|
while (v4lmjpegsrc->num_queued < MIN_BUFFERS_QUEUED ||
|
2004-03-14 22:34:34 +00:00
|
|
|
v4lmjpegsrc->frame_queue_state[v4lmjpegsrc->queue_frame] ==
|
|
|
|
QUEUE_STATE_READY_FOR_QUEUE) {
|
2003-05-21 06:33:18 +00:00
|
|
|
while (v4lmjpegsrc->frame_queue_state[v4lmjpegsrc->queue_frame] !=
|
2004-03-15 19:32:28 +00:00
|
|
|
QUEUE_STATE_READY_FOR_QUEUE && !v4lmjpegsrc->quit) {
|
2004-06-15 09:11:06 +00:00
|
|
|
GST_DEBUG_OBJECT (v4lmjpegsrc,
|
|
|
|
"Waiting for frames to become available (%d < %d)",
|
2004-03-15 19:32:28 +00:00
|
|
|
v4lmjpegsrc->num_queued, MIN_BUFFERS_QUEUED);
|
2004-03-14 22:34:34 +00:00
|
|
|
g_cond_wait (v4lmjpegsrc->cond_queue_state,
|
2004-03-15 19:32:28 +00:00
|
|
|
v4lmjpegsrc->mutex_queue_state);
|
2003-05-21 06:33:18 +00:00
|
|
|
}
|
|
|
|
if (v4lmjpegsrc->quit) {
|
2004-03-14 22:34:34 +00:00
|
|
|
g_mutex_unlock (v4lmjpegsrc->mutex_queue_state);
|
2004-03-15 19:32:28 +00:00
|
|
|
return TRUE; /* it won't get through anyway */
|
2003-05-21 06:33:18 +00:00
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
if (!gst_v4lmjpegsrc_queue_frame (v4lmjpegsrc, v4lmjpegsrc->queue_frame)) {
|
|
|
|
g_mutex_unlock (v4lmjpegsrc->mutex_queue_state);
|
2003-05-21 06:33:18 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
v4lmjpegsrc->queue_frame =
|
2004-03-15 19:32:28 +00:00
|
|
|
(v4lmjpegsrc->queue_frame + 1) % v4lmjpegsrc->breq.count;
|
2003-05-21 06:33:18 +00:00
|
|
|
}
|
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
/* syncing on the buffer grabs it */
|
2004-03-14 22:34:34 +00:00
|
|
|
if (!gst_v4lmjpegsrc_sync_next_frame (v4lmjpegsrc, num)) {
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
2003-05-21 06:33:18 +00:00
|
|
|
}
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
*size = v4lmjpegsrc->bsync.length;
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
g_mutex_unlock (v4lmjpegsrc->mutex_queue_state);
|
2003-05-21 06:33:18 +00:00
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4lmjpegsrc_get_buffer():
|
|
|
|
* get the memory address of a single buffer
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
guint8 *
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_v4lmjpegsrc_get_buffer (GstV4lMjpegSrc * v4lmjpegsrc, gint num)
|
2001-12-23 15:31:15 +00:00
|
|
|
{
|
2004-03-14 22:34:34 +00:00
|
|
|
/*DEBUG("gst_v4lmjpegsrc_get_buffer(), num = %d", num); */
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
if (!GST_V4L_IS_ACTIVE (GST_V4LELEMENT (v4lmjpegsrc)) ||
|
|
|
|
!GST_V4L_IS_OPEN (GST_V4LELEMENT (v4lmjpegsrc)))
|
2001-12-24 21:43:31 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (num < 0 || num >= v4lmjpegsrc->breq.count)
|
2001-12-23 15:31:15 +00:00
|
|
|
return NULL;
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
return GST_V4LELEMENT (v4lmjpegsrc)->buffer + (v4lmjpegsrc->breq.size * num);
|
2001-12-23 15:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4lmjpegsrc_requeue_frame():
|
|
|
|
* requeue a frame for capturing
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_v4lmjpegsrc_requeue_frame (GstV4lMjpegSrc * v4lmjpegsrc, gint num)
|
2001-12-23 15:31:15 +00:00
|
|
|
{
|
2004-06-15 09:11:06 +00:00
|
|
|
GST_DEBUG_OBJECT (v4lmjpegsrc, "requeueing frame %d", num);
|
2004-03-14 22:34:34 +00:00
|
|
|
GST_V4L_CHECK_OPEN (GST_V4LELEMENT (v4lmjpegsrc));
|
|
|
|
GST_V4L_CHECK_ACTIVE (GST_V4LELEMENT (v4lmjpegsrc));
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2003-05-21 06:33:18 +00:00
|
|
|
/* mark frame as 'ready to requeue' */
|
2004-03-14 22:34:34 +00:00
|
|
|
g_mutex_lock (v4lmjpegsrc->mutex_queue_state);
|
2003-05-21 06:33:18 +00:00
|
|
|
|
|
|
|
if (v4lmjpegsrc->frame_queue_state[num] != QUEUE_STATE_SYNCED) {
|
2004-02-27 23:36:43 +00:00
|
|
|
GST_ELEMENT_ERROR (v4lmjpegsrc, RESOURCE, TOO_LAZY, (NULL),
|
2004-03-15 19:32:28 +00:00
|
|
|
("Invalid state %d (expected %d), can't requeue",
|
|
|
|
v4lmjpegsrc->frame_queue_state[num], QUEUE_STATE_SYNCED));
|
2001-12-23 15:31:15 +00:00
|
|
|
return FALSE;
|
2003-05-21 06:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
v4lmjpegsrc->frame_queue_state[num] = QUEUE_STATE_READY_FOR_QUEUE;
|
|
|
|
|
|
|
|
/* let an optional wait know */
|
2004-03-14 22:34:34 +00:00
|
|
|
g_cond_broadcast (v4lmjpegsrc->cond_queue_state);
|
2003-05-21 06:33:18 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
g_mutex_unlock (v4lmjpegsrc->mutex_queue_state);
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4lmjpegsrc_capture_stop():
|
|
|
|
* stop streaming capture
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_v4lmjpegsrc_capture_stop (GstV4lMjpegSrc * v4lmjpegsrc)
|
2001-12-23 15:31:15 +00:00
|
|
|
{
|
2003-05-21 06:33:18 +00:00
|
|
|
int n;
|
|
|
|
|
2004-06-15 09:11:06 +00:00
|
|
|
GST_DEBUG_OBJECT (v4lmjpegsrc, "stopping capture");
|
2004-03-14 22:34:34 +00:00
|
|
|
GST_V4L_CHECK_OPEN (GST_V4LELEMENT (v4lmjpegsrc));
|
|
|
|
GST_V4L_CHECK_ACTIVE (GST_V4LELEMENT (v4lmjpegsrc));
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
g_mutex_lock (v4lmjpegsrc->mutex_queue_state);
|
2003-05-21 06:33:18 +00:00
|
|
|
|
|
|
|
/* make an optional pending wait stop */
|
|
|
|
v4lmjpegsrc->quit = TRUE;
|
2004-03-14 22:34:34 +00:00
|
|
|
g_cond_broadcast (v4lmjpegsrc->cond_queue_state);
|
|
|
|
|
2003-05-21 06:33:18 +00:00
|
|
|
/* sync on remaining frames */
|
|
|
|
while (v4lmjpegsrc->num_queued > 0) {
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_v4lmjpegsrc_sync_next_frame (v4lmjpegsrc, &n);
|
2003-05-21 06:33:18 +00:00
|
|
|
}
|
|
|
|
|
ext/ogg/gstoggmux.c: Basic pad template which accepts OGM tracks, speex, flac, vorbis and theora. Any is incorrect.
Original commit message from CVS:
* ext/ogg/gstoggmux.c:
Basic pad template which accepts OGM tracks, speex, flac, vorbis
and theora. Any is incorrect.
* gst/asfdemux/gstasfmux.c: (gst_asfmux_vidsink_link):
Fix caps.
* sys/v4l/gstv4lmjpegsink.c: (gst_v4lmjpegsink_base_init):
* sys/v4l/gstv4lmjpegsrc.c: (gst_v4lmjpegsrc_base_init),
(gst_v4lmjpegsrc_init), (gst_v4lmjpegsrc_srcconnect),
(gst_v4lmjpegsrc_getcaps), (gst_v4lmjpegsrc_change_state):
* sys/v4l/gstv4lmjpegsrc.h:
* sys/v4l/gstv4lsrc.c: (gst_v4lsrc_src_link), (gst_v4lsrc_getcaps),
(gst_v4lsrc_change_state):
* sys/v4l/v4lmjpegsrc_calls.c: (gst_v4lmjpegsrc_capture_start),
(gst_v4lmjpegsrc_capture_stop):
Fix caps. Keep track of internal state. Work.
2004-10-24 13:41:18 +00:00
|
|
|
v4lmjpegsrc->is_capturing = FALSE;
|
2004-03-14 22:34:34 +00:00
|
|
|
g_mutex_unlock (v4lmjpegsrc->mutex_queue_state);
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4lmjpegsrc_capture_deinit():
|
|
|
|
* deinitialize the capture system
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_v4lmjpegsrc_capture_deinit (GstV4lMjpegSrc * v4lmjpegsrc)
|
2001-12-23 15:31:15 +00:00
|
|
|
{
|
2004-06-15 09:11:06 +00:00
|
|
|
GST_DEBUG_OBJECT (v4lmjpegsrc, "quitting capture subsystem");
|
2004-03-14 22:34:34 +00:00
|
|
|
GST_V4L_CHECK_OPEN (GST_V4LELEMENT (v4lmjpegsrc));
|
|
|
|
GST_V4L_CHECK_ACTIVE (GST_V4LELEMENT (v4lmjpegsrc));
|
2001-12-23 15:31:15 +00:00
|
|
|
|
|
|
|
/* unmap the buffer */
|
2004-03-14 22:34:34 +00:00
|
|
|
munmap (GST_V4LELEMENT (v4lmjpegsrc)->buffer,
|
|
|
|
v4lmjpegsrc->breq.size * v4lmjpegsrc->breq.count);
|
|
|
|
GST_V4LELEMENT (v4lmjpegsrc)->buffer = NULL;
|
2001-12-23 15:31:15 +00:00
|
|
|
|
2003-05-21 06:33:18 +00:00
|
|
|
/* free buffer tracker */
|
2004-03-14 22:34:34 +00:00
|
|
|
g_mutex_free (v4lmjpegsrc->mutex_queue_state);
|
|
|
|
g_cond_free (v4lmjpegsrc->cond_queue_state);
|
|
|
|
g_free (v4lmjpegsrc->frame_queue_state);
|
|
|
|
g_free (v4lmjpegsrc->use_num_times);
|
2003-05-02 21:16:55 +00:00
|
|
|
|
2001-12-23 15:31:15 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|