Changing IMkvReadableWriter to IMkvWriteEOFReader
Changing the IMkvReadableWriter interface to IMkvWriteEOFReader. Also changing the default implementation. Change-Id: Id37ffd7ef0af2ff7a392fb4fb0b1b134664ab20f
This commit is contained in:
parent
74e5f0fa1d
commit
54ca052b1c
2
Makefile
2
Makefile
@ -2,7 +2,7 @@ CXX := g++
|
||||
CXXFLAGS := -W -Wall -g
|
||||
LIBWEBMA := libwebm.a
|
||||
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)
|
||||
OBJSSO := $(WEBMOBJS:.o=_so.o)
|
||||
OBJECTS1 := sample.o
|
||||
|
@ -7,7 +7,7 @@
|
||||
// be found in the AUTHORS file in the root of the source tree.
|
||||
|
||||
#include "mkvmuxer.hpp"
|
||||
#include "mkvreadablewriter.hpp"
|
||||
#include "mkvwriteeofreader.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
@ -91,7 +91,7 @@ bool WriteEbmlHeader(IMkvWriter* writer) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ChunkedCopy(mkvmuxer::IMkvReadableWriter* source,
|
||||
bool ChunkedCopy(mkvmuxer::IMkvWriteEOFReader* source,
|
||||
mkvmuxer::IMkvWriter* dst,
|
||||
mkvmuxer::int64 start, int64 size) {
|
||||
// TODO(vigneshv): Check if this is a reasonable value.
|
||||
@ -2091,7 +2091,7 @@ bool Segment::Init(IMkvWriter* ptr_writer) {
|
||||
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_) {
|
||||
return false;
|
||||
}
|
||||
|
23
mkvmuxer.hpp
23
mkvmuxer.hpp
@ -51,11 +51,15 @@ class 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:
|
||||
virtual int Read(long long position, long length,
|
||||
unsigned char* buffer) = 0;
|
||||
virtual int Length(long long* total, long long* available) = 0;
|
||||
// Reads data of size |length| starting from the offset of |position| into
|
||||
// |buffer|.
|
||||
virtual int Read(int64 position, int32 length, uint8* buffer) = 0;
|
||||
};
|
||||
|
||||
// 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);
|
||||
|
||||
// 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);
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
@ -943,9 +947,10 @@ class Segment {
|
||||
bool Init(IMkvWriter* ptr_writer);
|
||||
|
||||
// This function must be called before Init() if Cues are to be written before
|
||||
// the Clusters. Input parameter is a IMkvReadableWriter object which supports
|
||||
// both writing and reading.
|
||||
bool WriteCuesBeforeClusters(IMkvReadableWriter* ptr_writer);
|
||||
// the Clusters. Input parameter is a IMkvWriteEOFReader object, which is to
|
||||
// be used as the temporary storage, while moving the Cues before the
|
||||
// Clusters.
|
||||
bool WriteCuesBeforeClusters(IMkvWriteEOFReader* ptr_writer);
|
||||
|
||||
// Adds a generic track to the segment. Returns the newly-allocated
|
||||
// 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
|
||||
IMkvWriter* writer_;
|
||||
IMkvReadableWriter* writer_temp_;
|
||||
IMkvWriteEOFReader* writer_temp_;
|
||||
|
||||
LIBWEBM_DISALLOW_COPY_AND_ASSIGN(Segment);
|
||||
};
|
||||
|
@ -6,7 +6,7 @@
|
||||
// in the file PATENTS. All contributing project authors may
|
||||
// be found in the AUTHORS file in the root of the source tree.
|
||||
|
||||
#include "mkvreadablewriter.hpp"
|
||||
#include "mkvwriteeofreader.hpp"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <share.h> // for _SH_DENYWR
|
||||
@ -17,15 +17,16 @@
|
||||
|
||||
namespace mkvmuxer {
|
||||
|
||||
MkvReadableWriter::MkvReadableWriter() : file_(NULL) {
|
||||
MkvWriteEOFReader::MkvWriteEOFReader() : file_(NULL),
|
||||
writes_allowed_(true) {
|
||||
}
|
||||
|
||||
MkvReadableWriter::~MkvReadableWriter() {
|
||||
MkvWriteEOFReader::~MkvWriteEOFReader() {
|
||||
Close();
|
||||
}
|
||||
|
||||
int32 MkvReadableWriter::Write(const void* buffer, uint32 length) {
|
||||
if (file_ == NULL)
|
||||
int32 MkvWriteEOFReader::Write(const void* buffer, uint32 length) {
|
||||
if (file_ == NULL || !writes_allowed_)
|
||||
return -1;
|
||||
|
||||
if (length == 0)
|
||||
@ -39,7 +40,7 @@ int32 MkvReadableWriter::Write(const void* buffer, uint32 length) {
|
||||
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)
|
||||
return false;
|
||||
|
||||
@ -56,14 +57,14 @@ bool MkvReadableWriter::Open(const char* filename, bool create_temp_file) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void MkvReadableWriter::Close() {
|
||||
void MkvWriteEOFReader::Close() {
|
||||
if (file_ != NULL) {
|
||||
fclose(file_);
|
||||
file_ = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int64 MkvReadableWriter::Position() const {
|
||||
int64 MkvWriteEOFReader::Position() const {
|
||||
if (file_ == NULL)
|
||||
return 0;
|
||||
|
||||
@ -74,7 +75,7 @@ int64 MkvReadableWriter::Position() const {
|
||||
#endif
|
||||
}
|
||||
|
||||
int32 MkvReadableWriter::Position(int64 position) {
|
||||
int32 MkvWriteEOFReader::Position(int64 position) {
|
||||
if (file_ == NULL)
|
||||
return -1;
|
||||
|
||||
@ -85,20 +86,14 @@ int32 MkvReadableWriter::Position(int64 position) {
|
||||
#endif
|
||||
}
|
||||
|
||||
bool MkvReadableWriter::Seekable() const {
|
||||
bool MkvWriteEOFReader::Seekable() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void MkvReadableWriter::ElementStartNotify(uint64, int64) {
|
||||
void MkvWriteEOFReader::ElementStartNotify(uint64, int64) {
|
||||
}
|
||||
|
||||
int MkvReadableWriter::Length(long long* total, long long* available) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MkvReadableWriter::Read(long long offset,
|
||||
long len,
|
||||
unsigned char* buffer) {
|
||||
int MkvWriteEOFReader::Read(int64 offset, int32 len, uint8* buffer) {
|
||||
if (file_ == NULL)
|
||||
return -1;
|
||||
|
||||
@ -108,6 +103,9 @@ int MkvReadableWriter::Read(long long offset,
|
||||
if (len < 0)
|
||||
return -1;
|
||||
|
||||
if (writes_allowed_)
|
||||
writes_allowed_ = false;
|
||||
|
||||
if (len == 0)
|
||||
return 0;
|
||||
|
@ -6,8 +6,8 @@
|
||||
// in the file PATENTS. All contributing project authors may
|
||||
// be found in the AUTHORS file in the root of the source tree.
|
||||
|
||||
#ifndef MKVREADABLEWRITER_HPP
|
||||
#define MKVREADABLEWRITER_HPP
|
||||
#ifndef MKVWRITEEOFREADER_HPP
|
||||
#define MKVWRITEEOFREADER_HPP
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
@ -16,20 +16,19 @@
|
||||
|
||||
namespace mkvmuxer {
|
||||
|
||||
// Default implementation of the IMkvReadableWriter interface.
|
||||
class MkvReadableWriter : public IMkvReadableWriter {
|
||||
// Default implementation of the IMkvWriteEOFReader interface.
|
||||
class MkvWriteEOFReader : public IMkvWriteEOFReader {
|
||||
public:
|
||||
MkvReadableWriter();
|
||||
virtual ~MkvReadableWriter();
|
||||
MkvWriteEOFReader();
|
||||
virtual ~MkvWriteEOFReader();
|
||||
|
||||
// IMkvReadableWriter interface
|
||||
// IMkvWriteEOFReader interface
|
||||
virtual int64 Position() const;
|
||||
virtual int32 Position(int64 position);
|
||||
virtual bool Seekable() const;
|
||||
virtual int32 Write(const void* buffer, uint32 length);
|
||||
virtual void ElementStartNotify(uint64 element_id, int64 position);
|
||||
virtual int Read(long long position, long length, unsigned char* buffer);
|
||||
virtual int Length(long long* total, long long* available);
|
||||
virtual int Read(int64 position, int32 length, uint8* buffer);
|
||||
|
||||
// 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|.
|
||||
@ -45,9 +44,13 @@ class MkvReadableWriter : public IMkvReadableWriter {
|
||||
// File handle to output 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
|
||||
|
||||
#endif // MKVREADABLEWRITER_HPP
|
||||
#endif // MKVWRITEEOFREADER_HPP
|
@ -18,7 +18,7 @@
|
||||
|
||||
// libwebm muxer includes
|
||||
#include "mkvmuxer.hpp"
|
||||
#include "mkvreadablewriter.hpp"
|
||||
#include "mkvwriteeofreader.hpp"
|
||||
#include "mkvwriter.hpp"
|
||||
#include "mkvmuxerutil.hpp"
|
||||
|
||||
@ -272,7 +272,7 @@ int main(int argc, char* argv[]) {
|
||||
// Set Segment element attributes
|
||||
mkvmuxer::Segment muxer_segment;
|
||||
|
||||
mkvmuxer::MkvReadableWriter writer_temp;
|
||||
mkvmuxer::MkvWriteEOFReader writer_temp;
|
||||
if (cues_before_clusters) {
|
||||
if (!writer_temp.Open(NULL, true)) {
|
||||
printf("\n Filename is invalid or error while opening.\n");
|
||||
|
Loading…
x
Reference in New Issue
Block a user