From ca4d051ceafb77c281583c4e50b391f230544313 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 5 Nov 2012 10:36:55 +0000 Subject: Move trimming into the encoder; seems to be cleaner. --- src/lib/encoder.cc | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'src/lib/encoder.cc') diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc index bb23c9e59..b322be04c 100644 --- a/src/lib/encoder.cc +++ b/src/lib/encoder.cc @@ -23,7 +23,9 @@ #include "encoder.h" #include "util.h" +#include "options.h" +using std::pair; using namespace boost; int const Encoder::_history_size = 25; @@ -101,3 +103,51 @@ Encoder::frame_skipped () boost::mutex::scoped_lock lock (_history_mutex); _just_skipped = true; } + +void +Encoder::process_video (shared_ptr i, SourceFrame f, boost::shared_ptr s) +{ + if (_opt->decode_video_skip != 0 && (f % _opt->decode_video_skip) != 0) { + return; + } + + if (_opt->video_decode_range) { + pair const r = _opt->video_decode_range.get(); + if (f < r.first || f >= r.second) { + return; + } + } + + do_process_video (i, f, s); +} + +void +Encoder::process_audio (shared_ptr data, int64_t f) +{ + if (_opt->audio_decode_range) { + + shared_ptr trimmed (new AudioBuffers (*data.get ())); + + /* Range that we are encoding */ + pair required_range = _opt->audio_decode_range.get(); + /* Range of this block of data */ + pair this_range (f, f + trimmed->frames()); + + if (this_range.second < required_range.first || required_range.second < this_range.first) { + /* No part of this audio is within the required range */ + return; + } else if (required_range.first >= this_range.first && required_range.first < this_range.second) { + /* Trim start */ + int64_t const shift = required_range.first - this_range.first; + trimmed->move (shift, 0, trimmed->frames() - shift); + trimmed->set_frames (trimmed->frames() - shift); + } else if (required_range.second >= this_range.first && required_range.second < this_range.second) { + /* Trim end */ + trimmed->set_frames (required_range.second - this_range.first); + } + + data = trimmed; + } + + do_process_audio (data); +} -- cgit v1.2.3