summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ffmpeg_compatibility.cc119
-rw-r--r--src/lib/ffmpeg_compatibility.h31
-rw-r--r--src/lib/ffmpeg_decoder.cc39
-rw-r--r--src/lib/filter_graph.cc118
-rw-r--r--src/lib/filter_graph.h30
-rw-r--r--src/lib/image.cc204
-rw-r--r--src/lib/image.h29
-rw-r--r--src/lib/matcher.h1
-rw-r--r--src/lib/wscript1
9 files changed, 162 insertions, 410 deletions
diff --git a/src/lib/ffmpeg_compatibility.cc b/src/lib/ffmpeg_compatibility.cc
deleted file mode 100644
index 361fa7423..000000000
--- a/src/lib/ffmpeg_compatibility.cc
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
-
-extern "C" {
-#include <libavfilter/avfiltergraph.h>
-}
-#include "exceptions.h"
-
-#include "i18n.h"
-
-#if LIBAVFILTER_VERSION_MAJOR == 2 && LIBAVFILTER_VERSION_MINOR == 15
-
-typedef struct {
- enum PixelFormat pix_fmt;
-} AVSinkContext;
-
-static int
-avsink_init (AVFilterContext* ctx, const char* args, void* opaque)
-{
- AVSinkContext* priv = (AVSinkContext *) ctx->priv;
- if (!opaque) {
- return AVERROR (EINVAL);
- }
-
- *priv = *(AVSinkContext *) opaque;
- return 0;
-}
-
-static void
-null_end_frame (AVFilterLink *)
-{
-
-}
-
-static int
-avsink_query_formats (AVFilterContext* ctx)
-{
- AVSinkContext* priv = (AVSinkContext *) ctx->priv;
- enum PixelFormat pix_fmts[] = {
- priv->pix_fmt,
- PIX_FMT_NONE
- };
-
- avfilter_set_common_formats (ctx, avfilter_make_format_list ((int *) pix_fmts));
- return 0;
-}
-
-#endif
-
-AVFilter*
-get_sink ()
-{
-#if LIBAVFILTER_VERSION_MAJOR == 2 && LIBAVFILTER_VERSION_MINOR == 15
- /* XXX does this leak stuff? */
- AVFilter* buffer_sink = new AVFilter;
- buffer_sink->name = av_strdup (N_("avsink"));
- buffer_sink->priv_size = sizeof (AVSinkContext);
- buffer_sink->init = avsink_init;
- buffer_sink->query_formats = avsink_query_formats;
- buffer_sink->inputs = new AVFilterPad[2];
- AVFilterPad* i0 = const_cast<AVFilterPad*> (&buffer_sink->inputs[0]);
- i0->name = N_("default");
- i0->type = AVMEDIA_TYPE_VIDEO;
- i0->min_perms = AV_PERM_READ;
- i0->rej_perms = 0;
- i0->start_frame = 0;
- i0->get_video_buffer = 0;
- i0->get_audio_buffer = 0;
- i0->end_frame = null_end_frame;
- i0->draw_slice = 0;
- i0->filter_samples = 0;
- i0->poll_frame = 0;
- i0->request_frame = 0;
- i0->config_props = 0;
- const_cast<AVFilterPad*> (&buffer_sink->inputs[1])->name = 0;
- buffer_sink->outputs = new AVFilterPad[1];
- const_cast<AVFilterPad*> (&buffer_sink->outputs[0])->name = 0;
- return buffer_sink;
-#else
- AVFilter* buffer_sink = avfilter_get_by_name(N_("buffersink"));
- if (buffer_sink == 0) {
- throw DecodeError (N_("Could not create buffer sink filter"));
- }
-
- return buffer_sink;
-#endif
-}
-
-#if LIBAVFILTER_VERSION_MAJOR == 2 && LIBAVFILTER_VERSION_MINOR == 15
-AVFilterInOut *
-avfilter_inout_alloc ()
-{
- return (AVFilterInOut *) av_malloc (sizeof (AVFilterInOut));
-}
-#endif
-
-#ifndef HAVE_AV_FRAME_GET_BEST_EFFORT_TIMESTAMP
-int64_t av_frame_get_best_effort_timestamp (AVFrame const * f)
-{
- return f->best_effort_timestamp;
-}
-
-#endif
diff --git a/src/lib/ffmpeg_compatibility.h b/src/lib/ffmpeg_compatibility.h
deleted file mode 100644
index 772d22c33..000000000
--- a/src/lib/ffmpeg_compatibility.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
-
-struct AVFilterInOut;
-
-extern AVFilter* get_sink ();
-extern AVFilterInOut* avfilter_inout_alloc ();
-
-#ifndef HAVE_AV_PIXEL_FORMAT
-#define AVPixelFormat PixelFormat
-#endif
-
-#ifndef HAVE_AV_FRAME_GET_BEST_EFFORT_TIMESTAMP
-extern int64_t av_frame_get_best_effort_timestamp (AVFrame const *);
-#endif
diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc
index 8e09810cb..982139515 100644
--- a/src/lib/ffmpeg_decoder.cc
+++ b/src/lib/ffmpeg_decoder.cc
@@ -500,32 +500,35 @@ FFmpegDecoder::set_subtitle_stream (shared_ptr<SubtitleStream> s)
void
FFmpegDecoder::filter_and_emit_video ()
{
- boost::mutex::scoped_lock lm (_filter_graphs_mutex);
+ int64_t const bet = av_frame_get_best_effort_timestamp (_frame);
+ if (bet == AV_NOPTS_VALUE) {
+ _film->log()->log ("Dropping frame without PTS");
+ return;
+ }
shared_ptr<FilterGraph> graph;
- list<shared_ptr<FilterGraph> >::iterator i = _filter_graphs.begin();
- while (i != _filter_graphs.end() && !(*i)->can_process (libdcp::Size (_frame->width, _frame->height), (AVPixelFormat) _frame->format)) {
- ++i;
- }
-
- if (i == _filter_graphs.end ()) {
- graph.reset (new FilterGraph (_film, this, libdcp::Size (_frame->width, _frame->height), (AVPixelFormat) _frame->format));
- _filter_graphs.push_back (graph);
- _film->log()->log (String::compose (N_("New graph for %1x%2, pixel format %3"), _frame->width, _frame->height, _frame->format));
- } else {
- graph = *i;
+ {
+ boost::mutex::scoped_lock lm (_filter_graphs_mutex);
+
+ list<shared_ptr<FilterGraph> >::iterator i = _filter_graphs.begin();
+ while (i != _filter_graphs.end() && !(*i)->can_process (libdcp::Size (_frame->width, _frame->height), (AVPixelFormat) _frame->format)) {
+ ++i;
+ }
+
+ if (i == _filter_graphs.end ()) {
+ graph = filter_graph_factory (_film, this, libdcp::Size (_frame->width, _frame->height), (AVPixelFormat) _frame->format);
+ _filter_graphs.push_back (graph);
+ _film->log()->log (String::compose (N_("New graph for %1x%2, pixel format %3"), _frame->width, _frame->height, _frame->format));
+ } else {
+ graph = *i;
+ }
}
list<shared_ptr<Image> > images = graph->process (_frame);
for (list<shared_ptr<Image> >::iterator i = images.begin(); i != images.end(); ++i) {
- int64_t const bet = av_frame_get_best_effort_timestamp (_frame);
- if (bet != AV_NOPTS_VALUE) {
- emit_video (*i, false, bet * av_q2d (_format_context->streams[_video_stream]->time_base));
- } else {
- _film->log()->log ("Dropping frame without PTS");
- }
+ emit_video (*i, false, bet * av_q2d (_format_context->streams[_video_stream]->time_base));
}
}
diff --git a/src/lib/filter_graph.cc b/src/lib/filter_graph.cc
index 045cbaa6a..b0427a23d 100644
--- a/src/lib/filter_graph.cc
+++ b/src/lib/filter_graph.cc
@@ -23,20 +23,13 @@
extern "C" {
#include <libavfilter/avfiltergraph.h>
-#ifdef HAVE_BUFFERSRC_H
#include <libavfilter/buffersrc.h>
-#endif
-#if (LIBAVFILTER_VERSION_MAJOR == 2 && LIBAVFILTER_VERSION_MINOR >= 53 && LIBAVFILTER_VERSION_MINOR <= 77) || LIBAVFILTER_VERSION_MAJOR == 3
#include <libavfilter/avcodec.h>
#include <libavfilter/buffersink.h>
-#elif LIBAVFILTER_VERSION_MAJOR == 2 && LIBAVFILTER_VERSION_MINOR == 15
-#include <libavfilter/vsrc_buffer.h>
-#endif
#include <libavformat/avio.h>
}
#include "decoder.h"
#include "filter_graph.h"
-#include "ffmpeg_compatibility.h"
#include "filter.h"
#include "exceptions.h"
#include "image.h"
@@ -51,18 +44,20 @@ using std::list;
using boost::shared_ptr;
using libdcp::Size;
-/** Construct a FilterGraph for the settings in a film.
+/** Construct a FFmpegFilterGraph for the settings in a film.
* @param film Film.
* @param decoder Decoder that we are using.
* @param s Size of the images to process.
* @param p Pixel format of the images to process.
*/
-FilterGraph::FilterGraph (shared_ptr<Film> film, FFmpegDecoder* decoder, libdcp::Size s, AVPixelFormat p)
+FFmpegFilterGraph::FFmpegFilterGraph (shared_ptr<Film> film, FFmpegDecoder* decoder, libdcp::Size s, AVPixelFormat p)
: _buffer_src_context (0)
, _buffer_sink_context (0)
, _size (s)
, _pixel_format (p)
{
+ _frame = av_frame_alloc ();
+
string filters = Filter::ffmpeg_strings (film->filters()).first;
if (!filters.empty ()) {
filters += N_(",");
@@ -80,20 +75,20 @@ FilterGraph::FilterGraph (shared_ptr<Film> film, FFmpegDecoder* decoder, libdcp:
throw DecodeError (N_("could not find buffer src filter"));
}
- AVFilter* buffer_sink = get_sink ();
+ AVFilter* buffer_sink = avfilter_get_by_name(N_("buffersink"));
+ if (buffer_sink == 0) {
+ throw DecodeError (N_("Could not create buffer sink filter"));
+ }
stringstream a;
- a << _size.width << N_(":")
- << _size.height << N_(":")
- << _pixel_format << N_(":")
- << decoder->time_base_numerator() << N_(":")
- << decoder->time_base_denominator() << N_(":")
- << decoder->sample_aspect_ratio_numerator() << N_(":")
- << decoder->sample_aspect_ratio_denominator();
+ a << "video_size=" << _size.width << "x" << _size.height << ":"
+ << "pix_fmt=" << _pixel_format << ":"
+ << "time_base=" << decoder->time_base_numerator() << "/" << decoder->time_base_denominator() << ":"
+ << "pixel_aspect=" << decoder->sample_aspect_ratio_numerator() << "/" << decoder->sample_aspect_ratio_denominator();
int r;
- if ((r = avfilter_graph_create_filter (&_buffer_src_context, buffer_src, N_("in"), a.str().c_str(), 0, graph)) < 0) {
+ if ((r = avfilter_graph_create_filter (&_buffer_src_context, buffer_src, "in", a.str().c_str(), 0, graph)) < 0) {
throw DecodeError (N_("could not create buffer source"));
}
@@ -107,6 +102,8 @@ FilterGraph::FilterGraph (shared_ptr<Film> film, FFmpegDecoder* decoder, libdcp:
throw DecodeError (N_("could not create buffer sink."));
}
+ av_free (sink_params);
+
AVFilterInOut* outputs = avfilter_inout_alloc ();
outputs->name = av_strdup(N_("in"));
outputs->filter_ctx = _buffer_src_context;
@@ -119,15 +116,9 @@ FilterGraph::FilterGraph (shared_ptr<Film> film, FFmpegDecoder* decoder, libdcp:
inputs->pad_idx = 0;
inputs->next = 0;
-#if LIBAVFILTER_VERSION_MAJOR == 2 && LIBAVFILTER_VERSION_MINOR == 15
- if (avfilter_graph_parse (graph, filters.c_str(), inputs, outputs, 0) < 0) {
- throw DecodeError (N_("could not set up filter graph."));
- }
-#else
if (avfilter_graph_parse (graph, filters.c_str(), &inputs, &outputs, 0) < 0) {
throw DecodeError (N_("could not set up filter graph."));
}
-#endif
if (avfilter_graph_config (graph, 0) < 0) {
throw DecodeError (N_("could not configure filter graph."));
@@ -136,66 +127,29 @@ FilterGraph::FilterGraph (shared_ptr<Film> film, FFmpegDecoder* decoder, libdcp:
/* XXX: leaking `inputs' / `outputs' ? */
}
+FFmpegFilterGraph::~FFmpegFilterGraph ()
+{
+ av_frame_free (&_frame);
+}
+
/** Take an AVFrame and process it using our configured filters, returning a
- * set of Images.
+ * set of Images. Caller handles memory management of the input frame.
*/
list<shared_ptr<Image> >
-FilterGraph::process (AVFrame const * frame)
+FFmpegFilterGraph::process (AVFrame* frame)
{
list<shared_ptr<Image> > images;
-
-#if LIBAVFILTER_VERSION_MAJOR == 2 && LIBAVFILTER_VERSION_MINOR >= 53 && LIBAVFILTER_VERSION_MINOR <= 61
-
- if (av_vsrc_buffer_add_frame (_buffer_src_context, frame, 0) < 0) {
- throw DecodeError (N_("could not push buffer into filter chain."));
- }
-
-#elif LIBAVFILTER_VERSION_MAJOR == 2 && LIBAVFILTER_VERSION_MINOR == 15
-
- AVRational par;
- par.num = sample_aspect_ratio_numerator ();
- par.den = sample_aspect_ratio_denominator ();
-
- if (av_vsrc_buffer_add_frame (_buffer_src_context, frame, 0, par) < 0) {
- throw DecodeError (N_("could not push buffer into filter chain."));
- }
-
-#else
if (av_buffersrc_write_frame (_buffer_src_context, frame) < 0) {
throw DecodeError (N_("could not push buffer into filter chain."));
}
-#endif
-
-#if LIBAVFILTER_VERSION_MAJOR == 2 && LIBAVFILTER_VERSION_MINOR >= 15 && LIBAVFILTER_VERSION_MINOR <= 61
- while (avfilter_poll_frame (_buffer_sink_context->inputs[0])) {
-#else
- while (av_buffersink_read (_buffer_sink_context, 0)) {
-#endif
-
-#if LIBAVFILTER_VERSION_MAJOR == 2 && LIBAVFILTER_VERSION_MINOR >= 15
-
- int r = avfilter_request_frame (_buffer_sink_context->inputs[0]);
- if (r < 0) {
- throw DecodeError (N_("could not request filtered frame"));
- }
-
- AVFilterBufferRef* filter_buffer = _buffer_sink_context->inputs[0]->cur_buf;
-
-#else
-
- AVFilterBufferRef* filter_buffer;
- if (av_buffersink_get_buffer_ref (_buffer_sink_context, &filter_buffer, 0) < 0) {
- filter_buffer = 0;
+ while (1) {
+ if (av_buffersink_get_frame (_buffer_sink_context, _frame) < 0) {
+ break;
}
-#endif
-
- if (filter_buffer) {
- /* This takes ownership of filter_buffer */
- images.push_back (shared_ptr<Image> (new FilterBufferImage ((PixelFormat) frame->format, filter_buffer)));
- }
+ images.push_back (shared_ptr<Image> (new SimpleImage (_frame)));
}
return images;
@@ -206,7 +160,25 @@ FilterGraph::process (AVFrame const * frame)
* @return true if this chain can process images with `s' and `p', otherwise false.
*/
bool
-FilterGraph::can_process (libdcp::Size s, AVPixelFormat p) const
+FFmpegFilterGraph::can_process (libdcp::Size s, AVPixelFormat p) const
{
return (_size == s && _pixel_format == p);
}
+
+list<shared_ptr<Image> >
+EmptyFilterGraph::process (AVFrame* frame)
+{
+ list<shared_ptr<Image> > im;
+ im.push_back (shared_ptr<Image> (new SimpleImage (frame)));
+ return im;
+}
+
+shared_ptr<FilterGraph>
+filter_graph_factory (shared_ptr<Film> film, FFmpegDecoder* decoder, libdcp::Size size, AVPixelFormat pixel_format)
+{
+ if (film->filters().empty() && film->crop() == Crop()) {
+ return shared_ptr<FilterGraph> (new EmptyFilterGraph);
+ }
+
+ return shared_ptr<FilterGraph> (new FFmpegFilterGraph (film, decoder, size, pixel_format));
+}
diff --git a/src/lib/filter_graph.h b/src/lib/filter_graph.h
index 7e4e8422b..2138943e4 100644
--- a/src/lib/filter_graph.h
+++ b/src/lib/filter_graph.h
@@ -25,28 +25,48 @@
#define DVDOMATIC_FILTER_GRAPH_H
#include "util.h"
-#include "ffmpeg_compatibility.h"
class Image;
class VideoFilter;
class FFmpegDecoder;
-/** @class FilterGraph
+class FilterGraph
+{
+public:
+ virtual bool can_process (libdcp::Size, AVPixelFormat) const = 0;
+ virtual std::list<boost::shared_ptr<Image> > process (AVFrame *) = 0;
+};
+
+class EmptyFilterGraph : public FilterGraph
+{
+public:
+ bool can_process (libdcp::Size, AVPixelFormat) const {
+ return true;
+ }
+
+ std::list<boost::shared_ptr<Image> > process (AVFrame *);
+};
+
+/** @class FFmpegFilterGraph
* @brief A graph of FFmpeg filters.
*/
-class FilterGraph
+class FFmpegFilterGraph : public FilterGraph
{
public:
- FilterGraph (boost::shared_ptr<Film> film, FFmpegDecoder* decoder, libdcp::Size s, AVPixelFormat p);
+ FFmpegFilterGraph (boost::shared_ptr<Film> film, FFmpegDecoder* decoder, libdcp::Size s, AVPixelFormat p);
+ ~FFmpegFilterGraph ();
bool can_process (libdcp::Size s, AVPixelFormat p) const;
- std::list<boost::shared_ptr<Image> > process (AVFrame const * frame);
+ std::list<boost::shared_ptr<Image> > process (AVFrame * frame);
private:
AVFilterContext* _buffer_src_context;
AVFilterContext* _buffer_sink_context;
libdcp::Size _size; ///< size of the images that this chain can process
AVPixelFormat _pixel_format; ///< pixel format of the images that this chain can process
+ AVFrame* _frame;
};
+boost::shared_ptr<FilterGraph> filter_graph_factory (boost::shared_ptr<Film>, FFmpegDecoder *, libdcp::Size, AVPixelFormat);
+
#endif
diff --git a/src/lib/image.cc b/src/lib/image.cc
index 1be41fecf..b166dfac6 100644
--- a/src/lib/image.cc
+++ b/src/lib/image.cc
@@ -35,6 +35,7 @@ extern "C" {
#include <libavfilter/avfiltergraph.h>
#include <libpostproc/postprocess.h>
#include <libavutil/pixfmt.h>
+#include <libavutil/pixdesc.h>
}
#include "image.h"
#include "exceptions.h"
@@ -58,55 +59,32 @@ Image::swap (Image& other)
int
Image::lines (int n) const
{
- switch (_pixel_format) {
- case PIX_FMT_YUV420P:
- if (n == 0) {
- return size().height;
- } else {
- return size().height / 2;
- }
- break;
- case PIX_FMT_RGB24:
- case PIX_FMT_RGBA:
- case PIX_FMT_YUV422P10LE:
- case PIX_FMT_YUV422P:
- case PIX_FMT_YUV444P:
- case PIX_FMT_YUV444P9BE:
- case PIX_FMT_YUV444P9LE:
- case PIX_FMT_YUV444P10BE:
- case PIX_FMT_YUV444P10LE:
- case PIX_FMT_UYVY422:
+ if (n == 0) {
return size().height;
- default:
+ }
+
+ AVPixFmtDescriptor const * d = av_pix_fmt_desc_get(_pixel_format);
+ if (!d) {
throw PixelFormatError (N_("lines()"), _pixel_format);
}
-
- return 0;
+
+ return size().height / pow(2, d->log2_chroma_h);
}
/** @return Number of components */
int
Image::components () const
{
- switch (_pixel_format) {
- case PIX_FMT_YUV420P:
- case PIX_FMT_YUV422P10LE:
- case PIX_FMT_YUV422P:
- case PIX_FMT_YUV444P:
- case PIX_FMT_YUV444P9BE:
- case PIX_FMT_YUV444P9LE:
- case PIX_FMT_YUV444P10BE:
- case PIX_FMT_YUV444P10LE:
- return 3;
- case PIX_FMT_RGB24:
- case PIX_FMT_RGBA:
- case PIX_FMT_UYVY422:
- return 1;
- default:
+ AVPixFmtDescriptor const * d = av_pix_fmt_desc_get(_pixel_format);
+ if (!d) {
throw PixelFormatError (N_("components()"), _pixel_format);
}
- return 0;
+ if ((d->flags & PIX_FMT_PLANAR) == 0) {
+ return 1;
+ }
+
+ return d->nb_components;
}
shared_ptr<Image>
@@ -296,12 +274,12 @@ Image::make_black ()
{
/* U/V black value for 8-bit colour */
static uint8_t const eight_bit_uv = (1 << 7) - 1;
-
/* U/V black value for 9-bit colour */
static uint16_t const nine_bit_uv = (1 << 8) - 1;
-
/* U/V black value for 10-bit colour */
static uint16_t const ten_bit_uv = (1 << 9) - 1;
+ /* U/V black value for 16-bit colour */
+ static uint16_t const sixteen_bit_uv = (1 << 15) - 1;
switch (_pixel_format) {
case PIX_FMT_YUV420P:
@@ -326,11 +304,17 @@ Image::make_black ()
case PIX_FMT_YUV444P10LE:
yuv_16_black (ten_bit_uv);
break;
+
+ case PIX_FMT_YUV422P16LE:
+ case PIX_FMT_YUV444P16LE:
+ yuv_16_black (sixteen_bit_uv);
+ break;
case PIX_FMT_YUV444P10BE:
case PIX_FMT_YUV422P10BE:
yuv_16_black (swap_16 (ten_bit_uv));
-
+ break;
+
case PIX_FMT_RGB24:
memset (data()[0], 0, lines(0) * stride()[0]);
break;
@@ -420,53 +404,36 @@ Image::write_to_socket (shared_ptr<Socket> socket) const
float
Image::bytes_per_pixel (int c) const
{
- if (c == 3) {
+ AVPixFmtDescriptor const * d = av_pix_fmt_desc_get(_pixel_format);
+ if (!d) {
+ throw PixelFormatError (N_("lines()"), _pixel_format);
+ }
+
+ if (c >= components()) {
return 0;
}
+
+ float bpp[4] = { 0, 0, 0, 0 };
+
+ bpp[0] = floor ((d->comp[0].depth_minus1 + 1 + 7) / 8);
+ if (d->nb_components > 1) {
+ bpp[1] = floor ((d->comp[1].depth_minus1 + 1 + 7) / 8) / pow (2, d->log2_chroma_w);
+ }
+ if (d->nb_components > 2) {
+ bpp[2] = floor ((d->comp[2].depth_minus1 + 1 + 7) / 8) / pow (2, d->log2_chroma_w);
+ }
+ if (d->nb_components > 3) {
+ bpp[3] = floor ((d->comp[3].depth_minus1 + 1 + 7) / 8) / pow (2, d->log2_chroma_w);
+ }
- switch (_pixel_format) {
- case PIX_FMT_RGB24:
- if (c == 0) {
- return 3;
- } else {
- return 0;
- }
- case PIX_FMT_RGBA:
- if (c == 0) {
- return 4;
- } else {
- return 0;
- }
- case PIX_FMT_YUV420P:
- case PIX_FMT_YUV422P:
- if (c == 0) {
- return 1;
- } else {
- return 0.5;
- }
- case PIX_FMT_YUV422P10LE:
- if (c == 0) {
- return 2;
- } else {
- return 1;
- }
- case PIX_FMT_UYVY422:
- return 2;
- case PIX_FMT_YUV444P:
- return 3;
- case PIX_FMT_YUV444P9BE:
- case PIX_FMT_YUV444P9LE:
- case PIX_FMT_YUV444P10LE:
- case PIX_FMT_YUV444P10BE:
- return 6;
- default:
- throw PixelFormatError (N_("bytes_per_pixel()"), _pixel_format);
+ if ((d->flags & PIX_FMT_PLANAR) == 0) {
+ /* Not planar; sum them up */
+ return bpp[0] + bpp[1] + bpp[2] + bpp[3];
}
- return 0;
+ return bpp[c];
}
-
/** Construct a SimpleImage of a given size and format, allocating memory
* as required.
*
@@ -502,10 +469,9 @@ SimpleImage::allocate ()
SimpleImage::SimpleImage (SimpleImage const & other)
: Image (other)
+ , _size (other._size)
+ , _aligned (other._aligned)
{
- _size = other._size;
- _aligned = other._aligned;
-
allocate ();
for (int i = 0; i < components(); ++i) {
@@ -519,6 +485,25 @@ SimpleImage::SimpleImage (SimpleImage const & other)
}
}
+SimpleImage::SimpleImage (AVFrame* frame)
+ : Image (static_cast<AVPixelFormat> (frame->format))
+ , _size (frame->width, frame->height)
+ , _aligned (true)
+{
+ allocate ();
+
+ for (int i = 0; i < components(); ++i) {
+ uint8_t* p = _data[i];
+ uint8_t* q = frame->data[i];
+ for (int j = 0; j < lines(i); ++j) {
+ memcpy (p, q, _line_size[i]);
+ p += stride()[i];
+ /* AVFrame's linesize is what we call `stride' */
+ q += frame->linesize[i];
+ }
+ }
+}
+
SimpleImage::SimpleImage (shared_ptr<const Image> other)
: Image (*other.get())
{
@@ -609,59 +594,6 @@ SimpleImage::aligned () const
return _aligned;
}
-FilterBufferImage::FilterBufferImage (AVPixelFormat p, AVFilterBufferRef* b)
- : Image (p)
- , _buffer (b)
-{
- _line_size = (int *) av_malloc (4 * sizeof (int));
- _line_size[0] = _line_size[1] = _line_size[2] = _line_size[3] = 0;
-
- for (int i = 0; i < components(); ++i) {
- _line_size[i] = size().width * bytes_per_pixel(i);
- }
-}
-
-FilterBufferImage::~FilterBufferImage ()
-{
- avfilter_unref_buffer (_buffer);
- av_free (_line_size);
-}
-
-uint8_t **
-FilterBufferImage::data () const
-{
- return _buffer->data;
-}
-
-int *
-FilterBufferImage::line_size () const
-{
- return _line_size;
-}
-
-int *
-FilterBufferImage::stride () const
-{
- /* I've seen images where the _buffer->linesize is larger than the width
- (by a small amount), suggesting that _buffer->linesize is what we call
- stride. But I'm not sure.
- */
- return _buffer->linesize;
-}
-
-libdcp::Size
-FilterBufferImage::size () const
-{
- return libdcp::Size (_buffer->video->w, _buffer->video->h);
-}
-
-bool
-FilterBufferImage::aligned () const
-{
- /* XXX? */
- return true;
-}
-
RGBPlusAlphaImage::RGBPlusAlphaImage (shared_ptr<const Image> im)
: SimpleImage (im->pixel_format(), im->size(), false)
{
diff --git a/src/lib/image.h b/src/lib/image.h
index 62961a92e..70dacfaee 100644
--- a/src/lib/image.h
+++ b/src/lib/image.h
@@ -32,10 +32,8 @@ extern "C" {
#include <libavfilter/avfilter.h>
}
#include "util.h"
-#include "ffmpeg_compatibility.h"
class Scaler;
-class RGBFrameImage;
class SimpleImage;
/** @class Image
@@ -92,6 +90,8 @@ protected:
virtual void swap (Image &);
float bytes_per_pixel (int) const;
+ friend class pixel_formats_test;
+
private:
void yuv_16_black (uint16_t);
static uint16_t swap_16 (uint16_t);
@@ -99,30 +99,6 @@ private:
AVPixelFormat _pixel_format; ///< FFmpeg's way of describing the pixel format of this Image
};
-/** @class FilterBufferImage
- * @brief An Image that is held in an AVFilterBufferRef.
- */
-class FilterBufferImage : public Image
-{
-public:
- FilterBufferImage (AVPixelFormat, AVFilterBufferRef *);
- ~FilterBufferImage ();
-
- uint8_t ** data () const;
- int * line_size () const;
- int * stride () const;
- libdcp::Size size () const;
- bool aligned () const;
-
-private:
- /* Not allowed */
- FilterBufferImage (FilterBufferImage const &);
- FilterBufferImage& operator= (FilterBufferImage const &);
-
- AVFilterBufferRef* _buffer;
- int* _line_size;
-};
-
/** @class SimpleImage
* @brief An Image for which memory is allocated using a `simple' av_malloc().
*/
@@ -130,6 +106,7 @@ class SimpleImage : public Image
{
public:
SimpleImage (AVPixelFormat, libdcp::Size, bool);
+ SimpleImage (AVFrame *);
SimpleImage (SimpleImage const &);
SimpleImage (boost::shared_ptr<const Image>);
SimpleImage& operator= (SimpleImage const &);
diff --git a/src/lib/matcher.h b/src/lib/matcher.h
index 41aa373a4..21e42f53d 100644
--- a/src/lib/matcher.h
+++ b/src/lib/matcher.h
@@ -19,7 +19,6 @@
#include <boost/optional.hpp>
#include "processor.h"
-#include "ffmpeg_compatibility.h"
class Matcher : public Processor, public TimedAudioSink, public TimedVideoSink, public AudioSource, public VideoSource
{
diff --git a/src/lib/wscript b/src/lib/wscript
index 253a496d1..66207b1e4 100644
--- a/src/lib/wscript
+++ b/src/lib/wscript
@@ -22,7 +22,6 @@ sources = """
examine_content_job.cc
exceptions.cc
filter_graph.cc
- ffmpeg_compatibility.cc
ffmpeg_decoder.cc
film.cc
filter.cc