diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-10-15 23:42:19 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-10-15 23:42:19 +0100 |
| commit | 63b7da59cee71ab2ade744a8b547b5d8f2ff6bfc (patch) | |
| tree | 6e107ab63deff4e5e8b5a462f767e6ed4685cbdb /src/lib | |
| parent | bd9906422fe59126a27a3002b2bb4ce497eef508 (diff) | |
Clean up subtitle classes a bit.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/decoder.cc | 12 | ||||
| -rw-r--r-- | src/lib/decoder.h | 5 | ||||
| -rw-r--r-- | src/lib/ffmpeg_decoder.cc | 2 | ||||
| -rw-r--r-- | src/lib/ffmpeg_decoder.h | 1 | ||||
| -rw-r--r-- | src/lib/subtitle.cc | 29 | ||||
| -rw-r--r-- | src/lib/subtitle.h | 26 |
6 files changed, 43 insertions, 32 deletions
diff --git a/src/lib/decoder.cc b/src/lib/decoder.cc index 8989a938b..ef2ef6fb9 100644 --- a/src/lib/decoder.cc +++ b/src/lib/decoder.cc @@ -305,8 +305,8 @@ Decoder::process_video (AVFrame* frame) } shared_ptr<Subtitle> sub; - if (_subtitle && _subtitle->displayed_at (double (last_video_frame()) / rint (_fs->frames_per_second))) { - sub = _subtitle; + if (_timed_subtitle && _timed_subtitle->displayed_at (double (last_video_frame()) / rint (_fs->frames_per_second))) { + sub = _timed_subtitle->subtitle (); } TIMING ("Decoder emits %1", _video_frame); @@ -412,12 +412,12 @@ Decoder::setup_video_filters () } void -Decoder::process_subtitle (shared_ptr<Subtitle> s) +Decoder::process_subtitle (shared_ptr<TimedSubtitle> s) { - _subtitle = s; + _timed_subtitle = s; if (_opt->apply_crop) { - Position const p = _subtitle->position (); - _subtitle->set_position (Position (p.x - _fs->crop.left, p.y - _fs->crop.top)); + Position const p = _timed_subtitle->subtitle()->position (); + _timed_subtitle->subtitle()->set_position (Position (p.x - _fs->crop.left, p.y - _fs->crop.top)); } } diff --git a/src/lib/decoder.h b/src/lib/decoder.h index 805955b9d..8a04ec9f2 100644 --- a/src/lib/decoder.h +++ b/src/lib/decoder.h @@ -37,6 +37,7 @@ class Options; class Image; class Log; class DelayLine; +class TimedSubtitle; class Subtitle; /** @class Decoder. @@ -103,7 +104,7 @@ protected: void process_video (AVFrame *); void process_audio (uint8_t *, int); - void process_subtitle (boost::shared_ptr<Subtitle>); + void process_subtitle (boost::shared_ptr<TimedSubtitle>); /** our FilmState */ boost::shared_ptr<const FilmState> _fs; @@ -140,7 +141,7 @@ private: */ int64_t _audio_frames_processed; - boost::shared_ptr<Subtitle> _subtitle; + boost::shared_ptr<TimedSubtitle> _timed_subtitle; }; #endif diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index e01405191..e85439f6e 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -248,7 +248,7 @@ FFmpegDecoder::do_pass () int got_subtitle; AVSubtitle sub; if (avcodec_decode_subtitle2 (_subtitle_codec_context, &sub, &got_subtitle, &_packet) && got_subtitle) { - process_subtitle (shared_ptr<Subtitle> (new Subtitle (sub))); + process_subtitle (shared_ptr<TimedSubtitle> (new TimedSubtitle (sub))); avsubtitle_free (&sub); } } diff --git a/src/lib/ffmpeg_decoder.h b/src/lib/ffmpeg_decoder.h index d34c22785..ec822bf79 100644 --- a/src/lib/ffmpeg_decoder.h +++ b/src/lib/ffmpeg_decoder.h @@ -44,7 +44,6 @@ class FilmState; class Options; class Image; class Log; -class Subtitle; /** @class FFmpegDecoder * @brief A decoder using FFmpeg to decode content. diff --git a/src/lib/subtitle.cc b/src/lib/subtitle.cc index 2e9a89088..7e1ca2d2a 100644 --- a/src/lib/subtitle.cc +++ b/src/lib/subtitle.cc @@ -25,7 +25,7 @@ using namespace std; using namespace boost; -Subtitle::Subtitle (AVSubtitle const & sub) +TimedSubtitle::TimedSubtitle (AVSubtitle const & sub) { /* subtitle PTS in seconds */ float const packet_time = (sub.pts / AV_TIME_BASE) + float (sub.pts % AV_TIME_BASE) / 1e6; @@ -44,15 +44,14 @@ Subtitle::Subtitle (AVSubtitle const & sub) throw DecodeError ("non-bitmap subtitles not yet supported"); } - _position = Position (rect->x, rect->y); - _image.reset (new AlignedImage (PIX_FMT_RGBA, Size (rect->w, rect->h))); + shared_ptr<Image> image (new AlignedImage (PIX_FMT_RGBA, Size (rect->w, rect->h))); /* Start of the first line in the subtitle */ uint8_t* sub_p = rect->pict.data[0]; /* sub_p looks up into a RGB palette which is here */ uint32_t const * palette = (uint32_t *) rect->pict.data[1]; /* Start of the output data */ - uint32_t* out_p = (uint32_t *) _image->data()[0]; + uint32_t* out_p = (uint32_t *) image->data()[0]; for (int y = 0; y < rect->h; ++y) { uint8_t* sub_line_p = sub_p; @@ -61,26 +60,26 @@ Subtitle::Subtitle (AVSubtitle const & sub) *out_line_p++ = palette[*sub_line_p++]; } sub_p += rect->pict.linesize[0]; - out_p += _image->stride()[0] / sizeof (uint32_t); + out_p += image->stride()[0] / sizeof (uint32_t); } -} -Subtitle::Subtitle (Position p, shared_ptr<Image> i) - : _from (0) - , _to (0) - , _position (p) - , _image (i) -{ + _subtitle.reset (new Subtitle (Position (rect->x, rect->y), image)); +} -} - /** @param t Time in seconds from the start of the film */ bool -Subtitle::displayed_at (double t) +TimedSubtitle::displayed_at (double t) const { return t >= _from && t <= _to; } +Subtitle::Subtitle (Position p, shared_ptr<Image> i) + : _position (p) + , _image (i) +{ + +} + Rectangle subtitle_transformed_area ( float target_x_scale, float target_y_scale, diff --git a/src/lib/subtitle.h b/src/lib/subtitle.h index ef9571ad4..de8f02596 100644 --- a/src/lib/subtitle.h +++ b/src/lib/subtitle.h @@ -27,11 +27,8 @@ class Image; class Subtitle { public: - Subtitle (AVSubtitle const &); Subtitle (Position p, boost::shared_ptr<Image> i); - bool displayed_at (double t); - void set_position (Position p) { _position = p; } @@ -47,10 +44,6 @@ public: Rectangle area () const; private: - /** display from time in seconds from the start of the film */ - double _from; - /** display to time in seconds from the start of the film */ - double _to; Position _position; boost::shared_ptr<Image> _image; }; @@ -61,3 +54,22 @@ subtitle_transformed_area ( Rectangle sub_area, int subtitle_offset, float subtitle_scale ); +class TimedSubtitle +{ +public: + TimedSubtitle (AVSubtitle const &); + + bool displayed_at (double t) const; + + boost::shared_ptr<Subtitle> subtitle () const { + return _subtitle; + } + +private: + boost::shared_ptr<Subtitle> _subtitle; + + /** display from time in seconds from the start of the film */ + double _from; + /** display to time in seconds from the start of the film */ + double _to; +}; |
