diff --git a/src/media/libav_utils.cpp b/src/media/libav_utils.cpp index 293ad7fe98a3a0e2f373f5173fa6bfea2320f87b..e963921f7530b445ea1097e5b51a57bb88df85bc 100644 --- a/src/media/libav_utils.cpp +++ b/src/media/libav_utils.cpp @@ -165,27 +165,6 @@ void ring_avcodec_init() std::call_once(already_called, init_once); } - -int libav_pixel_format(int fmt) -{ - switch (fmt) { - case video::VIDEO_PIXFMT_BGRA: return AV_PIX_FMT_BGRA; - case video::VIDEO_PIXFMT_RGBA: return AV_PIX_FMT_RGBA; - case video::VIDEO_PIXFMT_YUYV422: return AV_PIX_FMT_YUYV422; - case video::VIDEO_PIXFMT_YUV420P: return AV_PIX_FMT_YUV420P; - case video::VIDEO_PIXFMT_NV21: return AV_PIX_FMT_NV21; - } - return fmt; -} - -int ring_pixel_format(int fmt) -{ - switch (fmt) { - case AV_PIX_FMT_YUYV422: return video::VIDEO_PIXFMT_YUYV422; - } - return fmt; -} - void ring_url_split(const char *url, char *hostname, size_t hostname_size, int *port, char *path, size_t path_size) diff --git a/src/media/libav_utils.h b/src/media/libav_utils.h index 0cce60369244c2bf5ce1ca44c519a43dec21e2b3..d61c7b08d757ac484e14b4c62752666820294e75 100644 --- a/src/media/libav_utils.h +++ b/src/media/libav_utils.h @@ -32,9 +32,6 @@ namespace ring { namespace libav_utils { void ring_avcodec_init(); - int libav_pixel_format(int fmt); - int ring_pixel_format(int fmt); - const char *const DEFAULT_H264_PROFILE_LEVEL_ID = "profile-level-id=428029"; const char *const MAX_H264_PROFILE_LEVEL_ID = "profile-level-id=640034"; diff --git a/src/media/media_buffer.cpp b/src/media/media_buffer.cpp index 9357b823d9ba652c118b79c07dff7b775b4c00b4..160c32c13fcb777cbbe39417c831b82222a24b35 100644 --- a/src/media/media_buffer.cpp +++ b/src/media/media_buffer.cpp @@ -70,7 +70,7 @@ VideoFrame::size() const noexcept int VideoFrame::format() const noexcept { - return libav_utils::ring_pixel_format(frame_->format); + return frame_->format; } int @@ -88,7 +88,7 @@ VideoFrame::height() const noexcept void VideoFrame::setGeometry(int format, int width, int height) noexcept { - frame_->format = libav_utils::libav_pixel_format(format); + frame_->format = format; frame_->width = width; frame_->height = height; } @@ -96,14 +96,13 @@ VideoFrame::setGeometry(int format, int width, int height) noexcept void VideoFrame::reserve(int format, int width, int height) { - auto libav_format = (AVPixelFormat)libav_utils::libav_pixel_format(format); auto libav_frame = frame_.get(); if (allocated_) { // nothing to do if same properties if (width == libav_frame->width and height == libav_frame->height - and libav_format == libav_frame->format) + and format == libav_frame->format) #if USE_OLD_AVU avpicture_free((AVPicture *) libav_frame); #else @@ -167,8 +166,7 @@ VideoFrame::operator =(const VideoFrame& src) std::size_t videoFrameSize(int format, int width, int height) { - return av_image_get_buffer_size((AVPixelFormat)libav_utils::libav_pixel_format(format), - width, height, 1); + return av_image_get_buffer_size((AVPixelFormat)format, width, height, 1); } #endif // RING_VIDEO diff --git a/src/media/media_decoder.cpp b/src/media/media_decoder.cpp index bbd39a6aa4f8169ba38881e90944bbffcdda7a82..992b80051a3258c63d8fb47b0b050a9dfd448c2d 100644 --- a/src/media/media_decoder.cpp +++ b/src/media/media_decoder.cpp @@ -444,7 +444,7 @@ MediaDecoder::getTimeBase() const } int MediaDecoder::getPixelFormat() const -{ return libav_utils::ring_pixel_format(decoderCtx_->pix_fmt); } +{ return decoderCtx_->pix_fmt; } void MediaDecoder::writeToRingBuffer(const AudioFrame& decodedFrame, diff --git a/src/media/media_encoder.cpp b/src/media/media_encoder.cpp index 69155b9e6b9fd5c49880d770ac9b439392292c7b..c00f9b8c9a6b3616d85b3807074d2f98514c85bf 100644 --- a/src/media/media_encoder.cpp +++ b/src/media/media_encoder.cpp @@ -278,7 +278,7 @@ MediaEncoder::addStream(const SystemCodecInfo& systemCodecInfo, std::string para // allocate buffers for both scaled (pre-encoder) and encoded frames const int width = encoderCtx->width; const int height = encoderCtx->height; - const int format = libav_utils::ring_pixel_format((int)encoderCtx->pix_fmt); + const int format = encoderCtx->pix_fmt; scaledFrameBufferSize_ = videoFrameSize(format, width, height); if (scaledFrameBufferSize_ <= AV_INPUT_BUFFER_MIN_SIZE) throw MediaEncoderException("buffer too small"); diff --git a/src/media/video/androidvideo/video_device_impl.cpp b/src/media/video/androidvideo/video_device_impl.cpp index 2dd11762d5d1753195e54e2317b35776743834f6..3f567cbad4981b593dc6e6481a98e743983d5ab7 100644 --- a/src/media/video/androidvideo/video_device_impl.cpp +++ b/src/media/video/androidvideo/video_device_impl.cpp @@ -41,12 +41,12 @@ namespace ring { namespace video { struct android_fmt { int code; std::string name; - enum VideoPixelFormat ring_format; + int ring_format; }; static const std::array<android_fmt, 2> and_formats { - android_fmt { 17, "NV21", VIDEO_PIXFMT_NV21 }, - android_fmt { 842094169, "YUV420", VIDEO_PIXFMT_YUV420P }, + android_fmt { 17, "NV21", AV_PIX_FMT_NV21 }, + android_fmt { 842094169, "YUV420", AV_PIX_FMT_YUV420P }, }; class VideoDeviceImpl { diff --git a/src/media/video/iosvideo/video_device_impl.cpp b/src/media/video/iosvideo/video_device_impl.cpp index e52a342f9b59a6702d5d4e7ebf548c60c8522367..131df2de00784612425747ad855f71c23e61a4ce 100644 --- a/src/media/video/iosvideo/video_device_impl.cpp +++ b/src/media/video/iosvideo/video_device_impl.cpp @@ -37,9 +37,9 @@ typedef struct static const std::array<ios_fmt, 4> ios_formats { - ios_fmt { "RGBA", VIDEO_PIXFMT_RGBA }, - ios_fmt { "BGRA", VIDEO_PIXFMT_BGRA }, - ios_fmt { "YUV420P", VIDEO_PIXFMT_YUV420P } + ios_fmt { "RGBA", AV_PIX_FMT_RGBA }, + ios_fmt { "BGRA", AV_PIX_FMT_BGRA }, + ios_fmt { "YUV420P", AV_PIX_FMT_YUV420P } }; class VideoDeviceImpl diff --git a/src/media/video/sinkclient.cpp b/src/media/video/sinkclient.cpp index 809a1b96108d4d391537742fa834c98413f78a43..4f7724dbc6cbaa0cf941cb2fcf6a00511c6c22a2 100644 --- a/src/media/video/sinkclient.cpp +++ b/src/media/video/sinkclient.cpp @@ -224,7 +224,7 @@ ShmHolder::renderFrame(VideoFrame& src) noexcept { const auto width = src.width(); const auto height = src.height(); - const auto format = VIDEO_PIXFMT_BGRA; + const auto format = AV_PIX_FMT_BGRA; const auto frameSize = videoFrameSize(format, width, height); if (!resizeArea(frameSize)) { @@ -344,16 +344,16 @@ SinkClient::update(Observable<std::shared_ptr<VideoFrame>>* /*obs*/, const int width = f.width(); const int height = f.height(); #if defined(__ANDROID__) || (defined(__APPLE__) && !TARGET_OS_IPHONE) - const int format = VIDEO_PIXFMT_RGBA; + const int format = AV_PIX_FMT_RGBA; #else - const int format = VIDEO_PIXFMT_BGRA; + const int format = AV_PIX_FMT_BGRA; #endif const auto bytes = videoFrameSize(format, width, height); if (bytes > 0) { if (auto buffer_ptr = target_.pull(bytes)) { - buffer_ptr->format = libav_utils::libav_pixel_format(format); + buffer_ptr->format = format; buffer_ptr->width = width; buffer_ptr->height = height; dst.setFromMemory(buffer_ptr->ptr, format, width, height); diff --git a/src/media/video/uwpvideo/video_device_impl.cpp b/src/media/video/uwpvideo/video_device_impl.cpp index f22ac2ece7da10238f910a990c99bbf9da861743..6feaeea5a4accab51caf8d562d05ec659f0c8081 100644 --- a/src/media/video/uwpvideo/video_device_impl.cpp +++ b/src/media/video/uwpvideo/video_device_impl.cpp @@ -39,10 +39,10 @@ typedef struct // have all formats map to bgra static const std::array<uwp_fmt, 4> uwp_formats { - uwp_fmt { "MJPG", VIDEO_PIXFMT_BGRA }, - uwp_fmt { "RGB24", VIDEO_PIXFMT_BGRA }, - uwp_fmt { "NV12", VIDEO_PIXFMT_BGRA }, - uwp_fmt { "YUY2", VIDEO_PIXFMT_BGRA } + uwp_fmt { "MJPG", AV_PIX_FMT_BGRA }, + uwp_fmt { "RGB24", AV_PIX_FMT_BGRA }, + uwp_fmt { "NV12", AV_PIX_FMT_BGRA }, + uwp_fmt { "YUY2", AV_PIX_FMT_BGRA } }; class VideoDeviceImpl diff --git a/src/media/video/video_base.h b/src/media/video/video_base.h index 1f85b298e5e12c46fc576b34dce1e35167332514..5b39096c6a4509eb019f753071783087742c4294 100644 --- a/src/media/video/video_base.h +++ b/src/media/video/video_base.h @@ -36,6 +36,10 @@ #include <mutex> #include <ciso646> // fix windows compiler bug +extern "C" { +#include <libavutil/pixfmt.h> +} + struct AVPacket; struct AVDictionary; @@ -49,14 +53,6 @@ class VideoFrame; namespace ring { namespace video { -enum VideoPixelFormat { - VIDEO_PIXFMT_BGRA = -1, - VIDEO_PIXFMT_YUV420P = -2, - VIDEO_PIXFMT_YUYV422 = -3, - VIDEO_PIXFMT_RGBA = -4, - VIDEO_PIXFMT_NV21 = -5, -}; - template <typename T> class Observer; template <typename T> class Observable; diff --git a/src/media/video/video_mixer.cpp b/src/media/video/video_mixer.cpp index 4de6b176264a0c97999938b032544f43f3465653..f864d9c849f6550fe375a0331dca71e3be825f1f 100644 --- a/src/media/video/video_mixer.cpp +++ b/src/media/video/video_mixer.cpp @@ -130,7 +130,7 @@ VideoMixer::process() VideoFrame& output = getNewFrame(); try { - output.reserve(VIDEO_PIXFMT_YUYV422, width_, height_); + output.reserve(AV_PIX_FMT_YUYV422, width_, height_); } catch (const std::bad_alloc& e) { RING_ERR("VideoFrame::allocBuffer() failed"); return; @@ -231,6 +231,6 @@ VideoMixer::getHeight() const int VideoMixer::getPixelFormat() const -{ return VIDEO_PIXFMT_YUYV422; } +{ return AV_PIX_FMT_YUYV422; } }} // namespace ring::video