35 #include "OMX_Video.h" 39 #include "OMX_Broadcom.h" 41 #define BROADCOM_CAMERA "OMX.broadcom.camera" 42 #define BROADCOM_ENCODER "OMX.broadcom.video_encode" 43 #define BROADCOM_NULLSINK "OMX.broadcom.null_sink" 44 #define BROADCOM_VIDEOSPLITTER "OMX.broadcom.video_splitter" 45 #define BROADCOM_IMAGEENCODER "OMX.broadcom.image_encode" 46 #define CAMERA_SHARPNESS 0 // -100->100 47 #define CAMERA_CONTRAST 0 // -100->100 48 #define CAMERA_BRIGHTNESS 50 // 0->100 49 #define CAMERA_SATURATION 0 // -100->100 50 #define CAMERA_METERING OMX_MeteringModeAverage 51 #define CAMERA_EXPOSURE OMX_ExposureControlAuto 52 #define CAMERA_EXPOSURE_COMPENSATION 0 // -10->10 53 #define CAMERA_SHUTTER_SPEED_AUTO OMX_TRUE 54 #define CAMERA_SHUTTER_SPEED 1.0/8.0 55 #define CAMERA_ISO_AUTO OMX_TRUE 56 #define CAMERA_ISO 100 // 100->800 57 #define CAMERA_WHITE_BALANCE OMX_WhiteBalControlAuto 58 #define CAMERA_FRAME_STABILIZATION OMX_FALSE 59 #define CAMERA_WHITE_BALANCE_RED_GAIN 1000 60 #define CAMERA_WHITE_BALANCE_BLUE_GAIN 1000 61 #define CAMERA_IMAGE_FILTER OMX_ImageFilterNone 62 #define CAMERA_MIRROR OMX_MirrorNone 63 #define CAMERA_ROTATION 0 64 #define CAMERA_COLOR_ENABLE OMX_FALSE 65 #define CAMERA_COLOR_U 128 66 #define CAMERA_COLOR_V 128 67 #define CAMERA_NOISE_REDUCTION OMX_TRUE 68 #define CAMERA_ROI_TOP 0 69 #define CAMERA_ROI_LEFT 0 70 #define CAMERA_ROI_WIDTH 100 71 #define CAMERA_ROI_HEIGHT 100 72 #define CAMERA_DRC OMX_DynRangeExpOff // Off/Low/Medium/High 74 #define ENCODER_QP OMX_FALSE 75 #define ENCODER_QP_I 0 76 #define ENCODER_QP_P 0 77 #define ENCODER_SEI OMX_FALSE 78 #define ENCODER_EEDE OMX_FALSE 79 #define ENCODER_EEDE_LOSS_RATE 0 80 #define ENCODER_INLINE_HEADERS OMX_TRUE 81 #define ENCODER_SPS_TIMING OMX_TRUE 87 m_cameraType(Unknown),
88 m_stillsEnabled(
true),
96 m_cameraPreviewPort(0),
98 m_videoEncoderInputPort(0),
99 m_videoEncoderOutputPort(0),
100 m_imageEncoderOutputPort(0),
101 m_splitterTunnel(&m_camera, 1, OMX_IndexParamVideoInit, &m_splitter, 0, OMX_IndexParamVideoInit),
102 m_videoTunnel(&m_splitter, 0, OMX_IndexParamVideoInit, &m_videoEncoder, 0, OMX_IndexParamVideoInit),
103 m_previewTunnel(&m_camera, 0, OMX_IndexParamVideoInit, &m_nullSink, 0, OMX_IndexParamVideoInit),
104 m_imageTunnel(&m_splitter, 1, OMX_IndexParamVideoInit, &m_imageEncoder, 0, OMX_IndexParamImageInit)
109 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"Restricting camera framerate to 30fps for full HD"));
114 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"Restricting camera framerate to 60fps for partial HD"));
119 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"Resticting camera framerate to 90fps for SD"));
146 m_cameraPreviewPort = m_camera.
GetPort(OMX_DirOutput, 0, OMX_IndexParamVideoInit);
147 m_cameraVideoPort = m_camera.
GetPort(OMX_DirOutput, 1, OMX_IndexParamVideoInit);
148 m_videoEncoderInputPort = m_videoEncoder.
GetPort(OMX_DirInput, 0, OMX_IndexParamVideoInit);
149 m_videoEncoderOutputPort = m_videoEncoder.
GetPort(OMX_DirOutput, 0, OMX_IndexParamVideoInit);
150 m_imageEncoderOutputPort = m_imageEncoder.
GetPort(OMX_DirOutput, 0, OMX_IndexParamImageInit);
152 if (!m_cameraVideoPort || !m_cameraPreviewPort || !m_videoEncoderInputPort || !m_videoEncoderOutputPort || !m_imageEncoderOutputPort)
156 if (!ConfigureCamera())
160 if (!ConfigureVideoEncoder() || !ConfigureImageEncoder())
170 m_videoEncoder.
SetState(OMX_StateIdle);
171 m_imageEncoder.
SetState(OMX_StateIdle);
183 m_camera.
EnablePort(OMX_DirOutput, 0,
true, OMX_IndexParamVideoInit);
184 m_camera.
EnablePort(OMX_DirOutput, 1,
true, OMX_IndexParamVideoInit);
185 m_splitter.
EnablePort(OMX_DirInput, 0,
true, OMX_IndexParamVideoInit);
186 m_splitter.
EnablePort(OMX_DirOutput, 0,
true, OMX_IndexParamVideoInit);
187 m_splitter.
EnablePort(OMX_DirOutput, 1,
true, OMX_IndexParamVideoInit);
188 m_videoEncoder.
EnablePort(OMX_DirInput, 0,
true, OMX_IndexParamVideoInit);
189 m_videoEncoder.
EnablePort(OMX_DirOutput, 0,
true, OMX_IndexParamVideoInit,
false);
190 m_videoEncoder.
CreateBuffers(OMX_DirOutput, 0, OMX_IndexParamVideoInit,
this);
191 m_videoEncoder.
WaitForResponse(OMX_CommandPortEnable, m_videoEncoderOutputPort, 1000);
192 m_imageEncoder.
EnablePort(OMX_DirInput, 0,
true, OMX_IndexParamImageInit);
193 m_imageEncoder.
EnablePort(OMX_DirOutput, 0,
true, OMX_IndexParamImageInit,
false);
194 m_imageEncoder.
CreateBuffers(OMX_DirOutput, 0, OMX_IndexParamImageInit,
this);
195 m_imageEncoder.
WaitForResponse(OMX_CommandPortEnable, m_imageEncoderOutputPort, 1000);
196 m_nullSink.
EnablePort(OMX_DirInput, 0,
true, OMX_IndexParamVideoInit);
200 m_camera.
SetState(OMX_StateExecuting);
201 m_splitter.
SetState(OMX_StateExecuting);
202 m_videoEncoder.
SetState(OMX_StateExecuting);
203 m_imageEncoder.
SetState(OMX_StateExecuting);
204 m_nullSink.
SetState(OMX_StateExecuting);
207 OMX_CONFIG_PORTBOOLEANTYPE capture;
209 capture.nPortIndex = m_cameraVideoPort;
210 capture.bEnabled = OMX_TRUE;
211 if (m_camera.
SetConfig(OMX_IndexConfigPortCapturing, &capture))
216 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"Pi camera setup"));
220 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"Failed to setup Pi camera"));
255 ProcessStillsBuffer(Buffer);
260 if (((OMX_INDEXTYPE)Type == OMX_IndexParamVideoInit) && m_videoEncoder.
GetAvailableBuffers(OMX_DirOutput, 0, OMX_IndexParamVideoInit) > 0)
262 ProcessVideoBuffer(Buffer);
275 if (!m_stillsEnabled)
278 OMX_BUFFERHEADERTYPE* buffer = m_imageEncoder.
GetBuffer(OMX_DirOutput, 0, 1000, OMX_IndexParamImageInit);
286 void TorcPiCamera::ProcessStillsBuffer(OMX_BUFFERHEADERTYPE *Buffer)
291 if (Buffer->nFilledLen > 0)
293 uint8_t* data = (uint8_t*)malloc(Buffer->nFilledLen);
294 memcpy(data, Buffer->pBuffer + Buffer->nOffset, Buffer->nFilledLen);
298 if (Buffer->nFlags & OMX_BUFFERFLAG_ENDOFFRAME)
305 bool TorcPiCamera::EnableVideo(
bool Video)
316 void TorcPiCamera::StartVideo(
void)
321 OMX_BUFFERHEADERTYPE* buffer = m_videoEncoder.
GetBuffer(OMX_DirOutput, 0, 1000, OMX_IndexParamVideoInit);
326 void TorcPiCamera::ProcessVideoBuffer(OMX_BUFFERHEADERTYPE *Buffer)
331 bool idr = Buffer->nFlags & OMX_BUFFERFLAG_SYNCFRAME;
332 bool complete = Buffer->nFlags & OMX_BUFFERFLAG_ENDOFFRAME;
333 bool sps = Buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG;
335 if (!sps && complete)
351 memcpy(
m_bufferedPacket->data + offset, reinterpret_cast<uint8_t*>(Buffer->pBuffer) + Buffer->nOffset, Buffer->nFilledLen);
359 packet = av_packet_alloc();
360 av_init_packet(packet);
361 packet->size = Buffer->nFilledLen;
362 packet->data =
reinterpret_cast<uint8_t*
>(Buffer->pBuffer) + Buffer->nOffset;
368 packet->duration = 1;
369 packet->flags |= idr ? AV_PKT_FLAG_KEY : 0;
377 QByteArray config = QByteArray::fromRawData((
char*)packet->data, packet->size);
400 packet->data =
nullptr;
401 av_packet_free(&packet);
409 uint8_t* data = (uint8_t*)av_malloc(Buffer->nFilledLen);
413 memcpy(
m_bufferedPacket->data, reinterpret_cast<uint8_t*>(Buffer->pBuffer) + Buffer->nOffset, Buffer->nFilledLen);
425 m_stillsEnabled =
false;
426 m_videoEnabled =
false;
432 while (m_imageEncoder.
GetInUseBuffers(OMX_DirOutput, 0, OMX_IndexParamImageInit) &&
433 m_videoEncoder.
GetInUseBuffers(OMX_DirOutput, 0, OMX_IndexParamVideoInit) &&
442 OMX_CONFIG_PORTBOOLEANTYPE capture;
444 capture.nPortIndex = m_cameraVideoPort;
445 capture.bEnabled = OMX_FALSE;
446 m_camera.
SetConfig(OMX_IndexConfigPortCapturing, &capture);
451 m_videoEncoder.
SetState(OMX_StateIdle);
452 m_imageEncoder.
SetState(OMX_StateIdle);
456 m_videoEncoder.
EnablePort(OMX_DirOutput, 0,
false, OMX_IndexParamVideoInit,
false);
457 m_videoEncoder.
DestroyBuffers(OMX_DirOutput, 0, OMX_IndexParamVideoInit);
458 m_videoEncoder.
WaitForResponse(OMX_CommandPortDisable, m_videoEncoderOutputPort, 1000);
461 m_imageEncoder.
EnablePort(OMX_DirOutput, 0,
false, OMX_IndexParamImageInit,
false);
462 m_imageEncoder.
DestroyBuffers(OMX_DirOutput, 0, OMX_IndexParamImageInit);
463 m_imageEncoder.
WaitForResponse(OMX_CommandPortDisable, m_imageEncoderOutputPort, 1000);
481 m_splitter.
SetState(OMX_StateLoaded);
482 m_videoEncoder.
SetState(OMX_StateLoaded);
483 m_imageEncoder.
SetState(OMX_StateLoaded);
484 m_nullSink.
SetState(OMX_StateLoaded);
489 bool TorcPiCamera::LoadDrivers(
void)
491 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"Trying to load Broadcom drivers"));
494 OMX_CONFIG_REQUESTCALLBACKTYPE callback;
496 callback.nPortIndex = OMX_ALL;
497 callback.nIndex = OMX_IndexParamCameraDeviceNumber;
498 callback.bEnable = OMX_TRUE;
499 if (m_camera.
SetConfig(OMX_IndexConfigRequestCallback, &callback))
504 OMX_PARAM_U32TYPE device;
506 device.nPortIndex = OMX_ALL;
508 if (m_camera.
SetConfig(OMX_IndexParamCameraDeviceNumber, &device))
513 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"Broadcom drivers loaded"));
515 OMX_CONFIG_CAMERAINFOTYPE info;
517 if (!m_camera.
GetConfig(OMX_IndexConfigCameraInfo, &info))
519 if (qstrcmp((
const char*)info.cameraname,
"imx219") == 0)
521 else if (qstrcmp((
const char*)info.cameraname,
"ov5647") == 0)
523 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"Camera: name '%1' (Version %2)")
524 .arg((
const char*)info.cameraname)
525 .arg(m_cameraType ==
V2 ?
"2" : m_cameraType ==
V1 ? QStringLiteral(
"1") : QStringLiteral(
"Unknown")));
531 bool TorcPiCamera::LoadCameraSettings(
void)
533 if (!m_cameraVideoPort)
537 OMX_CONFIG_SHARPNESSTYPE sharpness;
539 sharpness.nPortIndex = OMX_ALL;
541 if (m_camera.
SetConfig(OMX_IndexConfigCommonSharpness, &sharpness))
545 OMX_CONFIG_CONTRASTTYPE contrast;
547 contrast.nPortIndex = OMX_ALL;
549 if (m_camera.
SetConfig(OMX_IndexConfigCommonContrast, &contrast))
553 OMX_CONFIG_SATURATIONTYPE saturation;
555 saturation.nPortIndex = OMX_ALL;
557 if (m_camera.
SetConfig(OMX_IndexConfigCommonSaturation, &saturation))
561 OMX_CONFIG_BRIGHTNESSTYPE brightness;
563 brightness.nPortIndex = OMX_ALL;
565 if (m_camera.
SetConfig(OMX_IndexConfigCommonBrightness, &brightness))
569 OMX_CONFIG_EXPOSUREVALUETYPE exposure;
571 exposure.nPortIndex = OMX_ALL;
578 if (m_camera.
SetConfig(OMX_IndexConfigCommonExposureValue, &exposure))
582 OMX_CONFIG_EXPOSURECONTROLTYPE commonexposure;
584 commonexposure.nPortIndex = OMX_ALL;
586 if (m_camera.
SetConfig(OMX_IndexConfigCommonExposure, &commonexposure))
590 OMX_CONFIG_FRAMESTABTYPE framestabilisation;
592 framestabilisation.nPortIndex = OMX_ALL;
594 if (m_camera.
SetConfig(OMX_IndexConfigCommonFrameStabilisation, &framestabilisation))
598 OMX_CONFIG_WHITEBALCONTROLTYPE whitebalance;
600 whitebalance.nPortIndex = OMX_ALL;
602 if (m_camera.
SetConfig(OMX_IndexConfigCommonWhiteBalance, &whitebalance))
608 OMX_CONFIG_CUSTOMAWBGAINSTYPE whitebalancegain;
612 if (m_camera.
SetConfig(OMX_IndexConfigCustomAwbGains, &whitebalancegain))
617 OMX_CONFIG_IMAGEFILTERTYPE imagefilter;
619 imagefilter.nPortIndex = OMX_ALL;
621 if (m_camera.
SetConfig(OMX_IndexConfigCommonImageFilter, &imagefilter))
625 OMX_CONFIG_MIRRORTYPE mirror;
627 mirror.nPortIndex = m_cameraVideoPort;
629 if (m_camera.
SetConfig(OMX_IndexConfigCommonMirror, &mirror))
633 OMX_CONFIG_ROTATIONTYPE rotation;
635 rotation.nPortIndex = m_cameraVideoPort;
637 if (m_camera.
SetConfig(OMX_IndexConfigCommonRotate, &rotation))
641 OMX_CONFIG_COLORENHANCEMENTTYPE color_enhancement;
643 color_enhancement.nPortIndex = OMX_ALL;
647 if (m_camera.
SetConfig(OMX_IndexConfigCommonColorEnhancement, &color_enhancement))
651 OMX_CONFIG_BOOLEANTYPE denoise;
654 if (m_camera.
SetConfig(OMX_IndexConfigStillColourDenoiseEnable, &denoise))
658 OMX_CONFIG_INPUTCROPTYPE roi;
660 roi.nPortIndex = OMX_ALL;
665 if (m_camera.
SetConfig(OMX_IndexConfigInputCropPercentages, &roi))
669 OMX_CONFIG_DYNAMICRANGEEXPANSIONTYPE drc;
672 if (m_camera.
SetConfig(OMX_IndexConfigDynamicRangeExpansion, &drc))
678 bool TorcPiCamera::ConfigureCamera(
void)
680 if (!m_cameraPreviewPort || !m_cameraVideoPort)
684 OMX_PARAM_PORTDEFINITIONTYPE videoport;
686 videoport.nPortIndex = m_cameraVideoPort;
687 if (m_camera.
GetParameter(OMX_IndexParamPortDefinition, &videoport))
695 videoport.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused;
696 videoport.format.video.eColorFormat = OMX_COLOR_FormatYUV420PackedPlanar;
697 if (m_camera.
SetParameter(OMX_IndexParamPortDefinition, &videoport))
701 videoport.nPortIndex = m_cameraPreviewPort;
702 if (m_camera.
SetParameter(OMX_IndexParamPortDefinition, &videoport))
706 OMX_CONFIG_FRAMERATETYPE framerate;
708 framerate.nPortIndex = m_cameraVideoPort;
709 framerate.xEncodeFramerate = videoport.format.video.xFramerate;
710 if (m_camera.
SetConfig(OMX_IndexConfigVideoFramerate, &framerate))
714 framerate.nPortIndex = m_cameraPreviewPort;
715 if (m_camera.
SetConfig(OMX_IndexConfigVideoFramerate, &framerate))
719 if (!LoadCameraSettings())
725 bool TorcPiCamera::ConfigureImageEncoder(
void)
727 if (!m_imageEncoderOutputPort)
730 OMX_PARAM_PORTDEFINITIONTYPE encoderport;
732 encoderport.nPortIndex = m_imageEncoderOutputPort;
733 if (m_imageEncoder.
GetParameter(OMX_IndexParamPortDefinition, &encoderport))
740 encoderport.format.image.eCompressionFormat = OMX_IMAGE_CodingJPEG;
741 encoderport.format.image.eColorFormat = OMX_COLOR_FormatUnused;
743 if (m_imageEncoder.
SetParameter(OMX_IndexParamPortDefinition, &encoderport))
746 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"Set image encoder output parameters"));
749 encoderport.nPortIndex = m_imageEncoder.
GetPort(OMX_DirInput, 0, OMX_IndexParamImageInit);
750 if (m_imageEncoder.
GetParameter(OMX_IndexParamPortDefinition, &encoderport))
757 encoderport.format.image.eCompressionFormat = OMX_IMAGE_CodingUnused;
758 encoderport.format.image.eColorFormat = OMX_COLOR_FormatYUV420PackedPlanar;
760 if (m_imageEncoder.
SetParameter(OMX_IndexParamPortDefinition, &encoderport))
763 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"Set image encoder input parameters"));
767 bool TorcPiCamera::ConfigureVideoEncoder(
void)
769 if (!m_videoEncoderOutputPort)
773 OMX_PARAM_PORTDEFINITIONTYPE encoderport;
775 encoderport.nPortIndex = m_videoEncoderOutputPort;
776 if (m_videoEncoder.
GetParameter(OMX_IndexParamPortDefinition, &encoderport))
785 encoderport.format.video.eCompressionFormat = OMX_VIDEO_CodingAVC;
786 if (m_videoEncoder.
SetParameter(OMX_IndexParamPortDefinition, &encoderport))
789 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"Set video encoder output parameters"));
793 OMX_VIDEO_PARAM_BITRATETYPE bitrate;
795 bitrate.eControlRate = OMX_Video_ControlRateVariable;
797 bitrate.nPortIndex = m_videoEncoderOutputPort;
798 if (m_videoEncoder.
SetParameter(OMX_IndexParamVideoBitrate, &bitrate))
801 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"Set video encoder output bitrate"));
806 OMX_VIDEO_PARAM_QUANTIZATIONTYPE quantization;
808 quantization.nPortIndex = m_videoEncoderOutputPort;
811 if (m_videoEncoder.
SetParameter(OMX_IndexParamVideoQuantization, &quantization))
814 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"Set video encoder output quantization"));
818 OMX_VIDEO_PARAM_PORTFORMATTYPE format;
820 format.nPortIndex = m_videoEncoderOutputPort;
821 format.eCompressionFormat = OMX_VIDEO_CodingAVC;
822 if (m_videoEncoder.
SetParameter(OMX_IndexParamVideoPortFormat, &format))
825 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"Set video encoder output format"));
828 OMX_VIDEO_CONFIG_AVCINTRAPERIOD idr;
830 idr.nPortIndex = m_videoEncoderOutputPort;
831 if (m_videoEncoder.
GetConfig(OMX_IndexConfigVideoAVCIntraPeriod, &idr))
834 if (m_videoEncoder.
SetConfig(OMX_IndexConfigVideoAVCIntraPeriod, &idr))
840 OMX_PARAM_BRCMVIDEOAVCSEIENABLETYPE sei;
842 sei.nPortIndex = m_videoEncoderOutputPort;
844 if (m_videoEncoder.
SetParameter(OMX_IndexParamBrcmVideoAVCSEIEnable, &sei))
847 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"Set video encoder output SEI"));
850 OMX_VIDEO_EEDE_ENABLE eede;
852 eede.nPortIndex = m_videoEncoderOutputPort;
854 if (m_videoEncoder.
SetParameter(OMX_IndexParamBrcmEEDEEnable, &eede))
857 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"Set video endcoder output EEDE"));
859 OMX_VIDEO_EEDE_LOSSRATE eede_loss_rate;
861 eede_loss_rate.nPortIndex = m_videoEncoderOutputPort;
863 if (m_videoEncoder.
SetParameter(OMX_IndexParamBrcmEEDELossRate, &eede_loss_rate))
866 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"Set video encoder output EEDE loss rate"));
869 OMX_VIDEO_AVCPROFILETYPE profile = OMX_VIDEO_AVCProfileMain;
872 case FF_PROFILE_H264_BASELINE: profile = OMX_VIDEO_AVCProfileBaseline;
break;
873 case FF_PROFILE_H264_MAIN: profile = OMX_VIDEO_AVCProfileMain;
break;
874 case FF_PROFILE_H264_EXTENDED: profile = OMX_VIDEO_AVCProfileExtended;
break;
875 case FF_PROFILE_H264_HIGH: profile = OMX_VIDEO_AVCProfileHigh;
break;
876 case FF_PROFILE_H264_HIGH_10: profile = OMX_VIDEO_AVCProfileHigh10;
break;
877 case FF_PROFILE_H264_HIGH_422: profile = OMX_VIDEO_AVCProfileHigh422;
break;
878 case FF_PROFILE_H264_HIGH_444: profile = OMX_VIDEO_AVCProfileHigh444;
break;
880 LOG(VB_GENERAL, LOG_WARNING, QStringLiteral(
"Unknown H264 profile. Defaulting to main"));
883 OMX_VIDEO_PARAM_AVCTYPE avc;
885 avc.nPortIndex = m_videoEncoderOutputPort;
886 if (m_videoEncoder.
GetParameter(OMX_IndexParamVideoAvc, &avc))
888 avc.eProfile = profile;
889 if (m_videoEncoder.
SetParameter(OMX_IndexParamVideoAvc, &avc))
892 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"Set video encoder output profile"));
895 OMX_CONFIG_PORTBOOLEANTYPE headers;
897 headers.nPortIndex = m_videoEncoderOutputPort;
899 if (m_videoEncoder.
SetParameter(OMX_IndexParamBrcmVideoAVCInlineHeaderEnable, &headers))
902 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"Set video encoder output SPS/PPS"));
905 OMX_CONFIG_PORTBOOLEANTYPE timing;
907 timing.nPortIndex = m_videoEncoderOutputPort;
909 if (m_videoEncoder.
SetParameter(OMX_IndexParamBrcmVideoAVCSPSTimingEnable, &timing))
912 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"Set video encoder SPS timings"));
918 OMX_PARAM_U32TYPE single;
920 single.nPortIndex = m_splitter.
GetPort(OMX_DirOutput, 1, OMX_IndexParamVideoInit);
922 if (m_splitter.
SetParameter(OMX_IndexConfigSingleStep, &single))
929 " <xs:element name=\"pi\" type=\"cameraType\"/>\r\n");
954 static bool checked =
false;
962 if (!vc_gencmd(command,
sizeof(command),
"get_mem gpu"))
963 vc_gencmd_number_property(command,
"gpu", &gpumem);
967 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"Insufficent GPU memory for Pi camera - need 128Mb - have %1Mb").arg(gpumem));
971 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"%1Mb GPU memory").arg(gpumem));
976 if (!vc_gencmd(command,
sizeof(command),
"get_camera"))
978 vc_gencmd_number_property(command,
"supported", &supported);
979 vc_gencmd_number_property(command,
"detected", &detected);
984 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"Firmware reports that Pi camera is NOT supported"));
988 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"Firmware reports that Pi camera NOT detected"));
992 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"Pi camera supported and detected"));
1010 return QObject::tr(
"Pi Camera");
OMX_U32 GetInUseBuffers(OMX_DIRTYPE Direction, OMX_U32 Index, OMX_INDEXTYPE Domain)
OMX_ERRORTYPE SetState(OMX_STATETYPE State, bool Wait=true)
OMX_U32 GetPort(OMX_DIRTYPE Direction, OMX_U32 Index, OMX_INDEXTYPE Domain)
#define CAMERA_SHUTTER_SPEED
#define VIDEO_H264_PROFILE
OMX_ERRORTYPE Create(void)
OMX_BUFFERHEADERTYPE * GetBuffer(OMX_DIRTYPE Direction, OMX_U32 Index, OMX_U32 Timeout, OMX_INDEXTYPE Domain)
#define CAMERA_COLOR_ENABLE
TorcCameraParams m_params
#define CAMERA_WHITE_BALANCE_RED_GAIN
TorcPiCamera(const TorcCameraParams &Params)
static QString GetAVCCodec(const QByteArray &Packet)
Determine the 3 byte H.264 codec descriptor string.
OMX_ERRORTYPE SetConfig(OMX_INDEXTYPE Index, OMX_PTR Structure)
OMX_ERRORTYPE DestroyBuffers(OMX_DIRTYPE Direction, OMX_U32 Index, OMX_INDEXTYPE Domain)
QReadWriteLock m_ringBufferLock
void WritingStarted(void)
bool AddPacket(AVPacket *Packet, bool CodecConfig)
#define CAMERA_WHITE_BALANCE
#define CAMERA_FRAME_STABILIZATION
#define BROADCOM_VIDEOSPLITTER
AVPacket * m_bufferedPacket
TorcPiCameraXSDFactory TorcPiCameraXSDFactory
OMX_ERRORTYPE EnablePort(OMX_DIRTYPE Direction, OMX_U32 Index, bool Enable, OMX_INDEXTYPE Domain, bool Wait=true)
void FinishSegment(bool Init)
virtual bool EnableStills(uint Count)
#define VIDEO_SEGMENT_TARGET
bool EnableStills(uint Count) override
void BufferReady(OMX_BUFFERHEADERTYPE *Buffer, quint64 Type)
An OpenMax buffer is ready (full)
bool Start(void) override
Start the camera.
#define CAMERA_ROI_HEIGHT
OMX_ERRORTYPE CreateBuffers(OMX_DIRTYPE Direction, OMX_U32 Index, OMX_INDEXTYPE Domain, QObject *Owner=nullptr)
#define CAMERA_BRIGHTNESS
#define ENCODER_SPS_TIMING
bool CanHandle(const QString &Type, const TorcCameraParams &Params) override
#define BROADCOM_NULLSINK
void ParametersChanged(TorcCameraParams &Params)
#define ENCODER_EEDE_LOSS_RATE
static const QString piCameraType
#define LOG(_MASK_, _LEVEL_, _STRING_)
OMX_U32 GetAvailableBuffers(OMX_DIRTYPE Direction, OMX_U32 Index, OMX_INDEXTYPE Domain)
void GetXSD(QMultiMap< QString, QString > &XSD)
#define CAMERA_IMAGE_FILTER
bool Setup(void) override
OMX_ERRORTYPE GetParameter(OMX_INDEXTYPE Index, OMX_PTR Structure)
#define ENCODER_INLINE_HEADERS
OMX_ERRORTYPE GetConfig(OMX_INDEXTYPE Index, OMX_PTR Structure)
TorcPiCameraFactory TorcPiCameraFactory
OMX_ERRORTYPE Destroy(void)
void StartStill(void) override
Start capturing a still image buffer.
#define BROADCOM_IMAGEENCODER
void WritingStopped(void)
#define CAMERA_NOISE_REDUCTION
OMX_ERRORTYPE SetParameter(OMX_INDEXTYPE Index, OMX_PTR Structure)
#define CAMERA_SATURATION
OMX_ERRORTYPE WaitForResponse(OMX_U32 Command, OMX_U32 Data2, OMX_S32 Timeout)
#define VIDEO_GOPDURA_TARGET
static bool gPiCameraDetected
void SaveStillBuffer(quint32 Length, uint8_t *Data)
#define CAMERA_SHUTTER_SPEED_AUTO
#define CAMERA_EXPOSURE_COMPENSATION
virtual ~TorcPiCameraFactory()
#define CAMERA_WHITE_BALANCE_BLUE_GAIN
void StreamVideo(bool Video) override
OMX_ERRORTYPE FillThisBuffer(OMX_BUFFERHEADERTYPE *Buffer)
TorcCameraDevice * Create(const QString &Type, const TorcCameraParams &Params) override
OMX_ERRORTYPE DisablePorts(OMX_INDEXTYPE Domain)
#define OMX_INITSTRUCTURE(Struct)