7 #include <packager/media/formats/webm/mkv_writer.h>
9 #include <absl/log/check.h>
14 MkvWriter::MkvWriter() : position_(0) {}
16 MkvWriter::~MkvWriter() {}
18 Status MkvWriter::Open(
const std::string& name) {
20 file_.reset(File::Open(name.c_str(),
"w"));
22 return Status(error::FILE_FAILURE,
"Unable to open file for writing.");
26 seekable_ = file_->Seek(0);
31 Status MkvWriter::Close() {
32 const std::string file_name = file_->file_name();
33 if (!file_.release()->Close()) {
36 "Cannot close file " + file_name +
37 ", possibly file permission issue or running out of disk space.");
42 mkvmuxer::int32 MkvWriter::Write(
const void* buf, mkvmuxer::uint32 len) {
45 const char* data =
reinterpret_cast<const char*
>(buf);
46 int64_t total_bytes_written = 0;
47 while (total_bytes_written < len) {
48 const int64_t written =
49 file_->Write(data + total_bytes_written, len - total_bytes_written);
53 total_bytes_written += written;
56 DCHECK_EQ(total_bytes_written, len);
61 int64_t MkvWriter::WriteFromFile(File* source) {
62 return WriteFromFile(source, kWholeFile);
65 int64_t MkvWriter::WriteFromFile(File* source, int64_t max_copy) {
68 const int64_t size = File::Copy(source, file_.get(), max_copy);
76 mkvmuxer::int64 MkvWriter::Position()
const {
80 mkvmuxer::int32 MkvWriter::Position(mkvmuxer::int64 position) {
83 if (file_->Seek(position)) {
91 bool MkvWriter::Seekable()
const {
95 void MkvWriter::ElementStartNotify(mkvmuxer::uint64 ,
All the methods that are virtual are virtual for mocking.