[vlc-commits] demux:mkv: make the matroska_stream_c own it IOCallback and EbmlStream
Steve Lhomme
git at videolan.org
Thu Jan 25 12:54:21 CET 2018
vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Wed Jan 24 17:11:23 2018 +0100| [b56d6801402b146786fd55f8a061a2dd3d35e115] | committer: Steve Lhomme
demux:mkv: make the matroska_stream_c own it IOCallback and EbmlStream
Now AnalyseAllSegmentsFound() only get a matroska_stream_c and returns if it
can be used or not.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b56d6801402b146786fd55f8a061a2dd3d35e115
---
modules/demux/mkv/demux.cpp | 36 +++++++++++++---------------
modules/demux/mkv/demux.hpp | 2 +-
modules/demux/mkv/mkv.cpp | 40 +++++++++++---------------------
modules/demux/mkv/mkv.hpp | 9 ++++---
modules/demux/mkv/stream_io_callback.hpp | 2 +-
5 files changed, 36 insertions(+), 53 deletions(-)
diff --git a/modules/demux/mkv/demux.cpp b/modules/demux/mkv/demux.cpp
index 7cf139c68b..23f06f55f6 100644
--- a/modules/demux/mkv/demux.cpp
+++ b/modules/demux/mkv/demux.cpp
@@ -449,57 +449,56 @@ demux_sys_t::~demux_sys_t()
}
-matroska_stream_c *demux_sys_t::AnalyseAllSegmentsFound( demux_t *p_demux, EbmlStream *p_estream )
+bool demux_sys_t::AnalyseAllSegmentsFound( demux_t *p_demux, matroska_stream_c *p_stream1 )
{
int i_upper_lvl = 0;
EbmlElement *p_l0;
bool b_keep_stream = false, b_keep_segment = false;
/* verify the EBML Header... it shouldn't be bigger than 1kB */
- p_l0 = p_estream->FindNextID(EBML_INFO(EbmlHead), 1024);
+ p_l0 = p_stream1->estream.FindNextID(EBML_INFO(EbmlHead), 1024);
if (p_l0 == NULL)
{
msg_Err( p_demux, "No EBML header found" );
- return NULL;
+ return false;
}
/* verify we can read this Segment */
try
{
- p_l0->Read(*p_estream, EBML_CLASS_CONTEXT(EbmlHead), i_upper_lvl, p_l0, true);
+ p_l0->Read( p_stream1->estream, EBML_CLASS_CONTEXT(EbmlHead), i_upper_lvl, p_l0, true);
}
catch(...)
{
msg_Err(p_demux, "EBML Header Read failed");
- return NULL;
+ return false;
}
EDocType doc_type = GetChild<EDocType>(*static_cast<EbmlHead*>(p_l0));
if (std::string(doc_type) != "matroska" && std::string(doc_type) != "webm" )
{
msg_Err( p_demux, "Not a Matroska file : DocType = %s ", std::string(doc_type).c_str());
- return NULL;
+ return false;
}
EDocTypeReadVersion doc_read_version = GetChild<EDocTypeReadVersion>(*static_cast<EbmlHead*>(p_l0));
if (uint64(doc_read_version) > 2)
{
msg_Err( p_demux, "matroska file needs version %" PRId64 " but only versions 1 & 2 supported", uint64(doc_read_version));
- return NULL;
+ return false;
}
delete p_l0;
// find all segments in this file
- p_l0 = p_estream->FindNextID(EBML_INFO(KaxSegment), UINT64_MAX);
+ p_l0 = p_stream1->estream.FindNextID(EBML_INFO(KaxSegment), UINT64_MAX);
if (p_l0 == NULL)
{
- return NULL;
+ msg_Err( p_demux, "No segment found" );
+ return false;
}
- matroska_stream_c *p_stream1 = new matroska_stream_c();
-
while (p_l0 != 0)
{
bool b_l0_handled = false;
@@ -507,9 +506,9 @@ matroska_stream_c *demux_sys_t::AnalyseAllSegmentsFound( demux_t *p_demux, EbmlS
if ( MKV_IS_ID( p_l0, KaxSegment) )
{
EbmlParser *ep;
- matroska_segment_c *p_segment1 = new matroska_segment_c( *this, *p_estream );
+ matroska_segment_c *p_segment1 = new matroska_segment_c( *this, p_stream1->estream );
- ep = new EbmlParser(p_estream, p_l0, &demuxer,
+ ep = new EbmlParser(&p_stream1->estream, p_l0, &demuxer,
var_InheritBool( &demuxer, "mkv-use-dummy" ) );
p_segment1->ep = ep;
p_segment1->segment = (KaxSegment*)p_l0;
@@ -539,8 +538,8 @@ matroska_stream_c *demux_sys_t::AnalyseAllSegmentsFound( demux_t *p_demux, EbmlS
if (p_l0->IsFiniteSize() )
{
- p_l0->SkipData(*p_estream, KaxMatroska_Context);
- p_l0 = p_estream->FindNextID(EBML_INFO(KaxSegment), UINT64_MAX);
+ p_l0->SkipData(p_stream1->estream, KaxMatroska_Context);
+ p_l0 = p_stream1->estream.FindNextID(EBML_INFO(KaxSegment), UINT64_MAX);
}
else
{
@@ -552,12 +551,9 @@ matroska_stream_c *demux_sys_t::AnalyseAllSegmentsFound( demux_t *p_demux, EbmlS
}
if ( !b_keep_stream )
- {
- delete p_stream1;
- p_stream1 = NULL;
- }
+ return false;
- return p_stream1;
+ return true;
}
void demux_sys_t::InitUi()
diff --git a/modules/demux/mkv/demux.hpp b/modules/demux/mkv/demux.hpp
index 78f82619f8..0fed033858 100644
--- a/modules/demux/mkv/demux.hpp
+++ b/modules/demux/mkv/demux.hpp
@@ -390,7 +390,7 @@ public:
bool PreloadLinked();
void FreeUnused();
bool PreparePlayback( virtual_segment_c & new_vsegment, mtime_t i_mk_date );
- matroska_stream_c *AnalyseAllSegmentsFound( demux_t *p_demux, EbmlStream *p_estream );
+ bool AnalyseAllSegmentsFound( demux_t *p_demux, matroska_stream_c * );
void JumpTo( virtual_segment_c & vsegment, virtual_chapter_c & vchapter );
void InitUi();
diff --git a/modules/demux/mkv/mkv.cpp b/modules/demux/mkv/mkv.cpp
index f3f17a0fec..093113c125 100644
--- a/modules/demux/mkv/mkv.cpp
+++ b/modules/demux/mkv/mkv.cpp
@@ -96,8 +96,6 @@ static int Open( vlc_object_t * p_this )
matroska_segment_c *p_segment;
const uint8_t *p_peek;
std::string s_path, s_filename;
- vlc_stream_io_callback *p_io_callback;
- EbmlStream *p_io_stream;
bool b_need_preload = false;
/* peek the begining */
@@ -116,29 +114,20 @@ static int Open( vlc_object_t * p_this )
if ( vlc_stream_Control( p_demux->s, STREAM_CAN_FASTSEEK, &p_sys->b_fastseekable ) )
p_sys->b_fastseekable = false;
- p_io_callback = new vlc_stream_io_callback( p_demux->s, false );
- p_io_stream = new (std::nothrow) EbmlStream( *p_io_callback );
-
- if( p_io_stream == NULL )
+ p_stream = new matroska_stream_c( p_demux->s, false );
+ if ( unlikely(p_stream == NULL) )
{
- msg_Err( p_demux, "failed to create EbmlStream" );
- delete p_io_callback;
+ msg_Err( p_demux, "failed to create matroska_stream_c" );
delete p_sys;
- return VLC_EGENERIC;
+ return VLC_ENOMEM;
}
+ p_sys->streams.push_back( p_stream );
- p_stream = p_sys->AnalyseAllSegmentsFound( p_demux, p_io_stream );
- if( p_stream == NULL )
+ if( !p_sys->AnalyseAllSegmentsFound( p_demux, p_stream ) )
{
msg_Err( p_demux, "cannot find KaxSegment or missing mandatory KaxInfo" );
- delete p_io_stream;
- delete p_io_callback;
goto error;
}
- p_sys->streams.push_back( p_stream );
-
- p_stream->p_io_callback = p_io_callback;
- p_stream->p_estream = p_io_stream;
for (size_t i=0; i<p_stream->segments.size(); i++)
{
@@ -216,21 +205,15 @@ static int Open( vlc_object_t * p_this )
if ( file_ok )
{
- vlc_stream_io_callback *p_file_io = new vlc_stream_io_callback( p_file_stream, true );
- EbmlStream *p_estream = new EbmlStream(*p_file_io);
-
- p_stream = p_sys->AnalyseAllSegmentsFound( p_demux, p_estream );
+ matroska_stream_c *p_stream = new matroska_stream_c( p_file_stream, true );
- if ( p_stream == NULL )
+ if ( !p_sys->AnalyseAllSegmentsFound( p_demux, p_stream ) )
{
msg_Dbg( p_demux, "the file '%s' will not be used", s_filename.c_str() );
- delete p_estream;
- delete p_file_io;
+ delete p_stream;
}
else
{
- p_stream->p_io_callback = p_file_io;
- p_stream->p_estream = p_estream;
p_sys->streams.push_back( p_stream );
}
}
@@ -888,3 +871,8 @@ mkv_track_t::~mkv_track_t()
delete p_compression_data;
delete p_sys;
}
+
+matroska_stream_c::matroska_stream_c( stream_t *s, bool owner )
+ :io_callback( new vlc_stream_io_callback( s, owner ) )
+ ,estream( EbmlStream( *io_callback ) )
+{}
diff --git a/modules/demux/mkv/mkv.hpp b/modules/demux/mkv/mkv.hpp
index b3b175d9b4..2b04d08066 100644
--- a/modules/demux/mkv/mkv.hpp
+++ b/modules/demux/mkv/mkv.hpp
@@ -156,15 +156,14 @@ private:
class matroska_segment_c;
struct matroska_stream_c
{
- matroska_stream_c() :p_io_callback(NULL) ,p_estream(NULL) {}
+ matroska_stream_c(stream_t *s, bool owner);
~matroska_stream_c()
{
- delete p_io_callback;
- delete p_estream;
+ delete io_callback;
}
- IOCallback *p_io_callback;
- EbmlStream *p_estream;
+ IOCallback * io_callback;
+ EbmlStream estream;
std::vector<matroska_segment_c*> segments;
};
diff --git a/modules/demux/mkv/stream_io_callback.hpp b/modules/demux/mkv/stream_io_callback.hpp
index 6b9c442c6d..d2c72a4214 100644
--- a/modules/demux/mkv/stream_io_callback.hpp
+++ b/modules/demux/mkv/stream_io_callback.hpp
@@ -34,7 +34,7 @@ class vlc_stream_io_callback: public IOCallback
bool b_owner;
public:
- vlc_stream_io_callback( stream_t *, bool );
+ vlc_stream_io_callback( stream_t *, bool owner );
virtual ~vlc_stream_io_callback()
{
More information about the vlc-commits
mailing list