file_mkv_reader.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "file_mkv_reader.h"
  2. MKVReaderFILE::MKVReaderFILE(FILE *f) : f(f)
  3. {
  4. }
  5. MKVReaderFILE::MKVReaderFILE(const wchar_t *filename)
  6. {
  7. f = _wfopen(filename, L"rb");
  8. }
  9. int MKVReaderFILE::Read(void *buffer, size_t read_length, size_t *bytes_read)
  10. {
  11. *bytes_read = fread(buffer, 1, read_length, f);
  12. return nsmkv::READ_OK;
  13. }
  14. int MKVReaderFILE::Peek(void *buffer, size_t read_length, size_t *bytes_read)
  15. {
  16. *bytes_read = fread(buffer, 1, read_length, f);
  17. fseek(f, (long)(-read_length), SEEK_CUR);
  18. return nsmkv::READ_OK;
  19. }
  20. int MKVReaderFILE::Seek(uint64_t position)
  21. {
  22. fsetpos(f, (const fpos_t *)&position);
  23. return nsmkv::READ_OK;
  24. }
  25. uint64_t MKVReaderFILE::Tell()
  26. {
  27. uint64_t pos;
  28. fgetpos(f, (fpos_t *)&pos);
  29. return pos;
  30. }
  31. int MKVReaderFILE::Skip(uint64_t skip_bytes)
  32. {
  33. _fseeki64(f, skip_bytes, SEEK_CUR);
  34. return nsmkv::READ_OK;
  35. }
  36. MKVReaderFILE::~MKVReaderFILE()
  37. {
  38. fclose(f);
  39. }
  40. uint64_t MKVReaderFILE::GetContentLength()
  41. {
  42. uint64_t old = Tell();
  43. Seek(0);
  44. uint64_t content_length = Tell();
  45. Seek(old);
  46. return content_length;
  47. }