[vlc-commits] [Git][videolan/vlc][master] chromecast: Add duration for streams

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Thu Mar 26 12:24:26 UTC 2026



Felix Paul Kühne pushed to branch master at VideoLAN / VLC


Commits:
de592342 by Dave Nicolson at 2026-03-26T12:37:21+01:00
chromecast: Add duration for streams

- - - - -


5 changed files:

- modules/stream_out/chromecast/chromecast.h
- modules/stream_out/chromecast/chromecast_common.h
- modules/stream_out/chromecast/chromecast_communication.cpp
- modules/stream_out/chromecast/chromecast_ctrl.cpp
- modules/stream_out/chromecast/chromecast_demux.cpp


Changes:

=====================================
modules/stream_out/chromecast/chromecast.h
=====================================
@@ -122,7 +122,7 @@ public:
     unsigned msgReceiverClose(const std::string& destinationId);
     unsigned msgAuth();
     unsigned msgPlayerLoad( const std::string& destinationId,
-                            const std::string& mime, const vlc_meta_t *p_meta );
+                            const std::string& mime, const vlc_meta_t *p_meta, vlc_tick_t input_length );
     unsigned msgPlayerPlay( const std::string& destinationId, int64_t mediaSessionId );
     unsigned msgPlayerStop( const std::string& destinationId, int64_t mediaSessionId );
     unsigned msgPlayerPause( const std::string& destinationId, int64_t mediaSessionId );
@@ -145,7 +145,7 @@ private:
                      const std::string & destinationId = DEFAULT_CHOMECAST_RECEIVER,
                      castchannel::CastMessage_PayloadType payloadType = castchannel::CastMessage_PayloadType_STRING);
     int pushMediaPlayerMessage( const std::string& destinationId, const std::stringstream & payload );
-    std::string GetMedia( const std::string& mime, const vlc_meta_t *p_meta );
+    std::string GetMedia( const std::string& mime, const vlc_meta_t *p_meta, vlc_tick_t input_length );
     unsigned getNextReceiverRequestId();
     unsigned getNextRequestId();
 
@@ -211,6 +211,7 @@ private:
     void doStop();
 
     void setMeta( vlc_meta_t *p_meta );
+    void setInputLength( vlc_tick_t length );
 
     vlc_tick_t getPlaybackTimestamp();
 
@@ -240,6 +241,7 @@ private:
     static void set_pause_state(void*, bool paused);
 
     static void set_meta(void*, vlc_meta_t *p_meta);
+    static void set_input_length(void*, vlc_tick_t length);
 
     void prepareHttpArtwork();
 
@@ -277,6 +279,7 @@ private:
     bool m_request_stop;
     bool m_request_load;
     bool m_paused;
+    vlc_tick_t m_input_length;
     bool m_input_eof;
     bool m_cc_eof;
     bool m_pace;


=====================================
modules/stream_out/chromecast/chromecast_common.h
=====================================
@@ -70,6 +70,8 @@ typedef struct
 
     void (*pf_set_meta)(void*, vlc_meta_t *p_meta);
 
+    void (*pf_set_input_length)(void*, vlc_tick_t length);
+
 } chromecast_common;
 
 # ifdef __cplusplus


=====================================
modules/stream_out/chromecast/chromecast_communication.cpp
=====================================
@@ -284,7 +284,8 @@ static std::string meta_get_escaped(const vlc_meta_t *p_meta, vlc_meta_type_t ty
 }
 
 std::string ChromecastCommunication::GetMedia( const std::string& mime,
-                                               const vlc_meta_t *p_meta )
+                                               const vlc_meta_t *p_meta,
+                                               vlc_tick_t input_length )
 {
     std::stringstream ss;
 
@@ -350,19 +351,28 @@ std::string ChromecastCommunication::GetMedia( const std::string& mime,
     msg_Dbg( m_module, "s_chromecast_url: %s", chromecast_url.str().c_str());
 
     ss << "\"contentId\":\"" << chromecast_url.str() << "\""
-       << ",\"streamType\":\"LIVE\""
+       << ",\"streamType\":\"" << ( input_length > VLC_TICK_0 ? "BUFFERED" : "LIVE" ) << "\""
        << ",\"contentType\":\"" << mime << "\"";
+       
+
+    if( input_length > VLC_TICK_0 )
+    {
+        std::stringstream duration;
+        duration.setf( std::ios_base::fixed, std::ios_base::floatfield );
+        duration << std::setprecision(6) << secf_from_vlc_tick(input_length);
+        ss << ",\"duration\":" << duration.str();
+    }
 
     return ss.str();
 }
 
 unsigned ChromecastCommunication::msgPlayerLoad( const std::string& destinationId,
-                                             const std::string& mime, const vlc_meta_t *p_meta )
+                                             const std::string& mime, const vlc_meta_t *p_meta, vlc_tick_t input_length )
 {
     unsigned id = getNextRequestId();
     std::stringstream ss;
     ss << "{\"type\":\"LOAD\","
-       <<  "\"media\":{" << GetMedia( mime, p_meta ) << "},"
+       <<  "\"media\":{" << GetMedia( mime, p_meta, input_length ) << "},"
        <<  "\"autoplay\":\"false\","
        <<  "\"requestId\":" << id
        << "}";


=====================================
modules/stream_out/chromecast/chromecast_ctrl.cpp
=====================================
@@ -144,6 +144,7 @@ intf_sys_t::intf_sys_t(vlc_object_t * const p_this, int port, std::string device
  , m_request_stop( false )
  , m_request_load( false )
  , m_paused( false )
+ , m_input_length( VLC_TICK_INVALID )
  , m_input_eof( false )
  , m_cc_eof( false )
  , m_pace( false )
@@ -182,6 +183,7 @@ intf_sys_t::intf_sys_t(vlc_object_t * const p_this, int port, std::string device
     m_common.pf_send_input_event = send_input_event;
     m_common.pf_set_pause_state  = set_pause_state;
     m_common.pf_set_meta         = set_meta;
+    m_common.pf_set_input_length = set_input_length;
 
     assert( var_Type( vlc_object_parent(vlc_object_parent(m_module)), CC_SHARED_VAR_NAME) == 0 );
     if (var_Create( vlc_object_parent(vlc_object_parent(m_module)), CC_SHARED_VAR_NAME, VLC_VAR_ADDRESS ) == VLC_SUCCESS )
@@ -406,7 +408,7 @@ void intf_sys_t::tryLoad()
     // Reset the mediaSessionID to allow the new session to become the current one.
     // we cannot start a new load when the last one is still processing
     m_last_request_id =
-        m_communication->msgPlayerLoad( m_appTransportId, m_mime, m_meta );
+        m_communication->msgPlayerLoad( m_appTransportId, m_mime, m_meta, m_input_length );
     if( m_last_request_id != ChromecastCommunication::kInvalidId )
         m_state = Loading;
 }
@@ -1232,6 +1234,12 @@ void intf_sys_t::setMeta(vlc_meta_t *p_meta)
     m_meta = p_meta;
 }
 
+void intf_sys_t::setInputLength(vlc_tick_t length)
+{
+    vlc::threads::mutex_locker lock( m_lock );
+    m_input_length = length;
+}
+
 vlc_tick_t intf_sys_t::getPlaybackTimestamp()
 {
     vlc::threads::mutex_locker lock( m_lock );
@@ -1329,3 +1337,9 @@ void intf_sys_t::set_meta(void *pt, vlc_meta_t *p_meta)
     intf_sys_t *p_this = static_cast<intf_sys_t*>(pt);
     p_this->setMeta( p_meta );
 }
+
+void intf_sys_t::set_input_length(void *pt, vlc_tick_t length)
+{
+    intf_sys_t *p_this = static_cast<intf_sys_t*>(pt);
+    p_this->setInputLength( length );
+}


=====================================
modules/stream_out/chromecast/chromecast_demux.cpp
=====================================
@@ -91,6 +91,7 @@ struct demux_cc
             m_can_seek = false;
         if (demux_Control( p_demux->s, DEMUX_GET_LENGTH, &m_length ) != VLC_SUCCESS)
             m_length = -1;
+        p_renderer->pf_set_input_length( p_renderer->p_opaque, m_length );
 
         int i_current_title;
         if( demux_Control( p_demux->s, DEMUX_GET_TITLE,
@@ -141,6 +142,7 @@ struct demux_cc
     {
         assert(p_renderer);
         p_renderer->pf_set_meta( p_renderer->p_opaque, NULL );
+        p_renderer->pf_set_input_length( p_renderer->p_opaque, VLC_TICK_INVALID );
         p_renderer->pf_set_demux_enabled(p_renderer->p_opaque, false, NULL, NULL);
     }
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/de592342d31900eb9c85de97ad1feb5879f718fc

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/de592342d31900eb9c85de97ad1feb5879f718fc
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list