]> git.tdb.fi Git - xinema.git/commitdiff
Make some auxiliary information about the stream available
authorMikko Rasa <tdb@tdb.fi>
Sun, 18 Oct 2015 11:07:22 +0000 (14:07 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 18 Oct 2015 11:07:22 +0000 (14:07 +0300)
source/client.cpp
source/client.h
source/xinestream.cpp
source/xinestream.h

index 0130846f92c888a6838756a499f33df4357425d8..353694e6d6109f943cd05649c59324ed4ad39af9 100644 (file)
@@ -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();
index d76a9149afc9d6dc4e11fc32a57d889a11f06093..2b12e4d69f9e1bf074a95cf07497b6465a6bf320 100644 (file)
@@ -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);
index 4fc2e88fa1f569bcf2ef811117d2a02eb8bbef11..2d2c058be2cf91f4520175570c0a28fee141b3ca 100644 (file)
@@ -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;
index 554b448aac489ff7ab5b899b7cec8181ac63249a..01cc3e05c3533c1baddde06c6a4dc4998a6aee21 100644 (file)
@@ -29,6 +29,9 @@ public:
        sigc::signal<void, const std::string &> signal_title_changed;
        sigc::signal<void, const Msp::Time::TimeDelta &> signal_duration_changed;
        sigc::signal<void, const Msp::Time::TimeDelta &> signal_position_changed;
+       sigc::signal<void, unsigned, unsigned> signal_video_size_changed;
+       sigc::signal<void, float> signal_framerate_changed;
+       sigc::signal<void, const std::string &, const std::string &> signal_codecs_changed;
        sigc::signal<void> signal_channels_changed;
        sigc::signal<void, int> signal_current_audio_channel_changed;
        sigc::signal<void, int> 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<std::string> audio_channels;
        std::vector<std::string> 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 &);