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
|
// license:BSD-3-Clause
// copyright-holders:Ryan Holtz
/*********************************************************************
avivideo.cpp
Image device for AVI video.
*********************************************************************/
#include "emu.h"
#include "avivideo.h"
#include "aviio.h"
/***************************************************************************
TYPE DEFINITIONS
***************************************************************************/
// device type definition
DEFINE_DEVICE_TYPE(IMAGE_AVIVIDEO, avivideo_image_device, "avivideo_image", "AVI Video Image")
//-------------------------------------------------
// avivideo_image_device - constructor
//-------------------------------------------------
avivideo_image_device::avivideo_image_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock) :
device_t(mconfig, IMAGE_AVIVIDEO, tag, owner, clock),
device_image_interface(mconfig, *this),
m_frame(nullptr),
m_avi(nullptr),
m_frame_timer(nullptr),
m_frame_count(0),
m_frame_num(0)
{
}
//-------------------------------------------------
// avivideo_image_device - destructor
//-------------------------------------------------
avivideo_image_device::~avivideo_image_device()
{
call_unload();
}
void avivideo_image_device::device_start()
{
m_frame_timer = timer_alloc(FUNC(avivideo_image_device::frame_timer), this);
m_frame_timer->adjust(attotime::never);
save_item(NAME(m_frame_count));
save_item(NAME(m_frame_num));
}
void avivideo_image_device::device_reset()
{
m_frame_num = 0;
}
TIMER_CALLBACK_MEMBER(avivideo_image_device::frame_timer)
{
if (m_avi != nullptr)
{
avi_file::error avierr = m_avi->read_uncompressed_video_frame(m_frame_num, *m_frame);
if (avierr != avi_file::error::NONE)
{
m_frame_timer->adjust(attotime::never);
return;
}
m_frame_num++;
if (m_frame_num >= m_frame_count)
{
m_frame_num = 0;
}
}
else
{
m_frame_timer->adjust(attotime::never);
}
}
image_init_result avivideo_image_device::call_load()
{
m_frame = new bitmap_argb32;
avi_file::error avierr = avi_file::open(filename(), m_avi);
if (avierr != avi_file::error::NONE)
{
delete m_frame;
m_frame = nullptr;
return image_init_result::FAIL;
}
const avi_file::movie_info &aviinfo = m_avi->get_movie_info();
float frame_rate = (float)aviinfo.video_timescale / (float)aviinfo.video_sampletime;
attotime frame_time = attotime::from_hz((int)round(frame_rate));
m_frame_timer->adjust(frame_time, 0, frame_time);
m_frame_count = aviinfo.video_numsamples;
m_frame_num = 0;
return image_init_result::PASS;
}
void avivideo_image_device::call_unload()
{
if (m_frame)
{
delete m_frame;
m_frame = nullptr;
}
if (m_avi)
{
m_avi.release();
m_avi = nullptr;
}
}
|