Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Ap4AsyncReaderStream.cpp « MP4Splitter « parser « filters « src - github.com/mpc-hc/mpc-hc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2824094a2fa98cc0c31d1a9432cc66caf8673bf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "stdafx.h"
#include "Ap4AsyncReaderStream.h"

AP4_AsyncReaderStream::AP4_AsyncReaderStream(CBaseSplitterFile* pFile)
	: m_refs(1)
	, m_pFile(pFile)
{
	ASSERT(pFile);
}

AP4_AsyncReaderStream::~AP4_AsyncReaderStream()
{
	ASSERT(m_refs == 0);
}

void AP4_AsyncReaderStream::AddReference()
{
	ASSERT(m_refs > 0);
	++m_refs;
}

void AP4_AsyncReaderStream::Release()
{
	ASSERT(m_refs > 0);
	if (--m_refs == 0) {
		delete this;
	}
}

AP4_Result AP4_AsyncReaderStream::Read(void* buffer, AP4_Size bytesToRead, AP4_Size* bytesRead)
{
	__int64 bytesAvail = m_pFile->GetRemaining();

	if (bytesAvail < (long long)bytesToRead) {
		if (bytesRead) {
			*bytesRead = bytesAvail;
		}
		bytesToRead = bytesAvail;
	}

	if (bytesAvail == 0) {
		return AP4_ERROR_EOS;
	}

	if (FAILED(m_pFile->ByteRead((BYTE*)buffer, bytesToRead))) {
		if (bytesRead) {
			*bytesRead = 0;
		}
		return AP4_ERROR_READ_FAILED;
	}

	if (bytesRead) {
		*bytesRead = bytesToRead;
	}

	return AP4_SUCCESS;
}

AP4_Result AP4_AsyncReaderStream::Write(const void* buffer, AP4_Size bytesToWrite, AP4_Size* bytesWritten)
{
	return AP4_ERROR_WRITE_FAILED;
}

AP4_Result AP4_AsyncReaderStream::Seek(AP4_Offset offset)
{
	m_pFile->Seek(offset);
	return m_pFile->GetPos() == offset ? AP4_SUCCESS : AP4_FAILURE;
}

AP4_Result AP4_AsyncReaderStream::Tell(AP4_Offset& offset)
{
	offset = (AP4_Offset)m_pFile->GetPos();
	return AP4_SUCCESS;
}

AP4_Result AP4_AsyncReaderStream::GetSize(AP4_Size& size)
{
	size = (AP4_Size)m_pFile->GetLength();
	return AP4_SUCCESS;
}