diff --git a/config.json b/config.json index d11c56c3..57af9cc6 100644 --- a/config.json +++ b/config.json @@ -13,7 +13,6 @@ "Bedford Hills": {"video": "rtsp://73.114.177.111/axis-media/media.amp"}, "Pocapaglia": {"video": "rtsp://176.65.94.105/axis-media/media.amp"}, - "Norwich": {"video": "rtsp://37.157.51.30/axis-media/media.amp"}, "Great Falls": {"video": "rtsp://76.75.8.116/axis-media/media.amp", "position":"47.551039,-111.539400"}, "Western Cape": {"video":"rtsp://196.21.92.82/axis-media/media.amp", "position":"-33.925840,18.423220"}, diff --git a/inc/EncodedVideoFrameBuffer.h b/inc/EncodedVideoFrameBuffer.h index 0bb020bd..b9a4c6f5 100644 --- a/inc/EncodedVideoFrameBuffer.h +++ b/inc/EncodedVideoFrameBuffer.h @@ -17,13 +17,15 @@ class EncodedVideoFrameBuffer : public webrtc::VideoFrameBuffer { public: - EncodedVideoFrameBuffer(int width, int height, const rtc::scoped_refptr &encoded_data, webrtc::VideoFrameType frameType) - : m_width(width), m_height(height), m_encoded_data(encoded_data), m_frameType(frameType) {} + EncodedVideoFrameBuffer(int width, int height, const rtc::scoped_refptr &encoded_data, webrtc::VideoFrameType frameType, const webrtc::SdpVideoFormat& format) + : m_width(width), m_height(height), m_encoded_data(encoded_data), m_frameType(frameType), m_format(format) {} virtual Type type() const { return webrtc::VideoFrameBuffer::Type::kNative; } virtual rtc::scoped_refptr ToI420() { return nullptr; } virtual int width() const { return m_width; } virtual int height() const { return m_height; } + webrtc::SdpVideoFormat getFormat() const { return m_format; } + webrtc::EncodedImage getEncodedImage(uint32_t rtptime, int ntptime ) const { webrtc::EncodedImage encoded_image; encoded_image.SetEncodedData(webrtc::EncodedImageBuffer::Create(m_encoded_data->data(), m_encoded_data->size())); @@ -38,4 +40,5 @@ class EncodedVideoFrameBuffer : public webrtc::VideoFrameBuffer const int m_height; rtc::scoped_refptr m_encoded_data; webrtc::VideoFrameType m_frameType; + webrtc::SdpVideoFormat m_format; }; diff --git a/inc/NullDecoder.h b/inc/NullDecoder.h index 4d0428e2..42c9acaa 100644 --- a/inc/NullDecoder.h +++ b/inc/NullDecoder.h @@ -37,7 +37,7 @@ class NullDecoder : public webrtc::VideoDecoder { return WEBRTC_VIDEO_CODEC_UNINITIALIZED; } rtc::scoped_refptr encodedData = input_image.GetEncodedData(); - rtc::scoped_refptr frameBuffer = rtc::make_ref_counted(m_settings.max_render_resolution().Width(), m_settings.max_render_resolution().Height(), encodedData, input_image.FrameType()); + rtc::scoped_refptr frameBuffer = rtc::make_ref_counted(m_settings.max_render_resolution().Width(), m_settings.max_render_resolution().Height(), encodedData, input_image.FrameType(), m_format); webrtc::VideoFrame frame = webrtc::VideoFrame::Builder() .set_video_frame_buffer(frameBuffer) diff --git a/inc/NullEncoder.h b/inc/NullEncoder.h index 440d6905..4b35ba49 100644 --- a/inc/NullEncoder.h +++ b/inc/NullEncoder.h @@ -39,18 +39,26 @@ class NullEncoder : public webrtc::VideoEncoder { int32_t Encode(const webrtc::VideoFrame& frame, const std::vector* frame_types) override { if (!m_encoded_image_callback) { - RTC_LOG(LS_WARNING) << "RegisterEncodeCompleteCallback() not called"; + RTC_LOG(LS_ERROR) << "RegisterEncodeCompleteCallback() not called"; return WEBRTC_VIDEO_CODEC_UNINITIALIZED; } rtc::scoped_refptr buffer = frame.video_frame_buffer(); if (buffer->type() != webrtc::VideoFrameBuffer::Type::kNative) { - RTC_LOG(LS_WARNING) << "buffer type must be kNative"; + RTC_LOG(LS_ERROR) << "buffer type must be kNative"; return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; } - // get webrtc::EncodedImage EncodedVideoFrameBuffer* encodedBuffer = (EncodedVideoFrameBuffer*)buffer.get(); + + // check format is consistent + webrtc::SdpVideoFormat format = encodedBuffer->getFormat(); + if (format.name != m_format.name) { + RTC_LOG(LS_ERROR) << "format name must be " << m_format.name << " not " << format.name; + return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; + } + + // get webrtc::EncodedImage webrtc::EncodedImage encoded_image = encodedBuffer->getEncodedImage(frame.rtp_timestamp(), frame.ntp_time_ms()); RTC_LOG(LS_VERBOSE) << "EncodedImage " << frame.id() << " " << encoded_image.FrameType() << " " << buffer->width() << "x" << buffer->height(); diff --git a/inc/V4l2Capturer.h b/inc/V4l2Capturer.h index e3e1ba46..f3bbceb5 100644 --- a/inc/V4l2Capturer.h +++ b/inc/V4l2Capturer.h @@ -28,6 +28,7 @@ class V4l2Capturer : public VideoSource size_t width = 0; size_t height = 0; size_t fps = 0; + std::string format = "H264"; if (opts.find("width") != opts.end()) { width = std::stoi(opts.at("width")); @@ -40,9 +41,13 @@ class V4l2Capturer : public VideoSource { fps = std::stoi(opts.at("fps")); } + if (opts.find("format") != opts.end()) + { + format = opts.at("format"); + } std::unique_ptr capturer(new V4l2Capturer()); - if (!capturer->Init(width, height, fps, videourl)) + if (!capturer->Init(format, width, height, fps, videourl)) { RTC_LOG(LS_WARNING) << "Failed to create V4l2Capturer(w = " << width << ", h = " << height << ", fps = " << fps @@ -62,19 +67,23 @@ class V4l2Capturer : public VideoSource private: V4l2Capturer() : m_stop(false) {} - bool Init(size_t width, + bool Init(const std::string &format, + size_t width, size_t height, size_t fps, const std::string &videourl) { + m_format = format; m_width = width; m_height = height; + std::string device = "/dev/video0"; if (videourl.find("v4l2://") == 0) { device = videourl.substr(strlen("v4l2://")); } - V4L2DeviceParameters param(device.c_str(), V4L2_PIX_FMT_H264, width, height, fps); + + V4L2DeviceParameters param(device.c_str(), V4l2Device::fourcc(format.c_str()), width, height, fps); m_capture.reset(V4l2Capture::create(param)); bool ret = false; @@ -136,7 +145,7 @@ class V4l2Capturer : public VideoSource int64_t ts = std::chrono::high_resolution_clock::now().time_since_epoch().count()/1000/1000; webrtc::VideoFrameType frameType = idr ? webrtc::VideoFrameType::kVideoFrameKey : webrtc::VideoFrameType::kVideoFrameDelta; - rtc::scoped_refptr frameBuffer = rtc::make_ref_counted(m_capture->getWidth(), m_capture->getHeight(), encodedData, frameType); + rtc::scoped_refptr frameBuffer = rtc::make_ref_counted(m_capture->getWidth(), m_capture->getHeight(), encodedData, frameType, webrtc::SdpVideoFormat(m_format)); webrtc::VideoFrame frame = webrtc::VideoFrame::Builder() .set_video_frame_buffer(frameBuffer) .set_rotation(webrtc::kVideoRotation_0) @@ -164,6 +173,7 @@ class V4l2Capturer : public VideoSource std::unique_ptr m_capture; rtc::scoped_refptr m_sps; rtc::scoped_refptr m_pps; + std::string m_format; int m_width; int m_height; };