Changing IMkvReadableWriter to IMkvWriteEOFReader
Changing the IMkvReadableWriter interface to IMkvWriteEOFReader. Also changing the default implementation. Change-Id: Id37ffd7ef0af2ff7a392fb4fb0b1b134664ab20f
This commit is contained in:
2
Makefile
2
Makefile
@@ -2,7 +2,7 @@ CXX := g++
|
|||||||
CXXFLAGS := -W -Wall -g
|
CXXFLAGS := -W -Wall -g
|
||||||
LIBWEBMA := libwebm.a
|
LIBWEBMA := libwebm.a
|
||||||
LIBWEBMSO := libwebm.so
|
LIBWEBMSO := libwebm.so
|
||||||
WEBMOBJS := mkvparser.o mkvreader.o mkvmuxer.o mkvmuxerutil.o mkvwriter.o mkvreadablewriter.o
|
WEBMOBJS := mkvparser.o mkvreader.o mkvmuxer.o mkvmuxerutil.o mkvwriter.o mkvwriteeofreader.o
|
||||||
OBJSA := $(WEBMOBJS:.o=_a.o)
|
OBJSA := $(WEBMOBJS:.o=_a.o)
|
||||||
OBJSSO := $(WEBMOBJS:.o=_so.o)
|
OBJSSO := $(WEBMOBJS:.o=_so.o)
|
||||||
OBJECTS1 := sample.o
|
OBJECTS1 := sample.o
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
// be found in the AUTHORS file in the root of the source tree.
|
// be found in the AUTHORS file in the root of the source tree.
|
||||||
|
|
||||||
#include "mkvmuxer.hpp"
|
#include "mkvmuxer.hpp"
|
||||||
#include "mkvreadablewriter.hpp"
|
#include "mkvwriteeofreader.hpp"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@@ -91,7 +91,7 @@ bool WriteEbmlHeader(IMkvWriter* writer) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ChunkedCopy(mkvmuxer::IMkvReadableWriter* source,
|
bool ChunkedCopy(mkvmuxer::IMkvWriteEOFReader* source,
|
||||||
mkvmuxer::IMkvWriter* dst,
|
mkvmuxer::IMkvWriter* dst,
|
||||||
mkvmuxer::int64 start, int64 size) {
|
mkvmuxer::int64 start, int64 size) {
|
||||||
// TODO(vigneshv): Check if this is a reasonable value.
|
// TODO(vigneshv): Check if this is a reasonable value.
|
||||||
@@ -2091,7 +2091,7 @@ bool Segment::Init(IMkvWriter* ptr_writer) {
|
|||||||
return segment_info_.Init();
|
return segment_info_.Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Segment::WriteCuesBeforeClusters(IMkvReadableWriter* ptr_writer) {
|
bool Segment::WriteCuesBeforeClusters(IMkvWriteEOFReader* ptr_writer) {
|
||||||
if (!ptr_writer || writer_cluster_ || writer_cues_ || writer_header_) {
|
if (!ptr_writer || writer_cluster_ || writer_cues_ || writer_header_) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
23
mkvmuxer.hpp
23
mkvmuxer.hpp
@@ -51,11 +51,15 @@ class IMkvWriter {
|
|||||||
LIBWEBM_DISALLOW_COPY_AND_ASSIGN(IMkvWriter);
|
LIBWEBM_DISALLOW_COPY_AND_ASSIGN(IMkvWriter);
|
||||||
};
|
};
|
||||||
|
|
||||||
class IMkvReadableWriter : public IMkvWriter {
|
// Classes implementing this interface should adhere to the following rule:
|
||||||
|
// - There can be any number of calls to Write().
|
||||||
|
// - Once the first call to Read() occurs, no more Write()'s are allowed.
|
||||||
|
// - Write() should return error if there has been a call to Read() before.
|
||||||
|
class IMkvWriteEOFReader : public IMkvWriter {
|
||||||
public:
|
public:
|
||||||
virtual int Read(long long position, long length,
|
// Reads data of size |length| starting from the offset of |position| into
|
||||||
unsigned char* buffer) = 0;
|
// |buffer|.
|
||||||
virtual int Length(long long* total, long long* available) = 0;
|
virtual int Read(int64 position, int32 length, uint8* buffer) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Writes out the EBML header for a WebM file. This function must be called
|
// Writes out the EBML header for a WebM file. This function must be called
|
||||||
@@ -63,7 +67,7 @@ class IMkvReadableWriter : public IMkvWriter {
|
|||||||
bool WriteEbmlHeader(IMkvWriter* writer);
|
bool WriteEbmlHeader(IMkvWriter* writer);
|
||||||
|
|
||||||
// Copies in Chunk from source to destination between the given byte positions
|
// Copies in Chunk from source to destination between the given byte positions
|
||||||
bool ChunkedCopy(IMkvReadableWriter* source, IMkvWriter* dst,
|
bool ChunkedCopy(IMkvWriteEOFReader* source, IMkvWriter* dst,
|
||||||
int64 start, int64 size);
|
int64 start, int64 size);
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////
|
||||||
@@ -943,9 +947,10 @@ class Segment {
|
|||||||
bool Init(IMkvWriter* ptr_writer);
|
bool Init(IMkvWriter* ptr_writer);
|
||||||
|
|
||||||
// This function must be called before Init() if Cues are to be written before
|
// This function must be called before Init() if Cues are to be written before
|
||||||
// the Clusters. Input parameter is a IMkvReadableWriter object which supports
|
// the Clusters. Input parameter is a IMkvWriteEOFReader object, which is to
|
||||||
// both writing and reading.
|
// be used as the temporary storage, while moving the Cues before the
|
||||||
bool WriteCuesBeforeClusters(IMkvReadableWriter* ptr_writer);
|
// Clusters.
|
||||||
|
bool WriteCuesBeforeClusters(IMkvWriteEOFReader* ptr_writer);
|
||||||
|
|
||||||
// Adds a generic track to the segment. Returns the newly-allocated
|
// Adds a generic track to the segment. Returns the newly-allocated
|
||||||
// track object (which is owned by the segment) on success, NULL on
|
// track object (which is owned by the segment) on success, NULL on
|
||||||
@@ -1249,7 +1254,7 @@ class Segment {
|
|||||||
|
|
||||||
// Pointer to actual writer object and temp writer object
|
// Pointer to actual writer object and temp writer object
|
||||||
IMkvWriter* writer_;
|
IMkvWriter* writer_;
|
||||||
IMkvReadableWriter* writer_temp_;
|
IMkvWriteEOFReader* writer_temp_;
|
||||||
|
|
||||||
LIBWEBM_DISALLOW_COPY_AND_ASSIGN(Segment);
|
LIBWEBM_DISALLOW_COPY_AND_ASSIGN(Segment);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
// in the file PATENTS. All contributing project authors may
|
// in the file PATENTS. All contributing project authors may
|
||||||
// be found in the AUTHORS file in the root of the source tree.
|
// be found in the AUTHORS file in the root of the source tree.
|
||||||
|
|
||||||
#include "mkvreadablewriter.hpp"
|
#include "mkvwriteeofreader.hpp"
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#include <share.h> // for _SH_DENYWR
|
#include <share.h> // for _SH_DENYWR
|
||||||
@@ -17,15 +17,16 @@
|
|||||||
|
|
||||||
namespace mkvmuxer {
|
namespace mkvmuxer {
|
||||||
|
|
||||||
MkvReadableWriter::MkvReadableWriter() : file_(NULL) {
|
MkvWriteEOFReader::MkvWriteEOFReader() : file_(NULL),
|
||||||
|
writes_allowed_(true) {
|
||||||
}
|
}
|
||||||
|
|
||||||
MkvReadableWriter::~MkvReadableWriter() {
|
MkvWriteEOFReader::~MkvWriteEOFReader() {
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 MkvReadableWriter::Write(const void* buffer, uint32 length) {
|
int32 MkvWriteEOFReader::Write(const void* buffer, uint32 length) {
|
||||||
if (file_ == NULL)
|
if (file_ == NULL || !writes_allowed_)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (length == 0)
|
if (length == 0)
|
||||||
@@ -39,7 +40,7 @@ int32 MkvReadableWriter::Write(const void* buffer, uint32 length) {
|
|||||||
return (bytes_written == length) ? 0 : -1;
|
return (bytes_written == length) ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MkvReadableWriter::Open(const char* filename, bool create_temp_file) {
|
bool MkvWriteEOFReader::Open(const char* filename, bool create_temp_file) {
|
||||||
if (filename == NULL && !create_temp_file)
|
if (filename == NULL && !create_temp_file)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -56,14 +57,14 @@ bool MkvReadableWriter::Open(const char* filename, bool create_temp_file) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MkvReadableWriter::Close() {
|
void MkvWriteEOFReader::Close() {
|
||||||
if (file_ != NULL) {
|
if (file_ != NULL) {
|
||||||
fclose(file_);
|
fclose(file_);
|
||||||
file_ = NULL;
|
file_ = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int64 MkvReadableWriter::Position() const {
|
int64 MkvWriteEOFReader::Position() const {
|
||||||
if (file_ == NULL)
|
if (file_ == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@@ -74,7 +75,7 @@ int64 MkvReadableWriter::Position() const {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 MkvReadableWriter::Position(int64 position) {
|
int32 MkvWriteEOFReader::Position(int64 position) {
|
||||||
if (file_ == NULL)
|
if (file_ == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@@ -85,20 +86,14 @@ int32 MkvReadableWriter::Position(int64 position) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MkvReadableWriter::Seekable() const {
|
bool MkvWriteEOFReader::Seekable() const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MkvReadableWriter::ElementStartNotify(uint64, int64) {
|
void MkvWriteEOFReader::ElementStartNotify(uint64, int64) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int MkvReadableWriter::Length(long long* total, long long* available) {
|
int MkvWriteEOFReader::Read(int64 offset, int32 len, uint8* buffer) {
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int MkvReadableWriter::Read(long long offset,
|
|
||||||
long len,
|
|
||||||
unsigned char* buffer) {
|
|
||||||
if (file_ == NULL)
|
if (file_ == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@@ -108,6 +103,9 @@ int MkvReadableWriter::Read(long long offset,
|
|||||||
if (len < 0)
|
if (len < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
if (writes_allowed_)
|
||||||
|
writes_allowed_ = false;
|
||||||
|
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@@ -6,8 +6,8 @@
|
|||||||
// in the file PATENTS. All contributing project authors may
|
// in the file PATENTS. All contributing project authors may
|
||||||
// be found in the AUTHORS file in the root of the source tree.
|
// be found in the AUTHORS file in the root of the source tree.
|
||||||
|
|
||||||
#ifndef MKVREADABLEWRITER_HPP
|
#ifndef MKVWRITEEOFREADER_HPP
|
||||||
#define MKVREADABLEWRITER_HPP
|
#define MKVWRITEEOFREADER_HPP
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
@@ -16,20 +16,19 @@
|
|||||||
|
|
||||||
namespace mkvmuxer {
|
namespace mkvmuxer {
|
||||||
|
|
||||||
// Default implementation of the IMkvReadableWriter interface.
|
// Default implementation of the IMkvWriteEOFReader interface.
|
||||||
class MkvReadableWriter : public IMkvReadableWriter {
|
class MkvWriteEOFReader : public IMkvWriteEOFReader {
|
||||||
public:
|
public:
|
||||||
MkvReadableWriter();
|
MkvWriteEOFReader();
|
||||||
virtual ~MkvReadableWriter();
|
virtual ~MkvWriteEOFReader();
|
||||||
|
|
||||||
// IMkvReadableWriter interface
|
// IMkvWriteEOFReader interface
|
||||||
virtual int64 Position() const;
|
virtual int64 Position() const;
|
||||||
virtual int32 Position(int64 position);
|
virtual int32 Position(int64 position);
|
||||||
virtual bool Seekable() const;
|
virtual bool Seekable() const;
|
||||||
virtual int32 Write(const void* buffer, uint32 length);
|
virtual int32 Write(const void* buffer, uint32 length);
|
||||||
virtual void ElementStartNotify(uint64 element_id, int64 position);
|
virtual void ElementStartNotify(uint64 element_id, int64 position);
|
||||||
virtual int Read(long long position, long length, unsigned char* buffer);
|
virtual int Read(int64 position, int32 length, uint8* buffer);
|
||||||
virtual int Length(long long* total, long long* available);
|
|
||||||
|
|
||||||
// Creates and opens a file for reading and writing. |filename| is the name of
|
// Creates and opens a file for reading and writing. |filename| is the name of
|
||||||
// the file to open. This function will overwrite the contents of |filename|.
|
// the file to open. This function will overwrite the contents of |filename|.
|
||||||
@@ -45,9 +44,13 @@ class MkvReadableWriter : public IMkvReadableWriter {
|
|||||||
// File handle to output file.
|
// File handle to output file.
|
||||||
FILE* file_;
|
FILE* file_;
|
||||||
|
|
||||||
LIBWEBM_DISALLOW_COPY_AND_ASSIGN(MkvReadableWriter);
|
// Flag indicating if writes are allowed. Will be set to false on first call
|
||||||
|
// to Read().
|
||||||
|
bool writes_allowed_;
|
||||||
|
|
||||||
|
LIBWEBM_DISALLOW_COPY_AND_ASSIGN(MkvWriteEOFReader);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace mkvmuxer
|
} // end namespace mkvmuxer
|
||||||
|
|
||||||
#endif // MKVREADABLEWRITER_HPP
|
#endif // MKVWRITEEOFREADER_HPP
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
// libwebm muxer includes
|
// libwebm muxer includes
|
||||||
#include "mkvmuxer.hpp"
|
#include "mkvmuxer.hpp"
|
||||||
#include "mkvreadablewriter.hpp"
|
#include "mkvwriteeofreader.hpp"
|
||||||
#include "mkvwriter.hpp"
|
#include "mkvwriter.hpp"
|
||||||
#include "mkvmuxerutil.hpp"
|
#include "mkvmuxerutil.hpp"
|
||||||
|
|
||||||
@@ -272,7 +272,7 @@ int main(int argc, char* argv[]) {
|
|||||||
// Set Segment element attributes
|
// Set Segment element attributes
|
||||||
mkvmuxer::Segment muxer_segment;
|
mkvmuxer::Segment muxer_segment;
|
||||||
|
|
||||||
mkvmuxer::MkvReadableWriter writer_temp;
|
mkvmuxer::MkvWriteEOFReader writer_temp;
|
||||||
if (cues_before_clusters) {
|
if (cues_before_clusters) {
|
||||||
if (!writer_temp.Open(NULL, true)) {
|
if (!writer_temp.Open(NULL, true)) {
|
||||||
printf("\n Filename is invalid or error while opening.\n");
|
printf("\n Filename is invalid or error while opening.\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user