7 #include "packager/media/formats/webm/mkv_writer.h"
12 MkvWriter::MkvWriter() : position_(0) {}
14 MkvWriter::~MkvWriter() {}
16 Status MkvWriter::Open(
const std::string& name) {
18 file_.reset(File::Open(name.c_str(),
"w"));
20 return Status(error::FILE_FAILURE,
"Unable to open file for writing.");
24 seekable_ = file_->Seek(0);
30 const std::string file_name = file_->file_name();
31 if (!file_.release()->Close()) {
34 "Cannot close file " + file_name +
35 ", possibly file permission issue or running out of disk space.");
40 mkvmuxer::int32 MkvWriter::Write(
const void* buf, mkvmuxer::uint32 len) {
43 const char* data =
reinterpret_cast<const char*
>(buf);
44 int64_t total_bytes_written = 0;
45 while (total_bytes_written < len) {
46 const int64_t written =
47 file_->Write(data + total_bytes_written, len - total_bytes_written);
51 total_bytes_written += written;
54 DCHECK_EQ(total_bytes_written, len);
59 int64_t MkvWriter::WriteFromFile(
File* source) {
60 return WriteFromFile(source, kWholeFile);
63 int64_t MkvWriter::WriteFromFile(
File* source, int64_t max_copy) {
66 const int64_t size = File::CopyFile(source, file_.get(), max_copy);
74 mkvmuxer::int64 MkvWriter::Position()
const {
78 mkvmuxer::int32 MkvWriter::Position(mkvmuxer::int64 position) {
81 if (file_->Seek(position)) {
89 bool MkvWriter::Seekable()
const {
93 void MkvWriter::ElementStartNotify(mkvmuxer::uint64 element_id,
94 mkvmuxer::int64 position) {}
Define an abstract file interface.
All the methods that are virtual are virtual for mocking.