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
|
#include "avi_yuv_decoder.h"
#include "../Winamp/wa_ipc.h"
#include <limits.h>
#include <bfc/error.h>
#include <intsafe.h>
int BMP_GetMallocSize(int32_t height, int32_t width, int32_t bits_per_pixel, size_t *out_frame_bytes);
AVIYUV *AVIYUV::CreateDecoder(nsavi::video_format *stream_format)
{
AVIYUV *decoder = new AVIYUV( stream_format);
if (!decoder)
{
return 0;
}
if (decoder->Initialize() != NErr_Success)
{
delete decoder;
return 0;
}
return decoder;
}
AVIYUV::AVIYUV(nsavi::video_format *stream_format) : stream_format(stream_format)
{
video_frame=0;
video_frame_size_bytes=0;
o=false;
}
AVIYUV::~AVIYUV()
{
free(video_frame);
}
int AVIYUV::Initialize()
{
size_t frame_bytes;
int ret = BMP_GetMallocSize(stream_format->height, stream_format->width, 16, &frame_bytes);
if (ret != NErr_Success)
return ret;
video_frame=malloc(frame_bytes);
if (!video_frame)
return NErr_OutOfMemory;
video_frame_size_bytes = frame_bytes;
return NErr_Success;
}
int AVIYUV::GetOutputProperties(int *x, int *y, int *color_format, double *aspect_ratio, int *flip)
{
if (stream_format)
{
*x = stream_format->width;
*y = stream_format->height;
//*flip = 1;
*color_format = stream_format->compression;
return AVI_SUCCESS;
}
return AVI_FAILURE;
}
int AVIYUV::DecodeChunk(uint16_t type, const void *inputBuffer, size_t inputBufferBytes)
{
if (stream_format)
{
if (video_frame_size_bytes < inputBufferBytes)
return AVI_FAILURE;
memcpy(video_frame, inputBuffer, inputBufferBytes);
//video_frame = inputBuffer; // heh
o=true;
return AVI_SUCCESS;
}
return AVI_FAILURE;
}
void AVIYUV::Flush()
{
}
int AVIYUV::GetPicture(void **data, void **decoder_data)
{
if (o && video_frame)
{
*data =(void *) video_frame;
*decoder_data=0;
//video_frame=0;
o=false;
//video_outputted=true;
return AVI_SUCCESS;
}
return AVI_FAILURE;
}
void AVIYUV::Close()
{
delete this;
}
#define CBCLASS AVIYUV
START_DISPATCH;
CB(GET_OUTPUT_PROPERTIES, GetOutputProperties)
CB(DECODE_CHUNK, DecodeChunk)
VCB(FLUSH, Flush)
VCB(CLOSE, Close)
CB(GET_PICTURE, GetPicture)
END_DISPATCH;
#undef CBCLASS
|