[Matroska-cvs] [matroska] r1256 - trunk/foo_input_matroska

ayana at matroska.org ayana at matroska.org
Mon Jul 17 08:47:00 CEST 2006


Author: ayana
Date: 2006-07-17 10:46:55 +0400 (Mon, 17 Jul 2006)
New Revision: 1256

Modified:
   trunk/foo_input_matroska/container_matroska.h
   trunk/foo_input_matroska/container_matroska_impl.cpp
   trunk/foo_input_matroska/container_matroska_impl.h
Log:
change: interface of container_matroska

Modified: trunk/foo_input_matroska/container_matroska.h
===================================================================
--- trunk/foo_input_matroska/container_matroska.h	2006-07-13 15:47:42 UTC (rev 1255)
+++ trunk/foo_input_matroska/container_matroska.h	2006-07-17 06:46:55 UTC (rev 1256)
@@ -4,46 +4,91 @@
 namespace foobar2000_io {
 
     namespace matroska {
-        class NOVTABLE attachment {
-        public:
-            virtual ~attachment() {};
-            virtual void get_name(pfc::string_base & p_out)=0;
-            virtual void get_mime_type(pfc::string_base & p_out)=0;
-            virtual void get_description(pfc::string_base & p_out)=0;
-            virtual t_size get_size()=0;
-            virtual t_sfilesize get_position()=0;
-            virtual void get(void * p_buffer, t_size p_size = 0)=0;
-            virtual void get(void * p_buffer, t_sfilesize p_position, t_size p_size)=0;
-        };
+        class attachment;
 
-        typedef pfc::ptr_list_t<attachment> attachment_list_t;
-    };
-
+        typedef pfc::list_base_const_t<attachment> attachment_list;
+    }
+    
     class NOVTABLE container_matroska : public service_base {
     public:
-        virtual void open(service_ptr_t<container_matroska> & p_out, service_ptr_t<file> & p_file, bool p_info_only, abort_callback & p_abort)=0;
-        virtual matroska::attachment_list_t & get_attachment_list()=0;
+        virtual void open(const char * p_path, bool p_info_only, abort_callback & p_abort)=0;
+        virtual void open_file(service_ptr_t<file> & p_out, const filesystem::t_open_mode p_mode = filesystem::open_mode_read) const =0;
+        virtual void get_display_path(pfc::string_base & p_out) const =0;
+        virtual bool is_our_path(const char * p_path) const =0;
+        virtual const matroska::attachment_list * get_attachment_list() const =0;
+
     public:
-        static void g_open(service_ptr_t<container_matroska> & p_out, service_ptr_t<file> & p_file, bool p_info_only, abort_callback & p_abort) {
+        static void g_open(service_ptr_t<container_matroska> & p_out, const char * p_path, bool p_info_only, abort_callback & p_abort) {
             service_enum_t<container_matroska> e;
             service_ptr_t<container_matroska> ptr;
-            if (e.first(ptr)) {
-                do {
-                    p_file->reopen(p_abort);
-		            try {
-			            ptr->open(p_out, p_file, p_info_only, p_abort);
-			            return;
-		            } catch(exception_io_data const &) {}
-	            } while(e.next(ptr));
+            while(e.next(ptr)) {
+                if (ptr->is_our_path(p_path)) {
+		            ptr->open(p_path, p_info_only, p_abort);
+                    p_out = ptr;
+		            return;
+                }
             }
-	        throw exception_io_data();
+	        throw exception_io_unsupported_format();
         }
+        static bool g_is_our_path(const char * p_path) {
+            service_enum_t<container_matroska> e;
+            service_ptr_t<container_matroska> ptr;
+            while(e.next(ptr)) {
+                if (ptr->is_our_path(p_path)) {
+		            return true;
+                }
+            }
+            return false;
+        }
 
         FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(container_matroska);
     };
 
+    typedef service_ptr_t<container_matroska> container_matroska_ptr;
+
+    namespace matroska {
+        class attachment {
+        private:
+            container_matroska * m_owner;
+            abort_callback * m_abort;
+            pfc::string8 m_name, m_mime_type, m_description;
+            t_size m_size;
+            t_sfilesize m_position;
+
+        public:
+            attachment() : m_owner(0), m_abort(0) {};
+            attachment(const container_matroska_ptr & p_owner, abort_callback & p_abort, const char * p_name, const char * p_mime_type,
+                        const char * p_description, const t_size p_size, const t_sfilesize p_position)
+                : m_name(p_name), m_mime_type(p_mime_type), m_description(p_description), m_size(p_size), m_position(p_position)
+            {
+                m_owner = p_owner.get_ptr();
+                m_abort = &p_abort;
+            };
+            ~attachment() {};
+            void get_name(pfc::string_base & p_out) const { p_out = m_name; };
+            void get_mime_type(pfc::string_base & p_out) const { p_out = m_mime_type; };
+            void get_description(pfc::string_base & p_out) const { p_out = m_description; };
+            t_size get_size() const { return m_size; };
+            t_sfilesize get_position() const { return m_position; };
+            void get(void * p_buffer, t_sfilesize p_position, t_size p_size) const {
+                service_ptr_t<file> file_ptr;
+                m_owner->open_file(file_ptr);
+                file_ptr->seek_ex(p_position, file::seek_from_beginning, *m_abort);
+                file_ptr->read(p_buffer, p_size, *m_abort);
+            };
+            void get(void * p_buffer, t_size p_size = 0) const {
+                if (!p_size) {
+                    p_size = get_size();
+                }
+                get(p_buffer, get_position(), p_size);
+            };
+        };
+    };
+
 };
 
+using namespace foobar2000_io;
+
 template<typename T>
 class container_matroska_factory_t : public service_factory_t<T> {};
 

Modified: trunk/foo_input_matroska/container_matroska_impl.cpp
===================================================================
--- trunk/foo_input_matroska/container_matroska_impl.cpp	2006-07-13 15:47:42 UTC (rev 1255)
+++ trunk/foo_input_matroska/container_matroska_impl.cpp	2006-07-17 06:46:55 UTC (rev 1256)
@@ -1,64 +1,40 @@
 #include "container_matroska_impl.h"
 
 /**
- * matroska::attachment
+ * container_matroska
  */
 
-matroska::attachment_impl::attachment_impl(service_ptr_t<file> & p_file, const MatroskaAttachment p_attachment, abort_callback & p_abort)
-: m_file(p_file)
-{
+void container_matroska_impl::open(const char * p_path, bool p_info_only, foobar2000_io::abort_callback &p_abort) {
+    cleanup();
+    if (!is_our_path(p_path)) {
+        throw exception_io_unsupported_format();
+    }
+    m_path = p_path;
     m_abort = &p_abort;
-    m_attachment = p_attachment;
-    console::info("construct");
-}
-
-void matroska::attachment_impl::get_name(pfc::string_base & p_out) {
-    p_out = m_attachment.FileName.GetUTF8().c_str();
-}
-
-void matroska::attachment_impl::get_mime_type(pfc::string_base & p_out) {
-    p_out = m_attachment.MimeType.c_str();
-}
-
-void matroska::attachment_impl::get_description(pfc::string_base & p_out) {
-    p_out = m_attachment.Description.GetUTF8().c_str();
-}
-
-t_size matroska::attachment_impl::get_size() {
-    return static_cast<t_size>(m_attachment.SourceDataLength);
-}
-
-t_sfilesize matroska::attachment_impl::get_position() {
-    return static_cast<t_sfilesize>(m_attachment.SourceStartPos);
-}
-
-void matroska::attachment_impl::get(void * p_buffer, t_size p_size) {
-    if (!p_size) {
-        p_size = get_size();
+    service_ptr_t<file> file_ptr;
+    try {
+        filesystem::g_open_read(file_ptr, m_path, *m_abort);
+        matroska_parser_ptr_t parser = matroska_parser_ptr_t(new MatroskaAudioParser(file_ptr, *m_abort));
+        parser->Parse(p_info_only);
+        for (t_size i = 0; i != parser->GetAttachmentList().get_count(); ++i) {
+            MatroskaAttachment & item = parser->GetAttachmentList().get_item(i);
+            matroska::attachment attachment(this, *m_abort, item.FileName.GetUTF8().c_str(), item.MimeType.c_str(), item.Description.GetUTF8().c_str(),
+                static_cast<t_size>(item.SourceDataLength), static_cast<t_sfilesize>(item.SourceStartPos));
+            m_attachment_list.add_item(attachment);
+        }
+    } catch (...) {
+        throw exception_io_unsupported_format();
     }
-    get(p_buffer, get_position(), p_size);
 }
 
-void matroska::attachment_impl::get(void * p_buffer, t_sfilesize p_position, t_size p_size) {
-    m_file->seek_ex(p_position, file::seek_from_beginning, *m_abort);
-    m_file->read(p_buffer, p_size, *m_abort);
+void container_matroska_impl::open_file(service_ptr_t<file> & p_out, const filesystem::t_open_mode p_mode) const {
+    filesystem::g_open(p_out, m_path, p_mode, *m_abort);
 }
 
-/**
- * container_matroska
- */
-
-void container_matroska_impl::open(service_ptr_t<container_matroska> & p_out, service_ptr_t<file> & p_file, bool p_info_only, foobar2000_io::abort_callback &p_abort) {
-    m_attachment_list.delete_all();
-    matroska_parser_ptr_t parser = matroska_parser_ptr_t(new MatroskaAudioParser(p_file, p_abort));
-    parser->Parse(p_info_only);
-    for (t_size i = 0; i != parser->GetAttachmentList().get_count(); ++i) {
-        matroska::attachment * attachment = new matroska::attachment_impl(p_file, parser->GetAttachmentList().get_item(i), p_abort);
-        m_attachment_list.add_item(attachment);
-    }
-    p_out = this;
+void container_matroska_impl::get_display_path(pfc::string_base & p_out) const {
+    p_out = m_path;
 }
 
-matroska::attachment_list_t & container_matroska_impl::get_attachment_list() {
-    return m_attachment_list;
-}
\ No newline at end of file
+const matroska::attachment_list * container_matroska_impl::get_attachment_list() const {
+    return reinterpret_cast<const matroska::attachment_list *>(&m_attachment_list);
+}

Modified: trunk/foo_input_matroska/container_matroska_impl.h
===================================================================
--- trunk/foo_input_matroska/container_matroska_impl.h	2006-07-13 15:47:42 UTC (rev 1255)
+++ trunk/foo_input_matroska/container_matroska_impl.h	2006-07-17 06:46:55 UTC (rev 1256)
@@ -4,46 +4,40 @@
 #include "matroska_parser.h"
 #include "container_matroska.h"
 
-namespace foobar2000_io {
-    namespace matroska {
-        class attachment_impl : public attachment
-        {
-        private:
-            service_ptr_t<file> m_file;
-            abort_callback * m_abort;
-            MatroskaAttachment m_attachment;
-        public:
-            attachment_impl(service_ptr_t<file> & p_file, const MatroskaAttachment p_attachment, abort_callback & p_abort);
-            virtual ~attachment_impl() {
-                console::info("destruct");
-            };
-            virtual void get_name(pfc::string_base & p_out);
-            virtual void get_mime_type(pfc::string_base & p_out);
-            virtual void get_description(pfc::string_base & p_out);
-            virtual t_size get_size();
-            virtual t_sfilesize get_position();
-            virtual void get(void * p_buffer, t_size p_size = 0);
-            virtual void get(void * p_buffer, t_sfilesize p_position, t_size p_size);
-        };
-
-        typedef pfc::ptr_list_t<matroska::attachment_impl> attachment_impl_list_t;
-    };
-};
-
 typedef boost::shared_ptr<MatroskaAudioParser> matroska_parser_ptr_t;
 
 class container_matroska_impl : public container_matroska
 {
 private:
-    matroska::attachment_list_t m_attachment_list;
+    typedef pfc::list_t<matroska::attachment> attachment_list_impl;
+
+    abort_callback * m_abort;
+    pfc::string8 m_path;
+    attachment_list_impl m_attachment_list;
+
+    void cleanup() {
+        m_path.reset();
+        m_attachment_list.remove_all();
+    };
+
 protected:
-    container_matroska_impl() {};
+    container_matroska_impl() {
+    };
     ~container_matroska_impl() {
-        m_attachment_list.delete_all();
+        cleanup();
     };
+
 public:
-    virtual void open(service_ptr_t<container_matroska> & p_out, service_ptr_t<file> & p_file, bool p_info_only, abort_callback & p_abort);
-    virtual matroska::attachment_list_t & get_attachment_list();
+    virtual void open(const char * p_path, bool p_info_only, abort_callback & p_abort);
+    virtual void open_file(service_ptr_t<file> & p_out, const filesystem::t_open_mode p_mode = filesystem::open_mode_read) const;
+    virtual void get_display_path(pfc::string_base & p_out) const;
+    virtual bool is_our_path(const char * p_path) const {
+        if (stricmp_utf8(pfc::string_extension(p_path), "mka") != 0 && stricmp_utf8(pfc::string_extension(p_path), "mkv") != 0) {
+            return false;
+        }
+        return true;
+    }
+    virtual const matroska::attachment_list * get_attachment_list() const;
 };
 
 static container_matroska_factory_t<container_matroska_impl> g_container_matroska_impl_factory;



More information about the Matroska-cvs mailing list