Skip to contentSkip to conversation

uvcvideo: Add support for MPEG-2 TS payload

RFC PATCH In review Stephan Lachowsky 2 participants 5 messages Jan 28, 2011 – Feb 19, 2011 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 uvcvideo: Add support for MPEG-2 TS payload

Parse the UVC 1.0 and UVC 1.1 VS_FORMAT_MPEG2TS descriptors. This a stream based format, so we generate a dummy frame descriptor with a dummy frame interval range.

---
 drivers/media/video/uvc/uvc_driver.c |   41 ++++++++++++++++++++++++++++++++++
 drivers/media/video/uvc/uvcvideo.h   |    3 ++
 2 files changed, 44 insertions(+), 0 deletions(-)
drivers/media/video/uvc/uvc_driver.c +41 -0
index a1e9dfb..6bcb9e1 100644
@@ -103,6 +103,11 @@ static struct uvc_format_desc uvc_fmts[] = {
 		.guid		= UVC_GUID_FORMAT_BY8,
 		.fcc		= V4L2_PIX_FMT_SBGGR8,
 	},
+	{
+		.name		= "MPEG2 TS",
+		.guid		= UVC_GUID_FORMAT_MPEG,
+		.fcc		= V4L2_PIX_FMT_MPEG,
+	},
 };
 
 /* ------------------------------------------------------------------------
@@ -398,6 +403,33 @@ static int uvc_parse_format(struct uvc_device *dev,
 		break;
 
 	case UVC_VS_FORMAT_MPEG2TS:
+		n = dev->uvc_version >= 0x0110 ? 23 : 7;
+		if (buflen < n) {
+			uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
+			       "interface %d FORMAT error\n",
+			       dev->udev->devnum,
+			       alts->desc.bInterfaceNumber);
+			return -EINVAL;
+		}
+
+		strlcpy(format->name, "MPEG2 TS", sizeof format->name);
+		format->fcc = V4L2_PIX_FMT_MPEG;
+		format->flags = UVC_FMT_FLAG_COMPRESSED | UVC_FMT_FLAG_STREAM;
+		format->bpp = 0;
+		ftype = 0;
+
+		/* Create a dummy frame descriptor. */
+		frame = &format->frame[0];
+		memset(&format->frame[0], 0, sizeof format->frame[0]);
+		frame->bFrameIntervalType = 0;
+		frame->dwDefaultFrameInterval = 1;
+		frame->dwFrameInterval = *intervals;
+		*(*intervals)++ = 1;
+		*(*intervals)++ = 10000000;
+		*(*intervals)++ = 1;
+		format->nframes = 1;
+		break;
+
 	case UVC_VS_FORMAT_STREAM_BASED:
 		/* Not supported yet. */
 	default:
@@ -673,6 +705,14 @@ static int uvc_parse_streaming(struct uvc_device *dev,
 			break;
 
 		case UVC_VS_FORMAT_MPEG2TS:
+			/* MPEG2TS format has no frame descriptor. We will create a
+			 * dummy frame descriptor with a dummy frame interval range.
+			 */
+			nformats++;
+			nframes++;
+			nintervals += 3;
+			break;
+
 		case UVC_VS_FORMAT_STREAM_BASED:
 			uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
 				"interface %d FORMAT %u is not supported.\n",
@@ -724,6 +764,7 @@ static int uvc_parse_streaming(struct uvc_device *dev,
 		switch (buffer[2]) {
 		case UVC_VS_FORMAT_UNCOMPRESSED:
 		case UVC_VS_FORMAT_MJPEG:
+		case UVC_VS_FORMAT_MPEG2TS:
 		case UVC_VS_FORMAT_DV:
 		case UVC_VS_FORMAT_FRAME_BASED:
 			format->frame = frame;
drivers/media/video/uvc/uvcvideo.h +3 -0
index 45f01e7..e522f99 100644
@@ -152,6 +152,9 @@ struct uvc_xu_control {
 #define UVC_GUID_FORMAT_BY8 \
 	{ 'B',  'Y',  '8',  ' ', 0x00, 0x00, 0x10, 0x00, \
 	 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
+#define UVC_GUID_FORMAT_MPEG \
+	{ 'M',  'P',  'E',  'G', 0x00, 0x00, 0x10, 0x00, \
+	 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
 
 /* ------------------------------------------------------------------------
  * Driver specific constants.
Signature · 1 line
1.7.3.5
#1 lore raw

Hi Stephan,

Quoted 3 lines · On Friday 28 January 2011 20:35:05 Stephan Lachowsky wrote:

Parse the UVC 1.0 and UVC 1.1 VS_FORMAT_MPEG2TS descriptors. This a stream based format, so we generate a dummy frame descriptor with a dummy frame interval range.

Thanks for the patch, and sorry for the late reply.

Don't you also need to implement support for the V4L2 MPEG CIDs ? I would expect the driver to support at least the controls used to select the MPEG format (MPEG2, TS), even if they're hardcoded to MPEG2-TS.

Quoted 95 lines
---
 drivers/media/video/uvc/uvc_driver.c |   41
++++++++++++++++++++++++++++++++++ drivers/media/video/uvc/uvcvideo.h   | 
  3 ++
 2 files changed, 44 insertions(+), 0 deletions(-)
(quoted diff) +0 -0

b/drivers/media/video/uvc/uvc_driver.c index a1e9dfb..6bcb9e1 100644

drivers/media/video/uvc/uvc_driver.c +41 -1
@@ -103,6 +103,11 @@ static struct uvc_format_desc uvc_fmts[] = {
 		.guid		= UVC_GUID_FORMAT_BY8,
 		.fcc		= V4L2_PIX_FMT_SBGGR8,
 	},
+	{
+		.name		= "MPEG2 TS",
+		.guid		= UVC_GUID_FORMAT_MPEG,
+		.fcc		= V4L2_PIX_FMT_MPEG,
+	},
 };
 
 /*
------------------------------------------------------------------------
@@ -398,6 +403,33 @@ static int uvc_parse_format(struct uvc_device *dev,
 break;
 
 	case UVC_VS_FORMAT_MPEG2TS:
+		n = dev->uvc_version >= 0x0110 ? 23 : 7;
+		if (buflen < n) {
+			uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
+			       "interface %d FORMAT error\n",
+			       dev->udev->devnum,
+			       alts->desc.bInterfaceNumber);
+			return -EINVAL;
+		}
+
+		strlcpy(format->name, "MPEG2 TS", sizeof format->name);
+		format->fcc = V4L2_PIX_FMT_MPEG;
+		format->flags = UVC_FMT_FLAG_COMPRESSED | UVC_FMT_FLAG_STREAM;
+		format->bpp = 0;
+		ftype = 0;
+
+		/* Create a dummy frame descriptor. */
+		frame = &format->frame[0];
+		memset(&format->frame[0], 0, sizeof format->frame[0]);
+		frame->bFrameIntervalType = 0;
+		frame->dwDefaultFrameInterval = 1;
+		frame->dwFrameInterval = *intervals;
+		*(*intervals)++ = 1;
+		*(*intervals)++ = 10000000;
+		*(*intervals)++ = 1;
+		format->nframes = 1;
+		break;
+
 	case UVC_VS_FORMAT_STREAM_BASED:
 		/* Not supported yet. */
 	default:
@@ -673,6 +705,14 @@ static int uvc_parse_streaming(struct uvc_device *dev,
 			break;
 
 		case UVC_VS_FORMAT_MPEG2TS:
+			/* MPEG2TS format has no frame descriptor. We will create a
+			 * dummy frame descriptor with a dummy frame interval range.
+			 */
+			nformats++;
+			nframes++;
+			nintervals += 3;
+			break;
+
 		case UVC_VS_FORMAT_STREAM_BASED:
 			uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
 				"interface %d FORMAT %u is not supported.\n",
@@ -724,6 +764,7 @@ static int uvc_parse_streaming(struct uvc_device *dev,
 		switch (buffer[2]) {
 		case UVC_VS_FORMAT_UNCOMPRESSED:
 		case UVC_VS_FORMAT_MJPEG:
+		case UVC_VS_FORMAT_MPEG2TS:
 		case UVC_VS_FORMAT_DV:
 		case UVC_VS_FORMAT_FRAME_BASED:
 			format->frame = frame;
(quoted diff) +0 -0

b/drivers/media/video/uvc/uvcvideo.h index 45f01e7..e522f99 100644

drivers/media/video/uvc/uvcvideo.h +3 -1
@@ -152,6 +152,9 @@ struct uvc_xu_control {
 #define UVC_GUID_FORMAT_BY8 \
 	{ 'B',  'Y',  '8',  ' ', 0x00, 0x00, 0x10, 0x00, \
 	 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
+#define UVC_GUID_FORMAT_MPEG \
+	{ 'M',  'P',  'E',  'G', 0x00, 0x00, 0x10, 0x00, \
+	 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
 
 /*
------------------------------------------------------------------------ *

Driver specific constants.

Signature · 3 lines
Regards,

Laurent Pinchart
#2 lore raw

Hi Laurent,

Quoted 9 lines · Laurent Pinchart

Hi Stephan,

Quoted 3 lines · On Friday 28 January 2011 20:35:05 Stephan Lachowsky wrote:

Parse the UVC 1.0 and UVC 1.1 VS_FORMAT_MPEG2TS descriptors. This a stream based format, so we generate a dummy frame descriptor with a dummy frame interval range.

Thanks for the patch, and sorry for the late reply.

No worries, just glad to have the moss knocked off the stone.

Quoted 3 lines

Don't you also need to implement support for the V4L2 MPEG CIDs ? I would expect the driver to support at least the controls used to select the MPEG format (MPEG2, TS), even if they're hardcoded to MPEG2-TS.

That would be possible, for the stream type there is your choice of MPEG2-TS so that is trivial. There are a very limited set of standardized controls that can be mapped: wKeyFrameRate, wPFrameRate, wCompQuality from the VS probe/commit (GOP size, B frames, bitrate).

Since these controls are optional in the spec, and an overly simplistic projection of the encoder's actual configuration space, device manufactures (typically) choose instead to use custom XUs that expose richer more representative ones.

Given this state of affairs, I think it would be prudent to blindly forward the data stream (Which is all, in essence, this patch enables) leaving the configuration to userspace.

I'm not suggesting we preclude adding XU -> MPEG2 CID mappings into uvcvideo later, just that as is this is a valuable step forward.

Stephan

Quoted 96 lines
Quoted 95 lines
---
 drivers/media/video/uvc/uvc_driver.c |   41
++++++++++++++++++++++++++++++++++ drivers/media/video/uvc/uvcvideo.h   | 
  3 ++
 2 files changed, 44 insertions(+), 0 deletions(-)
(quoted diff) +0 -0

b/drivers/media/video/uvc/uvc_driver.c index a1e9dfb..6bcb9e1 100644

drivers/media/video/uvc/uvc_driver.c +41 -1
@@ -103,6 +103,11 @@ static struct uvc_format_desc uvc_fmts[] = {
 		.guid		= UVC_GUID_FORMAT_BY8,
 		.fcc		= V4L2_PIX_FMT_SBGGR8,
 	},
+	{
+		.name		= "MPEG2 TS",
+		.guid		= UVC_GUID_FORMAT_MPEG,
+		.fcc		= V4L2_PIX_FMT_MPEG,
+	},
 };
 
 /*
------------------------------------------------------------------------
@@ -398,6 +403,33 @@ static int uvc_parse_format(struct uvc_device *dev,
 break;
 
 	case UVC_VS_FORMAT_MPEG2TS:
+		n = dev->uvc_version >= 0x0110 ? 23 : 7;
+		if (buflen < n) {
+			uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
+			       "interface %d FORMAT error\n",
+			       dev->udev->devnum,
+			       alts->desc.bInterfaceNumber);
+			return -EINVAL;
+		}
+
+		strlcpy(format->name, "MPEG2 TS", sizeof format->name);
+		format->fcc = V4L2_PIX_FMT_MPEG;
+		format->flags = UVC_FMT_FLAG_COMPRESSED | UVC_FMT_FLAG_STREAM;
+		format->bpp = 0;
+		ftype = 0;
+
+		/* Create a dummy frame descriptor. */
+		frame = &format->frame[0];
+		memset(&format->frame[0], 0, sizeof format->frame[0]);
+		frame->bFrameIntervalType = 0;
+		frame->dwDefaultFrameInterval = 1;
+		frame->dwFrameInterval = *intervals;
+		*(*intervals)++ = 1;
+		*(*intervals)++ = 10000000;
+		*(*intervals)++ = 1;
+		format->nframes = 1;
+		break;
+
 	case UVC_VS_FORMAT_STREAM_BASED:
 		/* Not supported yet. */
 	default:
@@ -673,6 +705,14 @@ static int uvc_parse_streaming(struct uvc_device *dev,
 			break;
 
 		case UVC_VS_FORMAT_MPEG2TS:
+			/* MPEG2TS format has no frame descriptor. We will create a
+			 * dummy frame descriptor with a dummy frame interval range.
+			 */
+			nformats++;
+			nframes++;
+			nintervals += 3;
+			break;
+
 		case UVC_VS_FORMAT_STREAM_BASED:
 			uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
 				"interface %d FORMAT %u is not supported.\n",
@@ -724,6 +764,7 @@ static int uvc_parse_streaming(struct uvc_device *dev,
 		switch (buffer[2]) {
 		case UVC_VS_FORMAT_UNCOMPRESSED:
 		case UVC_VS_FORMAT_MJPEG:
+		case UVC_VS_FORMAT_MPEG2TS:
 		case UVC_VS_FORMAT_DV:
 		case UVC_VS_FORMAT_FRAME_BASED:
 			format->frame = frame;
(quoted diff) +0 -0

b/drivers/media/video/uvc/uvcvideo.h index 45f01e7..e522f99 100644

drivers/media/video/uvc/uvcvideo.h +3 -1
@@ -152,6 +152,9 @@ struct uvc_xu_control {
 #define UVC_GUID_FORMAT_BY8 \
 	{ 'B',  'Y',  '8',  ' ', 0x00, 0x00, 0x10, 0x00, \
 	 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
+#define UVC_GUID_FORMAT_MPEG \
+	{ 'M',  'P',  'E',  'G', 0x00, 0x00, 0x10, 0x00, \
+	 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
 
 /*
------------------------------------------------------------------------ *

Driver specific constants.

#3 lore raw

Hi Stephan,

Quoted 24 lines · On Thursday 17 February 2011 18:18:38 Stephan Lachowsky wrote:
Quoted 6 lines · Laurent Pinchart
Quoted 3 lines · On Friday 28 January 2011 20:35:05 Stephan Lachowsky wrote:

Parse the UVC 1.0 and UVC 1.1 VS_FORMAT_MPEG2TS descriptors. This a stream based format, so we generate a dummy frame descriptor with a dummy frame interval range.

Thanks for the patch, and sorry for the late reply.

No worries, just glad to have the moss knocked off the stone.

Quoted 3 lines

Don't you also need to implement support for the V4L2 MPEG CIDs ? I would expect the driver to support at least the controls used to select the MPEG format (MPEG2, TS), even if they're hardcoded to MPEG2-TS.

That would be possible, for the stream type there is your choice of MPEG2-TS so that is trivial. There are a very limited set of standardized controls that can be mapped: wKeyFrameRate, wPFrameRate, wCompQuality from the VS probe/commit (GOP size, B frames, bitrate).

Since these controls are optional in the spec, and an overly simplistic projection of the encoder's actual configuration space, device manufactures (typically) choose instead to use custom XUs that expose richer more representative ones.

Quoted 6 lines

Given this state of affairs, I think it would be prudent to blindly forward the data stream (Which is all, in essence, this patch enables) leaving the configuration to userspace.

I'm not suggesting we preclude adding XU -> MPEG2 CID mappings into uvcvideo later, just that as is this is a valuable step forward.

I agree with this, but I would still implement support for the V4L2_CID_MPEG_STREAM_TYPE control. MPEG applications expect it to be supported.

Signature · 3 lines
Regards,

Laurent Pinchart
#4 lore raw

Hi Laurent,

Quoted 31 lines · Laurent Pinchart

Hi Stephan,

Quoted 28 lines · On Thursday 17 February 2011 18:18:38 Stephan Lachowsky wrote:
Quoted 6 lines · Laurent Pinchart
Quoted 3 lines · On Friday 28 January 2011 20:35:05 Stephan Lachowsky wrote:

Parse the UVC 1.0 and UVC 1.1 VS_FORMAT_MPEG2TS descriptors. This a stream based format, so we generate a dummy frame descriptor with a dummy frame interval range.

Thanks for the patch, and sorry for the late reply.

No worries, just glad to have the moss knocked off the stone.

Quoted 3 lines

Don't you also need to implement support for the V4L2 MPEG CIDs ? I would expect the driver to support at least the controls used to select the MPEG format (MPEG2, TS), even if they're hardcoded to MPEG2-TS.

That would be possible, for the stream type there is your choice of MPEG2-TS so that is trivial. There are a very limited set of standardized controls that can be mapped: wKeyFrameRate, wPFrameRate, wCompQuality from the VS probe/commit (GOP size, B frames, bitrate).

Since these controls are optional in the spec, and an overly simplistic projection of the encoder's actual configuration space, device manufactures (typically) choose instead to use custom XUs that expose richer more representative ones.

Given this state of affairs, I think it would be prudent to blindly forward the data stream (Which is all, in essence, this patch enables) leaving the configuration to userspace.

Quoted 7 lines
Quoted 2 lines

I'm not suggesting we preclude adding XU -> MPEG2 CID mappings into uvcvideo later, just that as is this is a valuable step forward.

I agree with this, but I would still implement support for the V4L2_CID_MPEG_STREAM_TYPE control. MPEG applications expect it to be supported.

Ok, this is reasonable: expect another patch for the control next week.

Stephan