summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-07-09 22:16:46 +0100
committerCarl Hetherington <cth@carlh.net>2013-07-09 22:16:46 +0100
commitdf52b97f307605aad15ab5f01c8fdcf93afc9d15 (patch)
treef7babd41e71985c611f3632395c52535f1c36f17 /src/lib
parent89115db77729a2c99f1a09ff6a461720e16f889e (diff)
Various fixes; simplification of FilmViewer; make image appear on first load of content.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ffmpeg_decoder.cc16
-rw-r--r--src/lib/ffmpeg_decoder.h1
-rw-r--r--src/lib/film.cc2
-rw-r--r--src/lib/image.cc1
-rw-r--r--src/lib/player.cc32
-rw-r--r--src/lib/player.h8
6 files changed, 53 insertions, 7 deletions
diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc
index bf0949130..3b7d727b8 100644
--- a/src/lib/ffmpeg_decoder.cc
+++ b/src/lib/ffmpeg_decoder.cc
@@ -67,6 +67,7 @@ FFmpegDecoder::FFmpegDecoder (shared_ptr<const Film> f, shared_ptr<const FFmpegC
, _decode_video (video)
, _decode_audio (audio)
, _pts_offset (0)
+ , _just_sought (false)
{
setup_subtitle ();
@@ -298,15 +299,16 @@ FFmpegDecoder::seek_back ()
void
FFmpegDecoder::do_seek (VideoContent::Frame frame, bool backwards, bool accurate)
{
- int64_t const vt = frame * _ffmpeg_content->video_frame_rate() / av_q2d (_format_context->streams[_video_stream]->time_base);
+ int64_t const vt = frame / (_ffmpeg_content->video_frame_rate() * av_q2d (_format_context->streams[_video_stream]->time_base));
av_seek_frame (_format_context, _video_stream, vt, backwards ? AVSEEK_FLAG_BACKWARD : 0);
- _video_position = frame;
avcodec_flush_buffers (video_codec_context());
if (_subtitle_codec_context) {
avcodec_flush_buffers (_subtitle_codec_context);
}
+ _just_sought = true;
+
if (accurate) {
while (1) {
int r = av_read_frame (_format_context, &_packet);
@@ -420,6 +422,15 @@ FFmpegDecoder::decode_video_packet ()
if (bet != AV_NOPTS_VALUE) {
double const pts = bet * av_q2d (_format_context->streams[_video_stream]->time_base) - _pts_offset;
+
+ if (_just_sought) {
+ /* We just did a seek, so disable any attempts to correct for where we
+ are / should be.
+ */
+ _video_position = pts * _ffmpeg_content->video_frame_rate ();
+ _just_sought = false;
+ }
+
double const next = _video_position / _ffmpeg_content->video_frame_rate();
double const one_frame = 1 / _ffmpeg_content->video_frame_rate ();
double delta = pts - next;
@@ -445,6 +456,7 @@ FFmpegDecoder::decode_video_packet ()
/* This PTS is within a frame of being right; emit this (otherwise it will be dropped) */
video (image, false, _video_position);
}
+
} else {
shared_ptr<const Film> film = _film.lock ();
assert (film);
diff --git a/src/lib/ffmpeg_decoder.h b/src/lib/ffmpeg_decoder.h
index 8f0482aad..2e64d8801 100644
--- a/src/lib/ffmpeg_decoder.h
+++ b/src/lib/ffmpeg_decoder.h
@@ -85,4 +85,5 @@ private:
bool _decode_audio;
double _pts_offset;
+ bool _just_sought;
};
diff --git a/src/lib/film.cc b/src/lib/film.cc
index fa75ab1f1..7320676d7 100644
--- a/src/lib/film.cc
+++ b/src/lib/film.cc
@@ -128,6 +128,7 @@ Film::Film (string d)
}
set_directory (result.string ());
+ _log.reset (new FileLog ("log"));
}
Film::Film (Film const & o)
@@ -793,6 +794,7 @@ Film::add_content (shared_ptr<Content> c)
c->set_start (_playlist->video_end ());
}
+ cout << "actually adding content.\n";
_playlist->add (c);
}
diff --git a/src/lib/image.cc b/src/lib/image.cc
index 722ff5d3c..0eabbe84d 100644
--- a/src/lib/image.cc
+++ b/src/lib/image.cc
@@ -45,6 +45,7 @@ extern "C" {
using std::string;
using std::min;
+using std::cout;
using boost::shared_ptr;
using libdcp::Size;
diff --git a/src/lib/player.cc b/src/lib/player.cc
index 9969fbf9e..7488364bd 100644
--- a/src/lib/player.cc
+++ b/src/lib/player.cc
@@ -96,6 +96,7 @@ Player::Player (shared_ptr<const Film> f, shared_ptr<const Playlist> p)
{
_playlist->Changed.connect (bind (&Player::playlist_changed, this));
_playlist->ContentChanged.connect (bind (&Player::content_changed, this, _1, _2));
+ _film->Changed.connect (bind (&Player::film_changed, this, _1));
set_video_container_size (_film->container()->size (_film->full_frame ()));
}
@@ -120,7 +121,7 @@ Player::pass ()
}
#ifdef DEBUG_PLAYER
- cout << "= PASS\n";
+ cout << "= PASS " << this << "\n";
#endif
Time earliest_t = TIME_MAX;
@@ -381,7 +382,7 @@ Player::setup_pieces ()
Playlist::ContentList content = _playlist->content ();
sort (content.begin(), content.end(), ContentSorter ());
-
+
for (Playlist::ContentList::iterator i = content.begin(); i != content.end(); ++i) {
shared_ptr<Piece> piece (new Piece (*i));
@@ -445,8 +446,13 @@ Player::content_changed (weak_ptr<Content> w, int p)
return;
}
- if (p == ContentProperty::START || p == ContentProperty::LENGTH) {
+ if (
+ p == ContentProperty::START || p == ContentProperty::LENGTH ||
+ p == VideoContentProperty::VIDEO_CROP || p == VideoContentProperty::VIDEO_RATIO
+ ) {
+
_have_valid_pieces = false;
+ Changed ();
}
}
@@ -454,6 +460,7 @@ void
Player::playlist_changed ()
{
_have_valid_pieces = false;
+ Changed ();
}
void
@@ -495,5 +502,20 @@ Player::emit_silence (OutputAudioFrame most)
_audio_position += _film->audio_frames_to_time (N);
}
-
-
+void
+Player::film_changed (Film::Property p)
+{
+ /* Here we should notice Film properties that affect our output, and
+ alert listeners that our output now would be different to how it was
+ last time we were run.
+ */
+
+ if (
+ p == Film::SCALER || p == Film::WITH_SUBTITLES ||
+ p == Film::SUBTITLE_SCALE || p == Film::SUBTITLE_OFFSET ||
+ p == Film::CONTAINER
+ ) {
+
+ Changed ();
+ }
+}
diff --git a/src/lib/player.h b/src/lib/player.h
index bbdb14ec2..3f8d59d29 100644
--- a/src/lib/player.h
+++ b/src/lib/player.h
@@ -26,6 +26,7 @@
#include "playlist.h"
#include "audio_buffers.h"
#include "content.h"
+#include "film.h"
class Job;
class Film;
@@ -67,6 +68,12 @@ public:
/** Emitted when some audio data is ready */
boost::signals2::signal<void (boost::shared_ptr<const AudioBuffers>, Time)> Audio;
+ /** Emitted when something has changed such that if we went back and emitted
+ * the last frame again it would look different. This is not emitted after
+ * a seek.
+ */
+ boost::signals2::signal<void ()> Changed;
+
private:
void process_video (boost::weak_ptr<Piece>, boost::shared_ptr<const Image>, bool, VideoContent::Frame);
@@ -79,6 +86,7 @@ private:
void emit_black ();
void emit_silence (OutputAudioFrame);
boost::shared_ptr<Resampler> resampler (boost::shared_ptr<AudioContent>);
+ void film_changed (Film::Property);
boost::shared_ptr<const Film> _film;
boost::shared_ptr<const Playlist> _playlist;