aboutsummaryrefslogtreecommitdiff
path: root/Src/vp6/flv_vp6_decoder.cpp
blob: 5de9fd769a12fd05c5f86c9a4e429f572a5fb207 (plain) (blame)
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
#include "flv_vp6_decoder.h"
#include "../nsv/nsvlib.h"
#include "../libvp6/include/vp6.h"
int FLVDecoderCreator::CreateVideoDecoder(int format_type, int width, int height, ifc_flvvideodecoder **decoder)
{
	if (format_type == FLV::VIDEO_FORMAT_VP6 || format_type == FLV::VIDEO_FORMAT_VP62)
	{
		//DXL_XIMAGE_HANDLE xim = DXL_CreateXImageOfType((unsigned char *)"" , format_type == FLV::VIDEO_FORMAT_VP6?NSV_MAKETYPE('V','P','6','0'):NSV_MAKETYPE('V','P','6','2'));
		DXL_XIMAGE_HANDLE xim = DXL_AlterXImage( NULL, (unsigned char *)"" ,NSV_MAKETYPE('V','P','6','0'), DXRGBNULL, 0, 0);
		if (!xim)
			return CREATEDECODER_FAILURE;
		*decoder = new FLVVP6(xim);
		return CREATEDECODER_SUCCESS;
	}
	return CREATEDECODER_NOT_MINE;
}

int FLVDecoderCreator::HandlesVideo(int format_type)
{
	if (format_type == FLV::VIDEO_FORMAT_VP6 || format_type == FLV::VIDEO_FORMAT_VP62)
	{
		return CREATEDECODER_SUCCESS;
	}
	return CREATEDECODER_NOT_MINE;
}

#define CBCLASS FLVDecoderCreator
START_DISPATCH;
CB(CREATE_VIDEO_DECODER, CreateVideoDecoder)
CB(HANDLES_VIDEO, HandlesVideo)
END_DISPATCH;
#undef CBCLASS

static const int vp6_postProcess=6;
static const int vp6_cpuFree=70;
static const int vp6_deInterlace=0;
static const int vp6_addNoise=1;

 enum
{
	PBC_SET_POSTPROC,
	PBC_SET_CPUFREE,
    PBC_MAX_PARAM,
	PBC_SET_TESTMODE,
	PBC_SET_PBSTRUCT,
	PBC_SET_BLACKCLAMP,
	PBC_SET_WHITECLAMP,
	PBC_SET_REFERENCEFRAME,
    PBC_SET_DEINTERLACEMODE,
    PBC_SET_ADDNOISE

} ;

 extern "C" 
 {
  void GetImageBufs(DXL_XIMAGE_HANDLE x, YV12_PLANES *p);
  void vp60_SetParameter(DXL_XIMAGE_HANDLE src, int Command, uintptr_t Parameter );
};

FLVVP6::FLVVP6(DXL_XIMAGE_HANDLE xim) : xim(xim)
{
	decoded=0;

	if(vp6_cpuFree)
		vp60_SetParameter(xim, PBC_SET_CPUFREE, vp6_cpuFree);
	else
		vp60_SetParameter(xim, PBC_SET_POSTPROC, vp6_postProcess);

	vp60_SetParameter(xim, PBC_SET_DEINTERLACEMODE, vp6_deInterlace );
	vp60_SetParameter(xim, PBC_SET_ADDNOISE, vp6_addNoise);
  vp60_SetParameter(xim, PBC_SET_BLACKCLAMP,0);
	vp60_SetParameter(xim, PBC_SET_WHITECLAMP,0);
}

int FLVVP6::GetOutputFormat(int *x, int *y, int *color_format)
{
	if (xim)
	{
		if (vp60_getWH(xim, x, y) == DXL_OK)
		{
			*color_format = NSV_MAKETYPE('Y','V','1','2');
			return FLV_VIDEO_SUCCESS;
		}
	}
	return FLV_VIDEO_FAILURE;
}

int FLVVP6::DecodeSample(const void *inputBuffer, size_t inputBufferBytes, int32_t timestamp)
{
	uint8_t *vp6_data = (uint8_t *)inputBuffer;
	if (inputBufferBytes)
	{
		// skip first byte
		vp6_data++;
		inputBufferBytes--;
	
		DXL_AlterXImageData(xim, (unsigned char *)vp6_data);
		DXL_SetXImageCSize(xim, inputBufferBytes);
		if (!vp60_decompress(xim))
		{
			decoded=1;
			return FLV_VIDEO_SUCCESS;
		}
	}

	return FLV_VIDEO_FAILURE;

}

void FLVVP6::Close()
{
	if (xim)
		DXL_DestroyXImage(xim);

	delete this;
}

int FLVVP6::GetPicture(void **data, void **decoder_data, uint64_t *timestamp)
{
	if (decoded)
	{
		GetImageBufs(xim,&vidbufdec);
		*data=&vidbufdec;
		*decoder_data = 0;
		decoded = 0;
		return FLV_VIDEO_SUCCESS;
	}

	return FLV_VIDEO_FAILURE;
}


#define CBCLASS FLVVP6
START_DISPATCH;
CB(FLV_VIDEO_GETOUTPUTFORMAT, GetOutputFormat)
CB(FLV_VIDEO_DECODE, DecodeSample)
VCB(FLV_VIDEO_CLOSE, Close)
CB(FLV_VIDEO_GET_PICTURE, GetPicture)
END_DISPATCH;
#undef CBCLASS