[vlc-devel] [PATCH 2/2] taglib: use the stream API on Winstore to read data from files

Steve Lhomme robux4 at gmail.com
Tue Aug 18 08:59:23 CEST 2015


--
replaces https://patches.videolan.org/patch/9666/ and https://patches.videolan.org/patch/9607/
---
 modules/meta_engine/taglib.cpp | 121 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 121 insertions(+)

diff --git a/modules/meta_engine/taglib.cpp b/modules/meta_engine/taglib.cpp
index 01846ef..0e7007b 100644
--- a/modules/meta_engine/taglib.cpp
+++ b/modules/meta_engine/taglib.cpp
@@ -35,6 +35,9 @@
 #include <vlc_url.h>                /* make_path */
 #include <vlc_mime.h>               /* mime type */
 #include <vlc_fs.h>
+#if VLC_WINSTORE_APP
+#include <vlc_access.h>
+#endif
 
 #include <sys/stat.h>
 
@@ -59,6 +62,9 @@
 #include <fileref.h>
 #include <tag.h>
 #include <tbytevector.h>
+#if VLC_WINSTORE_APP
+#include <tiostream.h>
+#endif
 
 #if TAGLIB_VERSION >= VERSION_INT(1,7,0)
 # define TAGLIB_HAVE_APEFILE_H
@@ -114,6 +120,104 @@ vlc_module_end ()
 
 using namespace TagLib;
 
+#if VLC_WINSTORE_APP
+class VlcIostream : public IOStream
+{
+public:
+    VlcIostream(access_t* p_demux)
+        :  m_demux( p_demux )
+    {
+        vlc_object_hold( m_demux );
+    }
+
+    ~VlcIostream()
+    {
+        vlc_access_Delete( m_demux );
+    }
+
+    FileName name() const
+    {
+        return m_demux->psz_location;
+    }
+
+    ByteVector readBlock(ulong length)
+    {
+        ByteVector res(length, 0);
+        int i_read = vlc_access_Read( m_demux, res.data(), length);
+        if (i_read < 0)
+            return ByteVector::null;;
+        res.resize(i_read);
+        return res;
+    }
+
+    void writeBlock(const ByteVector& data)
+    {
+        // Let's stay Read-Only for now
+        return;
+    }
+
+    void insert(const ByteVector& data, ulong start, ulong replace)
+    {
+        return;
+    }
+
+    void removeBlock(ulong start, ulong length)
+    {
+        return;
+    }
+
+    bool readOnly() const
+    {
+        return true;
+    }
+
+    bool isOpen() const
+    {
+        return true;
+    }
+
+    void seek(long offset, Position p)
+    {
+        uint64_t pos = 0;
+        switch (p)
+        {
+            case Current:
+                pos = vlc_access_Tell( m_demux );
+                break;
+            case End:
+                pos = access_GetSize( m_demux );
+                break;
+            default:
+                break;
+        }
+        vlc_access_Seek( m_demux, pos + offset );
+    }
+
+    void clear()
+    {
+        return;
+    }
+
+    long tell() const
+    {
+        return vlc_access_Tell( m_demux );
+    }
+
+    long length()
+    {
+        return access_GetSize( m_demux );
+    }
+
+    void truncate(long length)
+    {
+        return;
+    }
+
+private:
+    access_t* m_demux;
+};
+#endif /* VLC_WINSTORE_APP */
+
 static void ExtractTrackNumberValues( vlc_meta_t* p_meta, const char *psz_value )
 {
     unsigned int i_trknum, i_trktot;
@@ -682,6 +786,22 @@ static int ReadMeta( vlc_object_t* p_this)
         return VLC_ENOMEM;
 
     char *psz_path = make_path( psz_uri );
+#if VLC_WINSTORE_APP
+    if( psz_path == NULL )
+    {
+        free( psz_uri );
+        return VLC_EGENERIC;
+    }
+    free( psz_path );
+
+    access_t *p_access = vlc_access_NewMRL( p_this, psz_uri );
+    free( psz_uri );
+    if( p_access == NULL )
+        return VLC_EGENERIC;
+
+    VlcIostream s( p_access );
+    f = FileRef( &s );
+#else /* VLC_WINSTORE_APP */
     free( psz_uri );
     if( psz_path == NULL )
         return VLC_EGENERIC;
@@ -699,6 +819,7 @@ static int ReadMeta( vlc_object_t* p_this)
     f = FileRef( psz_path );
 #endif
     free( psz_path );
+#endif /* VLC_WINSTORE_APP */
 
     if( f.isNull() )
         return VLC_EGENERIC;
-- 
2.5.0



More information about the vlc-devel mailing list