Commit f6d001e3 authored by Adrien Béraud's avatar Adrien Béraud

video: use ffmpeg' AVPixelFormat

Change-Id: I019e66f12cf7d704f832bce457b63ca9aaefa15d
Reviewed-by: Philippe Gorley's avatarPhilippe Gorley <philippe.gorley@savoirfairelinux.com>
parent 2377472f
......@@ -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)
......
......@@ -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";
......
......@@ -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
......
......@@ -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,
......
......@@ -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");
......
......@@ -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 {
......
......@@ -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
......
......@@ -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);
......
......@@ -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
......
......@@ -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;
......
......@@ -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
Markdown is supported
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