[matroska] r1256 - trunk/foo_input_matroska
[email protected] Mon, 17 Jul 2006 10:47:00 +0400 (MSD)
| Newsgroups | gmane.comp.multimedia.matroska.cvs |
|---|---|
| Message-ID | <[email protected]> |
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
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- 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 {
=20
namespace matroska {
- class NOVTABLE attachment {
- public:
- virtual ~attachment() {};
- virtual void get_name(pfc::string_base & p_out)=3D0;
- virtual void get_mime_type(pfc::string_base & p_out)=3D0;
- virtual void get_description(pfc::string_base & p_out)=3D0;
- virtual t_size get_size()=3D0;
- virtual t_sfilesize get_position()=3D0;
- virtual void get(void * p_buffer, t_size p_size =3D 0)=3D0;
- virtual void get(void * p_buffer, t_sfilesize p_position, t_=
size p_size)=3D0;
- };
+ class attachment;
=20
- typedef pfc::ptr_list_t<attachment> attachment_list_t;
- };
-
+ typedef pfc::list_base_const_t<attachment> attachment_list;
+ }
+ =20
class NOVTABLE container_matroska : public service_base {
public:
- virtual void open(service_ptr_t<container_matroska> & p_out, ser=
vice_ptr_t<file> & p_file, bool p_info_only, abort_callback & p_abort)=3D=
0;
- virtual matroska::attachment_list_t & get_attachment_list()=3D0;
+ virtual void open(const char * p_path, bool p_info_only, abort_c=
allback & p_abort)=3D0;
+ virtual void open_file(service_ptr_t<file> & p_out, const filesy=
stem::t_open_mode p_mode =3D filesystem::open_mode_read) const =3D0;
+ virtual void get_display_path(pfc::string_base & p_out) const =3D=
0;
+ virtual bool is_our_path(const char * p_path) const =3D0;
+ virtual const matroska::attachment_list * get_attachment_list() =
const =3D0;
+
public:
- static void g_open(service_ptr_t<container_matroska> & p_out, se=
rvice_ptr_t<file> & p_file, bool p_info_only, abort_callback & p_abort) {
+ static void g_open(service_ptr_t<container_matroska> & p_out, co=
nst 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 =3D 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;
+ }
=20
FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(container_matroska);
};
=20
+ 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_cal=
lback & 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_descriptio=
n(p_description), m_size(p_size), m_position(p_position)
+ {
+ m_owner =3D p_owner.get_ptr();
+ m_abort =3D &p_abort;
+ };
+ ~attachment() {};
+ void get_name(pfc::string_base & p_out) const { p_out =3D m_=
name; };
+ void get_mime_type(pfc::string_base & p_out) const { p_out =3D=
m_mime_type; };
+ void get_description(pfc::string_base & p_out) const { p_out=
=3D 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_s=
ize) 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 =3D 0) const {
+ if (!p_size) {
+ p_size =3D get_size();
+ }
+ get(p_buffer, get_position(), p_size);
+ };
+ };
+ };
+
};
=20
+using namespace foobar2000_io;
+
template<typename T>
class container_matroska_factory_t : public service_factory_t<T> {};
=20
Modified: trunk/foo_input_matroska/container_matroska_impl.cpp
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- 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"
=20
/**
- * matroska::attachment
+ * container_matroska
*/
=20
-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 =3D p_path;
m_abort =3D &p_abort;
- m_attachment =3D p_attachment;
- console::info("construct");
-}
-
-void matroska::attachment_impl::get_name(pfc::string_base & p_out) {
- p_out =3D m_attachment.FileName.GetUTF8().c_str();
-}
-
-void matroska::attachment_impl::get_mime_type(pfc::string_base & p_out) =
{
- p_out =3D m_attachment.MimeType.c_str();
-}
-
-void matroska::attachment_impl::get_description(pfc::string_base & p_out=
) {
- p_out =3D 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 =3D get_size();
+ service_ptr_t<file> file_ptr;
+ try {
+ filesystem::g_open_read(file_ptr, m_path, *m_abort);
+ matroska_parser_ptr_t parser =3D matroska_parser_ptr_t(new Matro=
skaAudioParser(file_ptr, *m_abort));
+ parser->Parse(p_info_only);
+ for (t_size i =3D 0; i !=3D parser->GetAttachmentList().get_coun=
t(); ++i) {
+ MatroskaAttachment & item =3D parser->GetAttachmentList().ge=
t_item(i);
+ matroska::attachment attachment(this, *m_abort, item.FileNam=
e.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);
}
=20
-void matroska::attachment_impl::get(void * p_buffer, t_sfilesize p_posit=
ion, 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, con=
st filesystem::t_open_mode p_mode) const {
+ filesystem::g_open(p_out, m_path, p_mode, *m_abort);
}
=20
-/**
- * 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::abor=
t_callback &p_abort) {
- m_attachment_list.delete_all();
- matroska_parser_ptr_t parser =3D matroska_parser_ptr_t(new MatroskaA=
udioParser(p_file, p_abort));
- parser->Parse(p_info_only);
- for (t_size i =3D 0; i !=3D parser->GetAttachmentList().get_count();=
++i) {
- matroska::attachment * attachment =3D new matroska::attachment_i=
mpl(p_file, parser->GetAttachmentList().get_item(i), p_abort);
- m_attachment_list.add_item(attachment);
- }
- p_out =3D this;
+void container_matroska_impl::get_display_path(pfc::string_base & p_out)=
const {
+ p_out =3D m_path;
}
=20
-matroska::attachment_list_t & container_matroska_impl::get_attachment_li=
st() {
- return m_attachment_list;
-}
\ No newline at end of file
+const matroska::attachment_list * container_matroska_impl::get_attachmen=
t_list() const {
+ return reinterpret_cast<const matroska::attachment_list *>(&m_attach=
ment_list);
+}
Modified: trunk/foo_input_matroska/container_matroska_impl.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/foo_input_matroska/container_matroska_impl.h 2006-07-13 15:47:4=
2 UTC (rev 1255)
+++ trunk/foo_input_matroska/container_matroska_impl.h 2006-07-17 06:46:5=
5 UTC (rev 1256)
@@ -4,46 +4,40 @@
#include "matroska_parser.h"
#include "container_matroska.h"
=20
-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 Matroska=
Attachment 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 =3D 0);
- virtual void get(void * p_buffer, t_sfilesize p_position, t_=
size p_size);
- };
-
- typedef pfc::ptr_list_t<matroska::attachment_impl> attachment_im=
pl_list_t;
- };
-};
-
typedef boost::shared_ptr<MatroskaAudioParser> matroska_parser_ptr_t;
=20
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_callb=
ack & p_abort);
+ virtual void open_file(service_ptr_t<file> & p_out, const filesystem=
::t_open_mode p_mode =3D 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") !=3D 0 &&=
stricmp_utf8(pfc::string_extension(p_path), "mkv") !=3D 0) {
+ return false;
+ }
+ return true;
+ }
+ virtual const matroska::attachment_list * get_attachment_list() cons=
t;
};
=20
static container_matroska_factory_t<container_matroska_impl> g_container=
_matroska_impl_factory;