From: Mikko Rasa Date: Sun, 18 Oct 2015 11:07:22 +0000 (+0300) Subject: Make some auxiliary information about the stream available X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=60cd42dc4fdb1fdfa438402956e7342a01fc8677;p=xinema.git Make some auxiliary information about the stream available --- diff --git a/source/client.cpp b/source/client.cpp index 0130846..353694e 100644 --- a/source/client.cpp +++ b/source/client.cpp @@ -146,6 +146,9 @@ void Client::stream_created(XineStream &stream) stream.signal_title_changed.connect(sigc::mem_fun(this, &Client::stream_title_changed)); stream.signal_duration_changed.connect(sigc::mem_fun(this, &Client::stream_duration_changed)); stream.signal_position_changed.connect(sigc::mem_fun(this, &Client::stream_position_changed)); + stream.signal_video_size_changed.connect(sigc::mem_fun(this, &Client::stream_size_changed)); + stream.signal_framerate_changed.connect(sigc::mem_fun(this, &Client::stream_framerate_changed)); + stream.signal_codecs_changed.connect(sigc::mem_fun(this, &Client::stream_codecs_changed)); stream.signal_channels_changed.connect(sigc::mem_fun(this, &Client::stream_channels_changed)); stream.signal_current_audio_channel_changed.connect(sigc::mem_fun(this, &Client::stream_audio_channel_changed)); stream.signal_current_spu_channel_changed.connect(sigc::mem_fun(this, &Client::stream_spu_channel_changed)); @@ -163,6 +166,10 @@ void Client::stream_created(XineStream &stream) stream_position_changed(stream.get_position()); } + stream_size_changed(stream.get_video_width(), stream.get_video_height()); + stream_framerate_changed(stream.get_framerate()); + stream_codecs_changed(stream.get_video_codec(), stream.get_audio_codec()); + stream_channels_changed(); stream_audio_channel_changed(stream.get_current_audio_channel()); stream_spu_channel_changed(stream.get_current_spu_channel()); @@ -197,6 +204,22 @@ void Client::stream_position_changed(const Time::TimeDelta &pos) } } +void Client::stream_size_changed(unsigned w, unsigned h) +{ + send_reply(format("video_size %d %d", w, h)); +} + +void Client::stream_framerate_changed(float fps) +{ + send_reply(format("framerate %.2f", fps)); +} + +void Client::stream_codecs_changed(const string &vc, const string &ac) +{ + send_reply("video_codec "+vc); + send_reply("audio_codec "+ac); +} + void Client::stream_channels_changed() { XineStream &stream = get_stream(); diff --git a/source/client.h b/source/client.h index d76a914..2b12e4d 100644 --- a/source/client.h +++ b/source/client.h @@ -40,6 +40,9 @@ private: void stream_title_changed(const std::string &); void stream_duration_changed(const Msp::Time::TimeDelta &); void stream_position_changed(const Msp::Time::TimeDelta &); + void stream_size_changed(unsigned, unsigned); + void stream_framerate_changed(float); + void stream_codecs_changed(const std::string &, const std::string &); void stream_channels_changed(); void stream_audio_channel_changed(int); void stream_spu_channel_changed(int); diff --git a/source/xinestream.cpp b/source/xinestream.cpp index 4fc2e88..2d2c058 100644 --- a/source/xinestream.cpp +++ b/source/xinestream.cpp @@ -10,6 +10,9 @@ XineStream::XineStream(XineEngine &e, const string &mrl): filename(mrl.substr(mrl.rfind('/')+1)), state(STOPPED), title(filename), + video_width(0), + video_height(0), + framerate(0.0f), current_audio(0), current_spu(OFF), channels_changed(false) @@ -120,16 +123,51 @@ void XineStream::tick() update_info(); } +bool XineStream::equals(const string &s1, const char *s2) +{ + if(!s2) + return s1.empty(); + return !s1.compare(s2); +} + void XineStream::update_info() { const char *xt = xine_get_meta_info(stream, XINE_META_INFO_TITLE); - if((xt && title.compare(xt)) || (!xt && !title.empty())) + if(!equals(title, xt)) { MutexLock lock(mutex); title = (xt ? xt : string()); signal_title_changed.emit(get_title()); } + unsigned w = xine_get_stream_info(stream, XINE_STREAM_INFO_VIDEO_WIDTH); + unsigned h = xine_get_stream_info(stream, XINE_STREAM_INFO_VIDEO_HEIGHT); + if(w!=video_width || h!=video_height) + { + MutexLock lock(mutex); + video_width = w; + video_height = h; + signal_video_size_changed.emit(video_width, video_height); + } + + float fps = 90000.0f/xine_get_stream_info(stream, XINE_STREAM_INFO_FRAME_DURATION); + if(fps!=framerate) + { + MutexLock lock(mutex); + framerate = fps; + signal_framerate_changed.emit(framerate); + } + + const char *xvc = xine_get_meta_info(stream, XINE_META_INFO_VIDEOCODEC); + const char *xac = xine_get_meta_info(stream, XINE_META_INFO_AUDIOCODEC); + if(!equals(video_codec, xvc) || !equals(audio_codec, xac)) + { + MutexLock lock(mutex); + video_codec = (xvc ? xvc : string()); + audio_codec = (xac ? xac : string()); + signal_codecs_changed.emit(video_codec, audio_codec); + } + int dur_msec, pos_msec; xine_get_pos_length(stream, 0, &pos_msec, &dur_msec); Time::TimeDelta dur = dur_msec*Time::msec; diff --git a/source/xinestream.h b/source/xinestream.h index 554b448..01cc3e0 100644 --- a/source/xinestream.h +++ b/source/xinestream.h @@ -29,6 +29,9 @@ public: sigc::signal signal_title_changed; sigc::signal signal_duration_changed; sigc::signal signal_position_changed; + sigc::signal signal_video_size_changed; + sigc::signal signal_framerate_changed; + sigc::signal signal_codecs_changed; sigc::signal signal_channels_changed; sigc::signal signal_current_audio_channel_changed; sigc::signal signal_current_spu_channel_changed; @@ -44,6 +47,11 @@ private: std::string title; Msp::Time::TimeDelta duration; Msp::Time::TimeDelta position; + unsigned video_width; + unsigned video_height; + float framerate; + std::string video_codec; + std::string audio_codec; std::vector audio_channels; std::vector spu_channels; int current_audio; @@ -59,6 +67,11 @@ public: const Msp::Time::TimeDelta &get_duration() const { return duration; } const Msp::Time::TimeDelta &get_position() const { return position; } const std::string &get_title() const; + unsigned get_video_width() const { return video_width; } + unsigned get_video_height() const { return video_height; } + float get_framerate() const { return framerate; } + const std::string &get_video_codec() const { return video_codec; } + const std::string &get_audio_codec() const { return audio_codec; } void play(); void seek(const Msp::Time::TimeDelta &); @@ -77,6 +90,7 @@ public: void tick(); private: + static bool equals(const std::string &, const char *); void update_info(); void update_channels(); void handle_event(const xine_event_t &);