1 // Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the LICENSE file in the root of the source
5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS. All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree.
9 #include "mkvreader.hpp"
15 MkvReader::MkvReader() : m_file(NULL), reader_owns_file_(true) {}
17 MkvReader::MkvReader(FILE* fp) : m_file(fp), reader_owns_file_(false) {
21 MkvReader::~MkvReader() {
22 if (reader_owns_file_)
27 int MkvReader::Open(const char* fileName) {
35 const errno_t e = fopen_s(&m_file, fileName, "rb");
40 m_file = fopen(fileName, "rb");
45 return !GetFileSize();
48 bool MkvReader::GetFileSize() {
52 int status = _fseeki64(m_file, 0L, SEEK_END);
55 return false; // error
57 m_length = _ftelli64(m_file);
59 fseek(m_file, 0L, SEEK_END);
60 m_length = ftell(m_file);
62 assert(m_length >= 0);
68 status = _fseeki64(m_file, 0L, SEEK_SET);
71 return false; // error
73 fseek(m_file, 0L, SEEK_SET);
79 void MkvReader::Close() {
86 int MkvReader::Length(long long* total, long long* available) {
94 *available = m_length;
99 int MkvReader::Read(long long offset, long len, unsigned char* buffer) {
112 if (offset >= m_length)
116 const int status = _fseeki64(m_file, offset, SEEK_SET);
121 fseek(m_file, offset, SEEK_SET);
124 const size_t size = fread(buffer, 1, len, m_file);
126 if (size < size_t(len))
132 } // end namespace mkvparser