mirror of
https://github.com/Relintai/rpi_player.git
synced 2025-04-26 13:04:59 +02:00
Simple test vlc scene from libvlc's sample code. Doesn't display videos at the moment for some reason. Will figure it out later.
This commit is contained in:
parent
1583366a99
commit
337326d792
@ -4,11 +4,12 @@
|
|||||||
#include "application.h"
|
#include "application.h"
|
||||||
|
|
||||||
#include "main_scene.h"
|
#include "main_scene.h"
|
||||||
|
#include "vlc_scene.h"
|
||||||
|
|
||||||
class ImplApplication : public Application {
|
class ImplApplication : public Application {
|
||||||
public:
|
public:
|
||||||
ImplApplication() : Application() {
|
ImplApplication() : Application() {
|
||||||
scene = new MainScene();
|
scene = new VLCScene();
|
||||||
}
|
}
|
||||||
~ImplApplication() {
|
~ImplApplication() {
|
||||||
delete scene;
|
delete scene;
|
||||||
|
@ -26,6 +26,8 @@ void MainScene::render() {
|
|||||||
b3->render();
|
b3->render();
|
||||||
|
|
||||||
_ts->draw();
|
_ts->draw();
|
||||||
|
|
||||||
|
Renderer::get_singleton()->present();
|
||||||
}
|
}
|
||||||
|
|
||||||
MainScene::MainScene() {
|
MainScene::MainScene() {
|
||||||
|
172
app/vlc_scene.cpp
Normal file
172
app/vlc_scene.cpp
Normal file
@ -0,0 +1,172 @@
|
|||||||
|
#include "vlc_scene.h"
|
||||||
|
|
||||||
|
#include "renderer/renderer.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define VIDEOWIDTH 320
|
||||||
|
#define VIDEOHEIGHT 240
|
||||||
|
|
||||||
|
// VLC prepares to render a video frame.
|
||||||
|
static void *lock(void *data, void **p_pixels) {
|
||||||
|
|
||||||
|
VLCScene *c = (VLCScene *)data;
|
||||||
|
|
||||||
|
int pitch;
|
||||||
|
SDL_LockMutex(c->mutex);
|
||||||
|
SDL_LockTexture(c->texture, NULL, p_pixels, &pitch);
|
||||||
|
|
||||||
|
return NULL; // Picture identifier, not needed here.
|
||||||
|
}
|
||||||
|
|
||||||
|
// VLC just rendered a video frame.
|
||||||
|
static void unlock(void *data, void *id, void *const *p_pixels) {
|
||||||
|
|
||||||
|
VLCScene *c = (VLCScene *)data;
|
||||||
|
|
||||||
|
uint16_t *pixels = (uint16_t *)*p_pixels;
|
||||||
|
|
||||||
|
// We can also render stuff.
|
||||||
|
int x, y;
|
||||||
|
for (y = 10; y < 40; y++) {
|
||||||
|
for (x = 10; x < 40; x++) {
|
||||||
|
if (x < 13 || y < 13 || x > 36 || y > 36) {
|
||||||
|
pixels[y * VIDEOWIDTH + x] = 0xffff;
|
||||||
|
} else {
|
||||||
|
// RV16 = 5+6+5 pixels per color, BGR.
|
||||||
|
pixels[y * VIDEOWIDTH + x] = 0x02ff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_UnlockTexture(c->texture);
|
||||||
|
SDL_UnlockMutex(c->mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// VLC wants to display a video frame.
|
||||||
|
static void display(void *data, void *id) {
|
||||||
|
|
||||||
|
VLCScene *c = (VLCScene *)data;
|
||||||
|
|
||||||
|
int w = Renderer::get_singleton()->get_window_size_w();
|
||||||
|
int h = Renderer::get_singleton()->get_window_size_h();
|
||||||
|
|
||||||
|
SDL_Rect rect;
|
||||||
|
rect.w = VIDEOWIDTH;
|
||||||
|
rect.h = VIDEOHEIGHT;
|
||||||
|
rect.x = (int)((1. + .5 * sin(0.03 * c->n)) * (w - VIDEOWIDTH) / 2);
|
||||||
|
rect.y = (int)((1. + .5 * cos(0.03 * c->n)) * (h - VIDEOHEIGHT) / 2);
|
||||||
|
|
||||||
|
Renderer::get_singleton()->set_draw_color(0, 80, 0, 255);
|
||||||
|
Renderer::get_singleton()->clear();
|
||||||
|
SDL_RenderCopy(Renderer::get_singleton()->get_renderer(), c->texture, NULL, &rect);
|
||||||
|
//Renderer::get_singleton()->present();
|
||||||
|
|
||||||
|
//SDL_SetRenderDrawColor(Renderer::get_singleton()->get_renderer(), 0, 80, 0, 255);
|
||||||
|
//SDL_RenderClear(Renderer::get_singleton()->get_renderer());
|
||||||
|
//SDL_RenderCopy(Renderer::get_singleton()->get_renderer(), c->texture, NULL, &rect);
|
||||||
|
//SDL_RenderPresent(Renderer::get_singleton()->get_renderer());
|
||||||
|
}
|
||||||
|
|
||||||
|
void VLCScene::event(const SDL_Event &ev) {
|
||||||
|
|
||||||
|
action = 0;
|
||||||
|
|
||||||
|
switch (ev.type) {
|
||||||
|
case SDL_KEYDOWN:
|
||||||
|
action = ev.key.keysym.sym;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (action) {
|
||||||
|
case ' ':
|
||||||
|
printf("Pause toggle.\n");
|
||||||
|
pause = !pause;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VLCScene::update(float delta) {
|
||||||
|
if (!r) {
|
||||||
|
r = true;
|
||||||
|
printf("play\n");
|
||||||
|
libvlc_media_player_play(mp);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pause) {
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VLCScene::render() {
|
||||||
|
Renderer::get_singleton()->present();
|
||||||
|
}
|
||||||
|
|
||||||
|
VLCScene::VLCScene() {
|
||||||
|
r = false;
|
||||||
|
done = 0;
|
||||||
|
action = 0;
|
||||||
|
pause = 0;
|
||||||
|
|
||||||
|
texture = SDL_CreateTexture(
|
||||||
|
Renderer::get_singleton()->get_renderer(),
|
||||||
|
SDL_PIXELFORMAT_BGR565, SDL_TEXTUREACCESS_STREAMING,
|
||||||
|
VIDEOWIDTH, VIDEOHEIGHT);
|
||||||
|
|
||||||
|
if (!texture) {
|
||||||
|
fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mutex = SDL_CreateMutex();
|
||||||
|
|
||||||
|
char const *vlc_argv[] = {
|
||||||
|
//"--no-audio", // Don't play audio.
|
||||||
|
"--no-xlib", // Don't use Xlib.
|
||||||
|
|
||||||
|
// Apply a video filter.
|
||||||
|
//"--video-filter", "sepia",
|
||||||
|
//"--sepia-intensity=200"
|
||||||
|
};
|
||||||
|
int vlc_argc = sizeof(vlc_argv) / sizeof(*vlc_argv);
|
||||||
|
|
||||||
|
if (getenv("VLC_PLUGIN_PATH") == nullptr) {
|
||||||
|
setenv("VLC_PLUGIN_PATH", "/usr/lib/vlc/plugins", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If you don't have this variable set you must have plugins directory
|
||||||
|
// with the executable or libvlc_new() will not work!
|
||||||
|
printf("VLC_PLUGIN_PATH=%s\n", getenv("VLC_PLUGIN_PATH"));
|
||||||
|
|
||||||
|
// Initialise libVLC.
|
||||||
|
libvlc = libvlc_new(vlc_argc, vlc_argv);
|
||||||
|
if (NULL == libvlc) {
|
||||||
|
printf("LibVLC initialization failure.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m = libvlc_media_new_path(libvlc, "./test.mp4");
|
||||||
|
|
||||||
|
mp = libvlc_media_player_new_from_media(m);
|
||||||
|
libvlc_media_release(m);
|
||||||
|
|
||||||
|
libvlc_video_set_callbacks(mp, lock, unlock, display, this);
|
||||||
|
libvlc_video_set_format(mp, "RV16", VIDEOWIDTH, VIDEOHEIGHT, VIDEOWIDTH * 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
VLCScene::~VLCScene() {
|
||||||
|
|
||||||
|
// Stop stream and clean up libVLC.
|
||||||
|
libvlc_media_player_stop(mp);
|
||||||
|
libvlc_media_player_release(mp);
|
||||||
|
libvlc_release(libvlc);
|
||||||
|
|
||||||
|
// Close window and clean up libSDL.
|
||||||
|
SDL_DestroyMutex(mutex);
|
||||||
|
}
|
33
app/vlc_scene.h
Normal file
33
app/vlc_scene.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#ifndef VLC_SCENE_H
|
||||||
|
#define VLC_SCENE_H
|
||||||
|
|
||||||
|
#include "scene.h"
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
|
#include "vlc/vlc.h"
|
||||||
|
|
||||||
|
class VLCScene : public Scene {
|
||||||
|
public:
|
||||||
|
void event(const SDL_Event &ev);
|
||||||
|
void update(float delta);
|
||||||
|
void render();
|
||||||
|
|
||||||
|
VLCScene();
|
||||||
|
~VLCScene();
|
||||||
|
|
||||||
|
SDL_Texture *texture;
|
||||||
|
SDL_mutex *mutex;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
libvlc_instance_t *libvlc;
|
||||||
|
libvlc_media_t *m;
|
||||||
|
libvlc_media_player_t *mp;
|
||||||
|
|
||||||
|
bool r;
|
||||||
|
int done;
|
||||||
|
int action;
|
||||||
|
int pause;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -21,8 +21,6 @@ void Application::update(float delta) {
|
|||||||
}
|
}
|
||||||
void Application::render() {
|
void Application::render() {
|
||||||
scene->render();
|
scene->render();
|
||||||
|
|
||||||
Renderer::get_singleton()->present();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::main_loop() {
|
void Application::main_loop() {
|
||||||
|
7
main.cpp
7
main.cpp
@ -96,6 +96,8 @@ int main(int argc, char **argv) {
|
|||||||
mqtt_server->add_local_session(
|
mqtt_server->add_local_session(
|
||||||
"a/b", [](const std::string &client_id, const std::vector<uint8_t> &data, void *obj) { reinterpret_cast<ICApplication *>(obj)->mqtt_sensor_callback(client_id, data); }, app);
|
"a/b", [](const std::string &client_id, const std::vector<uint8_t> &data, void *obj) { reinterpret_cast<ICApplication *>(obj)->mqtt_sensor_callback(client_id, data); }, app);
|
||||||
|
|
||||||
|
TTF_Init();
|
||||||
|
|
||||||
Renderer *renderer = new Renderer();
|
Renderer *renderer = new Renderer();
|
||||||
ImplApplication *sdl_app = new ImplApplication();
|
ImplApplication *sdl_app = new ImplApplication();
|
||||||
|
|
||||||
@ -105,18 +107,17 @@ int main(int argc, char **argv) {
|
|||||||
//mqtt_server->run_async();
|
//mqtt_server->run_async();
|
||||||
//server->main_loop();
|
//server->main_loop();
|
||||||
|
|
||||||
TTF_Init();
|
|
||||||
|
|
||||||
while (sdl_app->running) {
|
while (sdl_app->running) {
|
||||||
sdl_app->main_loop();
|
sdl_app->main_loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
TTF_Quit();
|
|
||||||
} else {
|
} else {
|
||||||
printf("Running migrations.\n");
|
printf("Running migrations.\n");
|
||||||
app->migrate();
|
app->migrate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TTF_Quit();
|
||||||
|
|
||||||
delete sdl_app;
|
delete sdl_app;
|
||||||
delete renderer;
|
delete renderer;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user