*/
#include "active_captions.h"
-#include "piece.h"
#include "caption_content.h"
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
for (Map::const_iterator i = _data.begin(); i != _data.end(); ++i) {
- shared_ptr<Piece> piece = i->first.lock ();
- if (!piece) {
+ shared_ptr<CaptionContent> caption = i->first.lock ();
+ if (!caption) {
continue;
}
- if (!piece->content->caption->use() || (!always_burn_captions && !piece->content->caption->burn())) {
- /* Not burning this piece */
+ if (!caption->use() || (!always_burn_captions && !caption->burn())) {
+ /* Not burning this content */
continue;
}
}
/** Add a new subtitle with a from time.
- * @param piece Piece that the subtitle is from.
+ * @param content Content that the subtitle is from.
* @param ps Subtitles.
* @param from From time for these subtitles.
*/
void
-ActiveCaptions::add_from (weak_ptr<Piece> piece, PlayerCaption ps, DCPTime from)
+ActiveCaptions::add_from (weak_ptr<CaptionContent> content, PlayerCaption ps, DCPTime from)
{
- if (_data.find(piece) == _data.end()) {
- _data[piece] = list<Period>();
+ if (_data.find(content) == _data.end()) {
+ _data[content] = list<Period>();
}
- _data[piece].push_back (Period (ps, from));
+ _data[content].push_back (Period (ps, from));
}
-/** Add the to time for the last subtitle added from a piece.
- * @param piece Piece that the subtitle is from.
- * @param to To time for the last subtitle submitted to add_from for this piece.
+/** Add the to time for the last subtitle added from a piece of content.
+ * @param content Content that the subtitle is from.
+ * @param to To time for the last subtitle submitted to add_from for this content.
* @return Return the corresponding subtitles and their from time.
*/
pair<PlayerCaption, DCPTime>
-ActiveCaptions::add_to (weak_ptr<Piece> piece, DCPTime to)
+ActiveCaptions::add_to (weak_ptr<CaptionContent> content, DCPTime to)
{
- DCPOMATIC_ASSERT (_data.find(piece) != _data.end());
+ DCPOMATIC_ASSERT (_data.find(content) != _data.end());
- _data[piece].back().to = to;
+ _data[content].back().to = to;
- BOOST_FOREACH (TextCaption& i, _data[piece].back().subs.text) {
+ BOOST_FOREACH (TextCaption& i, _data[content].back().subs.text) {
i.set_out (dcp::Time(to.seconds(), 1000));
}
- return make_pair (_data[piece].back().subs, _data[piece].back().from);
+ return make_pair (_data[content].back().subs, _data[content].back().from);
}
-/** @param piece A piece.
- * @return true if we have any active subtitles from this piece.
+/** @param content Some content.
+ * @return true if we have any active subtitles from this content.
*/
bool
-ActiveCaptions::have (weak_ptr<Piece> piece) const
+ActiveCaptions::have (weak_ptr<CaptionContent> content) const
{
- Map::const_iterator i = _data.find(piece);
+ Map::const_iterator i = _data.find(content);
if (i == _data.end()) {
return false;
}
#include <list>
#include <map>
-class Piece;
+class CaptionContent;
/** @class ActiveCaptions
* @brief A class to maintain information on active subtitles for Player.
std::list<PlayerCaption> get_burnt (DCPTimePeriod period, bool always_burn_captions) const;
void clear_before (DCPTime time);
void clear ();
- void add_from (boost::weak_ptr<Piece> piece, PlayerCaption ps, DCPTime from);
- std::pair<PlayerCaption, DCPTime> add_to (boost::weak_ptr<Piece> piece, DCPTime to);
- bool have (boost::weak_ptr<Piece> piece) const;
+ void add_from (boost::weak_ptr<CaptionContent> content, PlayerCaption ps, DCPTime from);
+ std::pair<PlayerCaption, DCPTime> add_to (boost::weak_ptr<CaptionContent> content, DCPTime to);
+ bool have (boost::weak_ptr<CaptionContent> content) const;
private:
class Period
boost::optional<DCPTime> to;
};
- typedef std::map<boost::weak_ptr<Piece>, std::list<Period> > Map;
+ typedef std::map<boost::weak_ptr<CaptionContent>, std::list<Period> > Map;
Map _data;
};
}
if (decoder->caption) {
- decoder->caption->BitmapStart.connect (bind (&Player::bitmap_text_start, this, weak_ptr<Piece> (piece), _1));
- decoder->caption->PlainStart.connect (bind (&Player::plain_text_start, this, weak_ptr<Piece> (piece), _1));
- decoder->caption->Stop.connect (bind (&Player::subtitle_stop, this, weak_ptr<Piece> (piece), _1, _2));
+ decoder->caption->BitmapStart.connect (
+ bind(&Player::bitmap_text_start, this, weak_ptr<Piece>(piece), weak_ptr<CaptionContent>(piece->content->caption), _1)
+ );
+ decoder->caption->PlainStart.connect (
+ bind(&Player::plain_text_start, this, weak_ptr<Piece>(piece), weak_ptr<CaptionContent>(piece->content->caption), _1)
+ );
+ decoder->caption->Stop.connect (
+ bind(&Player::subtitle_stop, this, weak_ptr<Piece>(piece), weak_ptr<CaptionContent>(piece->content->caption), _1, _2)
+ );
}
}
}
void
-Player::bitmap_text_start (weak_ptr<Piece> wp, ContentBitmapCaption subtitle)
+Player::bitmap_text_start (weak_ptr<Piece> wp, weak_ptr<CaptionContent> wc, ContentBitmapCaption subtitle)
{
shared_ptr<Piece> piece = wp.lock ();
- if (!piece) {
+ shared_ptr<CaptionContent> caption = wc.lock ();
+ if (!piece || !caption) {
return;
}
/* Apply content's subtitle offsets */
- subtitle.sub.rectangle.x += piece->content->caption->x_offset ();
- subtitle.sub.rectangle.y += piece->content->caption->y_offset ();
+ subtitle.sub.rectangle.x += caption->x_offset ();
+ subtitle.sub.rectangle.y += caption->y_offset ();
/* Apply a corrective translation to keep the subtitle centred after the scale that is coming up */
- subtitle.sub.rectangle.x -= subtitle.sub.rectangle.width * ((piece->content->caption->x_scale() - 1) / 2);
- subtitle.sub.rectangle.y -= subtitle.sub.rectangle.height * ((piece->content->caption->y_scale() - 1) / 2);
+ subtitle.sub.rectangle.x -= subtitle.sub.rectangle.width * ((caption->x_scale() - 1) / 2);
+ subtitle.sub.rectangle.y -= subtitle.sub.rectangle.height * ((caption->y_scale() - 1) / 2);
/* Apply content's subtitle scale */
- subtitle.sub.rectangle.width *= piece->content->caption->x_scale ();
- subtitle.sub.rectangle.height *= piece->content->caption->y_scale ();
+ subtitle.sub.rectangle.width *= caption->x_scale ();
+ subtitle.sub.rectangle.height *= caption->y_scale ();
PlayerCaption ps;
ps.image.push_back (subtitle.sub);
DCPTime from (content_time_to_dcp (piece, subtitle.from()));
- _active_captions[subtitle.type()].add_from (wp, ps, from);
+ _active_captions[subtitle.type()].add_from (wc, ps, from);
}
void
-Player::plain_text_start (weak_ptr<Piece> wp, ContentTextCaption subtitle)
+Player::plain_text_start (weak_ptr<Piece> wp, weak_ptr<CaptionContent> wc, ContentTextCaption subtitle)
{
shared_ptr<Piece> piece = wp.lock ();
- if (!piece) {
+ shared_ptr<CaptionContent> caption = wc.lock ();
+ if (!piece || !caption) {
return;
}
}
BOOST_FOREACH (dcp::SubtitleString s, subtitle.subs) {
- s.set_h_position (s.h_position() + piece->content->caption->x_offset ());
- s.set_v_position (s.v_position() + piece->content->caption->y_offset ());
- float const xs = piece->content->caption->x_scale();
- float const ys = piece->content->caption->y_scale();
+ s.set_h_position (s.h_position() + caption->x_offset ());
+ s.set_v_position (s.v_position() + caption->y_offset ());
+ float const xs = caption->x_scale();
+ float const ys = caption->y_scale();
float size = s.size();
/* Adjust size to express the common part of the scaling;
}
s.set_in (dcp::Time(from.seconds(), 1000));
- ps.text.push_back (TextCaption (s, piece->content->caption->outline_width()));
- ps.add_fonts (piece->content->caption->fonts ());
+ ps.text.push_back (TextCaption (s, caption->outline_width()));
+ ps.add_fonts (caption->fonts ());
}
- _active_captions[subtitle.type()].add_from (wp, ps, from);
+ _active_captions[subtitle.type()].add_from (wc, ps, from);
}
void
-Player::subtitle_stop (weak_ptr<Piece> wp, ContentTime to, CaptionType type)
+Player::subtitle_stop (weak_ptr<Piece> wp, weak_ptr<CaptionContent> wc, ContentTime to, CaptionType type)
{
- if (!_active_captions[type].have (wp)) {
+ if (!_active_captions[type].have (wc)) {
return;
}
shared_ptr<Piece> piece = wp.lock ();
- if (!piece) {
+ shared_ptr<CaptionContent> caption = wc.lock ();
+ if (!piece || !caption) {
return;
}
return;
}
- pair<PlayerCaption, DCPTime> from = _active_captions[type].add_to (wp, dcp_to);
+ pair<PlayerCaption, DCPTime> from = _active_captions[type].add_to (wc, dcp_to);
bool const always = _always_burn_captions && *_always_burn_captions == type;
- if (piece->content->caption->use() && !always && !piece->content->caption->burn()) {
+ if (caption->use() && !always && !caption->burn()) {
Caption (from.first, type, DCPTimePeriod (from.second, dcp_to));
}
}
boost::shared_ptr<PlayerVideo> black_player_video_frame (Eyes eyes) const;
void video (boost::weak_ptr<Piece>, ContentVideo);
void audio (boost::weak_ptr<Piece>, AudioStreamPtr, ContentAudio);
- void bitmap_text_start (boost::weak_ptr<Piece>, ContentBitmapCaption);
- void plain_text_start (boost::weak_ptr<Piece>, ContentTextCaption);
- void subtitle_stop (boost::weak_ptr<Piece>, ContentTime, CaptionType);
+ void bitmap_text_start (boost::weak_ptr<Piece>, boost::weak_ptr<CaptionContent>, ContentBitmapCaption);
+ void plain_text_start (boost::weak_ptr<Piece>, boost::weak_ptr<CaptionContent>, ContentTextCaption);
+ void subtitle_stop (boost::weak_ptr<Piece>, boost::weak_ptr<CaptionContent>, ContentTime, CaptionType);
DCPTime one_video_frame () const;
void fill_audio (DCPTimePeriod period);
std::pair<boost::shared_ptr<AudioBuffers>, DCPTime> discard_audio (