技术标签: cocos2d-x Cocos2d-x windows
#include "VLCPlayer.h"
USING_NS_CC;
void *lock(void *data, void **p_pixels)
{
auto player = static_cast
(data);
*p_pixels = player->m_videobuf;
return NULL;
}
void unlock(void *data, void *id, void *const *p_pixels)
{
assert(id == NULL);
}
void display(void *data, void *id)
{
auto player = static_cast
(data);
player->m_readyToShow = true;
assert(id == NULL);
}
void endReached(const struct libvlc_event_t *event, void *data)
{
if (libvlc_MediaPlayerEndReached == event->type)
{
VLCPlayer *self = (VLCPlayer *)data;
self->m_isEndReached = true;
}
}
VLCPlayer::~VLCPlayer()
{
libvlc_media_player_stop(vlc_player);
libvlc_media_player_release(vlc_player);
libvlc_release(vlc);
free(m_videobuf);
}
VLCPlayer* VLCPlayer::create(Size size)
{
auto player = new VLCPlayer;
if (player && player->init(size)) {
player->autorelease();
} else {
CC_SAFE_DELETE(player);
}
return player;
}
bool VLCPlayer::init(Size &size)
{
vlc = libvlc_new(0, NULL);
vlc_player = libvlc_media_player_new(vlc);
width = size.width;
height = size.height;
m_videobuf = (char *)malloc((width * height) << 2);
memset(m_videobuf, 0, (width * height) << 2);
libvlc_video_set_callbacks(vlc_player, lock, unlock, display, this);
libvlc_video_set_format(vlc_player, "RGBA", width, height, width << 2);
libvlc_event_attach(libvlc_media_player_event_manager(vlc_player),
libvlc_MediaPlayerEndReached,
endReached,
(void *)this);
Texture2D *texture = new Texture2D();
texture->initWithData(m_videobuf,
(width * height) << 2,
Texture2D::PixelFormat::RGBA8888,
width, height, size);
texture->autorelease();
initWithTexture(texture);
scheduleUpdate();
return true;
}
void VLCPlayer::o_play(std::string &path, bool repeat)
{
m_isEndReached = false;
m_curMedia = path;
m_repeat = repeat;
m_readyToShow = false;
libvlc_media_t *media = libvlc_media_new_path(vlc, path.c_str());
libvlc_media_player_set_media(vlc_player, media);
libvlc_media_release(media);
libvlc_media_player_play(vlc_player);
}
void VLCPlayer::o_stop(void) { libvlc_media_player_stop(vlc_player); }
void VLCPlayer::o_resume(void) { libvlc_media_player_set_pause(vlc_player, 0); }
void VLCPlayer::o_pause(void) { libvlc_media_player_pause(vlc_player); }
bool VLCPlayer::isPlaying(void) { return (1 == libvlc_media_player_is_playing(vlc_player)) ? true : false; }
bool VLCPlayer::isEndReached() { return m_isEndReached; }
void VLCPlayer::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
_insideBounds = (flags & FLAGS_TRANSFORM_DIRTY) ? renderer->checkVisibility(transform, _contentSize) : _insideBounds;
if(_insideBounds)
{
if (m_readyToShow) {
m_readyToShow = false;
Texture2D *texture = new Texture2D();
texture->initWithData(m_videobuf,
(width * height) << 2,
Texture2D::PixelFormat::RGBA8888,
width, height, Size(width, height));
texture->autorelease();
setTexture(texture);
}
_quadCommand.init(_globalZOrder, _texture->getName(), getGLProgramState(), _blendFunc, &_quad, 1, transform);
renderer->addCommand(&_quadCommand);
#if CC_SPRITE_DEBUG_DRAW
_debugDrawNode->clear();
Vec2 vertices[4] = {
Vec2( _quad.bl.vertices.x, _quad.bl.vertices.y ),
Vec2( _quad.br.vertices.x, _quad.br.vertices.y ),
Vec2( _quad.tr.vertices.x, _quad.tr.vertices.y ),
Vec2( _quad.tl.vertices.x, _quad.tl.vertices.y ),
};
_debugDrawNode->drawPoly(vertices, 4, true, Color4F(1.0, 1.0, 1.0, 1.0));
#endif //CC_SPRITE_DEBUG_DRAW
}
}
void VLCPlayer::update(float dt)
{
if (m_repeat && isEndReached()) {
o_play(m_curMedia);
}
}
#ifndef __MOVIEPLAYER_H__
#define __MOVIEPLAYER_H__
#include "vlc/vlc.h"
#include "cocos2d.h"
class VLCPlayer : public cocos2d::Sprite
{
public:
~VLCPlayer();
static VLCPlayer* create(cocos2d::Size size);
bool init(cocos2d::Size &size);
void o_play(std::string &path, bool repeat = true);
inline void o_stop(void);
inline void o_pause(void);
inline void o_resume(void);
inline bool isPlaying(void);
inline bool isEndReached();
virtual void draw(cocos2d::Renderer *renderer, const cocos2d::Mat4 &transform, uint32_t flags) override;
virtual void update(float dt) override;
friend void endReached(const struct libvlc_event_t *event, void *data);
friend void *lock(void *data, void **p_pixels);
friend void unlock(void *data, void *id, void *const *p_pixels);
friend void display(void *data, void *id);
private:
libvlc_instance_t *vlc;
libvlc_media_player_t *vlc_player;
unsigned int width;
unsigned int height
char *m_videobuf;
bool m_isEndReached;
std::string m_curMedia;
bool m_repeat;
bool m_readyToShow;
};
#endif
文章浏览阅读4.6k次。10月11日,联想集团在全球总部未来中心举行了主题为“解密X空间”的新品发布会,正式发布了LEGIONY9000X笔记本电脑,并公布了“联想个人云存储核心测试用户招募”计划。高性能标压轻薄本 LEGION Y9000X赋能内容创造者“你正在用的笔记本是游戏本还是轻薄本?”通过这样的一个问题,联想中国区消费业务笔记本产品规划总监林林,拉开了“解密X空间”的序幕,带来重磅新品——高性能标..._y9000x写代码够用吗
文章浏览阅读3.4w次,点赞2次,收藏29次。前一阵研究强化学习,发现中文的资料非常少,实例就更少。于是翻译一篇q学习算法的教程,供需要的人学习。原文链接:http://mnemstudio.org/path-finding-q-learning-tutorial.htm正文:Q学习算法是一种用来解决马尔可夫决策过程中最优化问题的方法。Q学习算法最大的特点是它具有选择瞬时奖励和延迟奖励的能力。在每一步中,agent通过观察状态_强化学习教程
文章浏览阅读81次。后端:Java+SpringBoot前端:Vue数据库:MySQL开发软件:Eclipse、MyEclipse、IDEA都可以运行。_基于vue+springboot的校园二手商品交易网站论文
文章浏览阅读231次。对于每个前端从业者来说,除了F5键之外,用的最多的另外一个键就是F12了。今天,大神(@小鱼二)推荐我一个网站,才知道chrome还有各种骚姿势。网站是:umaar.com/dev-tip...
文章浏览阅读2k次。【jeecg-boot】jeecg-boot的一些功能扩展:_jeecg-boot
文章浏览阅读2.7k次。首先确保你的电脑有安装git环境,本人使用的是windows下的git环境。双击桌面图标 的Git Bash 打开窗口修改配置git config --global user.namegit config --global user.email如:git config --global user.name "muzidigbig"git config --glo..._gitlab 18: transfer closed with outstanding read data remaining
文章浏览阅读164次。第一章 未恋先失<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />初中时代的我,还是一个单纯的女孩,对于爱情,以为是眼泪制造出来的。我的圈子并不大,只有几个要好的女生,彭老二,周薇,秋毛。彭老二是个大嘴,校园里发生了什么事情她总是最先知道,通过她的大嘴,什么八卦新闻都逃..._操小帅
文章浏览阅读4.4k次,点赞2次,收藏23次。小波变换3级分解Mallat图:将带噪语音作为输入信号进行逐级DWT小波分解,并将分解出的低频成分cA3cA_3cA3与强制置0后的高频成分cD3cD_3cD3,cD2cD_2cD2,cD1cD_1cD1进行小波重构。Demo:clc,clear[x,Fs]= audioread('MUsic_Test.wav');snr = 20; %设定信噪比,单位dbnoise = randn(size(x)); % 用randn函数产生高斯白噪声Nx = length(x_db4小波
文章浏览阅读8.3k次,点赞5次,收藏34次。首先需要安装 snmp ,使用下面的命令进行安装安装完毕之后,使用下面的命令查看是否安装成功当命令行显示如图即为安装成功。_snmp工具
文章浏览阅读6.4k次,点赞5次,收藏40次。练习打字的官网:http://dazi.kukuw.com/关于打字的详细介绍:一个过来人的打字指法纠正之路_怎么敲键盘
文章浏览阅读9.6k次,点赞3次,收藏68次。一,网络安全体系结构网络安全体系结构是对网络信息安全基本问题的应对措施的集合,通常由保护,检测,响应和恢复等手段构成。1,网络信息安全的基本问题研究信息安全的困难在于:边界模糊数据安全与平台安全相交叉;存储安全与传输安全相制约;网络安全,应用安全与系统安全共存;集中的安全模式与分权制约安全模式相互竞争等。评估困难安全结构非常复杂,网络层,系统层,应用层的安全设备,安全协议和安全程序构成一个有机的整体,加上安全机制与人的互动性,网络的动态运行带来的易变性,使得评价网络安全性成为极_网络安全解决方案
文章浏览阅读1.2k次,点赞22次,收藏29次。QGIS在Windows下的编译——QGIS3.28.15 + Qt5.15.3 +CMake3.28.0 + VS2022 ---64位版本_qgis windows编译