summaryrefslogtreecommitdiff
path: root/src/eTransCodingDevice.cpp
blob: 406fe1589d078e4f3042a64f61fc1bbb1ad3e9a0 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
 * eTransCodingDevice.cpp
 *
 *  Created on: 2013. 11. 3.
 *      Author: kos
 */

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>

#include "ePreDefine.h"
#include "eTransCodingDevice.h"
//-------------------------------------------------------------------------------

#ifdef DEBUG_LOG
//#undef LOG
//#define LOG(X,...) { do{}while(0); }
#endif

#define IOCTL_OPCODE_SET_VPID   1
#define IOCTL_OPCODE_SET_APID   2
#define IOCTL_OPCODE_SET_PMTPID 3
#define IOCTL_OPCODE_START_TRANSCODING 100
#define IOCTL_OPCODE_STOP_TRANSCODING  200

eTransCodingDevice::eTransCodingDevice()
	: mDeviceFd(0)
{
}
//-------------------------------------------------------------------------------

eTransCodingDevice::~eTransCodingDevice()
{
	Close();
}
//-------------------------------------------------------------------------------

bool eTransCodingDevice::Open()
{
	mDeviceFd = open("/dev/bcm_enc0", O_RDWR);
	if(mDeviceFd <= 0) {
		mDeviceFd = 0;
#ifdef DEBUG_LOG
		LOG("transcoding device open failed.");
#endif
		return false;
	}
#ifdef DEBUG_LOG
	LOG("transcoding device open ok.");
#endif
	return true;
}
//-------------------------------------------------------------------------------

void eTransCodingDevice::Close()
{
	StopTranscoding();
	if(mDeviceFd == 0) {
		close(mDeviceFd);
	}
	mDeviceFd = 0;
}
//-------------------------------------------------------------------------------

int eTransCodingDevice::GetDeviceFd()
{
	return mDeviceFd;
}
//-------------------------------------------------------------------------------

bool eTransCodingDevice::SetStreamPid(int aVideoPid, int aAudioPid)
{
	if(aVideoPid > 0) {
		if(ioctl(mDeviceFd, IOCTL_OPCODE_SET_VPID, aVideoPid) < 0) {
#ifdef DEBUG_LOG
			LOG("setting stream video pid failed.");
#endif
			return false;
		}
	}
	if(aAudioPid > 0) {
		if(ioctl(mDeviceFd, IOCTL_OPCODE_SET_APID, aAudioPid) < 0) {
#ifdef DEBUG_LOG
			LOG("setting stream audio pid failed.");
#endif
			return false;
		}
	}
#ifdef DEBUG_LOG
	LOG("setting stream pid ok.");
#endif
	return true;
}
//-------------------------------------------------------------------------------

bool eTransCodingDevice::SetStreamPid(int aVideoPid, int aAudioPid, int aPmtPid)
{
	if(aVideoPid > 0) {
		if(ioctl(mDeviceFd, IOCTL_OPCODE_SET_VPID, aVideoPid) < 0) {
#ifdef DEBUG_LOG
			LOG("setting stream video pid failed.");
#endif
			return false;
		}
	}
	if(aAudioPid > 0) {
		if(ioctl(mDeviceFd, IOCTL_OPCODE_SET_APID, aAudioPid) < 0) {
#ifdef DEBUG_LOG
			LOG("setting stream audio pid failed.");
#endif
			return false;
		}
	}
	if(aPmtPid > 0) {
		if(ioctl(mDeviceFd, IOCTL_OPCODE_SET_PMTPID, aPmtPid) < 0) {
#ifdef DEBUG_LOG
			LOG("setting stream pmt pid failed.");
#endif
			return false;
		}
	}
#ifdef DEBUG_LOG
	LOG("setting stream pid ok.");
#endif
	return true;
}
//-------------------------------------------------------------------------------

bool eTransCodingDevice::StartTranscoding()
{
	if(ioctl(mDeviceFd, IOCTL_OPCODE_START_TRANSCODING, 0) < 0) {
#ifdef DEBUG_LOG
	LOG("start transcoding failed.");
#endif
		return false;
	}
#ifdef DEBUG_LOG
	LOG("start transcoding ok.");
#endif
	return true;
}
//-------------------------------------------------------------------------------

void eTransCodingDevice::StopTranscoding()
{
	ioctl(mDeviceFd, IOCTL_OPCODE_STOP_TRANSCODING, 0);
}
//-------------------------------------------------------------------------------