Verified Commit 40b63c96 authored by Bartosz Błaszków's avatar Bartosz Błaszków
Browse files

Add support for bitrate control

parent 5a85b6f6
......@@ -67,6 +67,10 @@ static const int desired_video_buffers = 256;
*/
#define V4L_TS_CONVERT_READY V4L_TS_DEFAULT
#define UVC_IFPERIOD_DEFAULT 10000
#define UVC_BITRATE_DEFAULT 3000000
struct video_data {
AVClass *class;
int fd;
......@@ -109,37 +113,6 @@ struct buff_data {
int index;
};
void print_probe_commit(uvcx_video_config_probe_commit_t * probe);
void print_probe_commit(uvcx_video_config_probe_commit_t * probe) {
printf("Frame interval: %d", probe->dwFrameInterval);
printf("\nBit rate : %d", probe->dwBitRate);
printf("\nHints : %X", probe->bmHints);
printf("\nConfiguration index : %d", probe->wConfigurationIndex);
printf("\nWidth : %d", probe->wWidth);
printf("\nHeight : %d", probe->wHeight);
printf("\nSlice units : %d", probe->wSliceUnits);
printf("\nSlice mode : %X", probe->wSliceMode);
printf("\nProfile : %X", probe->wProfile);
printf("\nIFrame Period : %d ms", probe->wIFramePeriod);
printf("\nEstimated video delay : %d ms", probe->wEstimatedVideoDelay);
printf("\nEstimated max config delay : %d ms", probe->wEstimatedMaxConfigDelay);
printf("\nUsage type : %X", probe->bUsageType);
printf("\nRate control mode : %X", probe->bRateControlMode);
printf("\nTemporal scale mode : %X", probe->bTemporalScaleMode);
printf("\nSpatial scale mode : %X", probe->bSpatialScaleMode);
printf("\nSNR scale mode : %X", probe->bSNRScaleMode);
printf("\nStream mux option : %X", probe->bStreamMuxOption);
printf("\nStream Format : %X", probe->bStreamFormat);
printf("\nEntropy CABAC : %X", probe->bEntropyCABAC);
printf("\nTimestamp : %X", probe->bTimestamp);
printf("\nNum of reorder frames : %d", probe->bNumOfReorderFrames);
printf("\nPreview flipped : %X", probe->bPreviewFlipped);
printf("\nView : %d", probe->bView);
printf("\nStream ID : %X", probe->bStreamID);
printf("\nSpatial layer ratio : %f", ((probe->bSpatialLayerRatio & 0xF0) >> 4) + ((float) (probe->bSpatialLayerRatio & 0x0F)) / 16);
printf("\nLeaky bucket size : %d ms\n", probe->wLeakyBucketSize);
}
static int device_open(AVFormatContext *ctx, const char* device_path)
{
struct video_data *s = ctx->priv_data;
......@@ -792,13 +765,21 @@ static int v4l2_set_parameters(AVFormatContext *ctx)
av_log(ctx, AV_LOG_WARNING, "Time per frame unknown\n");
/** try using uvcvideo params **/
if (ctx->video_codec_id == AV_CODEC_ID_H264) {
if (ctx->video_codec_id == AV_CODEC_ID_H264 &&
(s->initial_bitrate != UVC_BITRATE_DEFAULT || s->iframe_interval != UVC_IFPERIOD_DEFAULT)) {
uvcx_video_config_probe_commit_t probe;
// Fill the probe. 0 means parameter is not negotiated.
memset(&probe, 0, sizeof(probe));
make_uvc_xu_query(s->fd, UVCX_VIDEO_CONFIG_PROBE, UVC_GET_DEF, (uint8_t *) &probe);
probe.wIFramePeriod = s->iframe_interval / 2;
if (s->iframe_interval != UVC_IFPERIOD_DEFAULT) {
probe.wIFramePeriod = s->iframe_interval / 2;
}
if (s->initial_bitrate != UVC_BITRATE_DEFAULT) {
probe.dwBitRate = s->initial_bitrate;
}
// Hints describe which parameters should remain unchanged
probe.bmHints = UVC_H264_BMHINTS_RESOLUTION | UVC_H264_BMHINTS_PROFILE |
UVC_H264_BMHINTS_FRAME_INTERVAL;
......@@ -808,7 +789,6 @@ static int v4l2_set_parameters(AVFormatContext *ctx)
// Get an offer from device
make_uvc_xu_query(s->fd, UVCX_VIDEO_CONFIG_PROBE, UVC_GET_CUR, (uint8_t *) &probe);
print_probe_commit(&probe);
// Finish negotiation
make_uvc_xu_query(s->fd, UVCX_VIDEO_CONFIG_COMMIT, UVC_SET_CUR, (uint8_t *) &probe);
......@@ -1173,7 +1153,8 @@ static const AVOption options[] = {
{ "abs", "use absolute timestamps (wall clock)", OFFSET(ts_mode), AV_OPT_TYPE_CONST, {.i64 = V4L_TS_ABS }, 0, 2, DEC, "timestamps" },
{ "mono2abs", "force conversion from monotonic to absolute timestamps", OFFSET(ts_mode), AV_OPT_TYPE_CONST, {.i64 = V4L_TS_MONO2ABS }, 0, 2, DEC, "timestamps" },
{ "use_libv4l2", "use libv4l2 (v4l-utils) conversion functions", OFFSET(use_libv4l2), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC },
{ "iframe_interval", "(Logitech C920) set interval between I-frames for H264 encoding", OFFSET(iframe_interval), AV_OPT_TYPE_INT, {.i64 = 10000}, 0, INT_MAX, DEC },
{ "iframe_interval", "(Logitech C920) set interval (in ms) between I-frames", OFFSET(iframe_interval), AV_OPT_TYPE_INT, {.i64 = UVC_IFPERIOD_DEFAULT}, 0, INT_MAX, DEC },
{ "bitrate", "(Logitech C920) set bitrate for H264 encoding", OFFSET(initial_bitrate), AV_OPT_TYPE_INT, {.i64 = UVC_BITRATE_DEFAULT}, 0, INT_MAX, DEC },
{ NULL },
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment