Skip to content

Commit

Permalink
aggiornamenti
Browse files Browse the repository at this point in the history
  • Loading branch information
mikymaione committed Apr 22, 2021
1 parent c7fab9c commit 3c98be3
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 27 deletions.
4 changes: 2 additions & 2 deletions Streaming/HTML/MAME.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ copyright-holders:Michele Maione
*/

//const uri = "ws://80.183.63.209:8888";
//const uri = "ws://192.168.1.8:8888";
const uri = "ws://localhost:8888";
const uri = "ws://192.168.1.8:8888";
//const uri = "ws://localhost:8888";

let keypress_Listener;

Expand Down
2 changes: 1 addition & 1 deletion Streaming/HTML/mame.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<meta charset="UTF-8">

<meta name="date" content="2021-04-11" scheme="YYYY-MM-DD">
<meta name="date" content="2021-04-20" scheme="YYYY-MM-DD">
<meta name="author" content="Maione Michele">
<meta name="description" content="MAME Cloud Gaming (aka DinoServer 🦕🧡🦖)">

Expand Down
4 changes: 2 additions & 2 deletions build/projects/sdl/mame/vs2019/mame.vcxproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerWorkingDirectory>..\..\..\..\..</LocalDebuggerWorkingDirectory>
<LocalDebuggerCommandArguments>-streamingserver -window -video accel -sound sdl -resolution 800x600@60</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>-streamingserver -window -video accel -sound sdl -resolution 640x480@30</LocalDebuggerCommandArguments>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
Expand All @@ -18,6 +18,6 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerWorkingDirectory>..\..\..\..\..</LocalDebuggerWorkingDirectory>
<LocalDebuggerCommandArguments>-streamingserver -window -video accel -sound sdl -resolution 800x600@60</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>-streamingserver -window -video accel -sound sdl -resolution 640x480@30</LocalDebuggerCommandArguments>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion run.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
setx SDL_VIDEODRIVER windows
setx SDL_AUDIODRIVER directsound
mame64.exe -streamingserver -window -video accel -sound sdl -resolution 640x480@60
mame64.exe -streamingserver -window -video accel -sound sdl -resolution 640x480@30
2 changes: 1 addition & 1 deletion run.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
./mame64 -streamingserver -window -video accel -sound sdl -resolution 640x480@60
./mame64 -streamingserver -window -video accel -sound sdl -resolution 640x480@30
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// copyright-holders:Michele Maione
//============================================================
//
// encode_to_streamable_movie.hpp - (aka DinoEncoding 🦕🧡🦖)
// encode_to_movie.hpp - (aka DinoEncoding 🦕🧡🦖)
// Encoding to:
// -mp4 (H.264 + AAC)
// -webm (VP9 + Vorbis)
Expand All @@ -18,7 +18,7 @@
#include <ostream>
#include <string>

// FFMPEG C headers
// FFmpeg C headers
extern "C"
{
#include "libavcodec/avcodec.h"
Expand All @@ -31,7 +31,7 @@ extern "C"

namespace encoding
{
class encode_to_streamable_movie
class encode_to_movie
{
public:
enum CODEC { MP4, WEBM, MPEGTS };
Expand Down Expand Up @@ -62,7 +62,8 @@ namespace encoding

// Video
AVCodecID VIDEO_CODEC;
//static constexpr int64_t VIDEO_BIT_RATE = 1 * 1000;
static constexpr int64_t VIDEO_BIT_RATE = 16 * 1000;
static constexpr int64_t VIDEO_BIT_RATE_TOLERANCE = 32 * 1000;

//SDL_PIXELFORMAT_RGBA32 = AV_PIX_FMT_BGR32
//SDL_PIXELFORMAT_RGB24 = AV_PIX_FMT_RGB24
Expand All @@ -71,7 +72,7 @@ namespace encoding

// Audio
AVCodecID AUDIO_CODEC;
//static constexpr int64_t AUDIO_BIT_RATE = 64 * 1000;
static constexpr int64_t AUDIO_BIT_RATE = 64 * 1000;

static constexpr int AUDIO_CHANNELS_IN = 2;
static constexpr int AUDIO_CHANNELS_OUT = 1; //1
Expand Down Expand Up @@ -132,7 +133,7 @@ namespace encoding

static int write_packet(void* opaque, uint8_t* buf, int buf_size)
{
auto* const this_ = static_cast<encode_to_streamable_movie*>(opaque);
auto* const this_ = static_cast<encode_to_movie*>(opaque);

this_->socket->write(reinterpret_cast<const char*>(buf), buf_size);

Expand Down Expand Up @@ -162,8 +163,8 @@ namespace encoding
encoder_context->video_codec_context->width = width;
encoder_context->video_codec_context->height = height;

//encoder_context->video_codec_context->bit_rate = VIDEO_BIT_RATE;
//encoder_context->video_codec_context->bit_rate_tolerance = 0;
encoder_context->video_codec_context->bit_rate = VIDEO_BIT_RATE;
encoder_context->video_codec_context->bit_rate_tolerance = VIDEO_BIT_RATE_TOLERANCE;

//encoder_context->video_codec_context->max_b_frames = 0;
//encoder_context->video_codec_context->has_b_frames = 0;
Expand Down Expand Up @@ -244,10 +245,10 @@ namespace encoding
encoder_context->audio_codec_context->sample_rate = SAMPLE_RATE_OUT;
encoder_context->audio_codec_context->sample_fmt = AUDIO_SAMPLE_FORMAT_OUT;

//encoder_context->audio_codec_context->bit_rate = AUDIO_BIT_RATE;
encoder_context->audio_codec_context->bit_rate = AUDIO_BIT_RATE;

encoder_context->audio_codec_context->time_base = { 1,fps };
//encoder_context->audio_codec_context->time_base = { 1,SAMPLE_RATE_OUT };
encoder_context->audio_codec_context->time_base = { 1, fps };
//encoder_context->audio_codec_context->time_base = { 1, SAMPLE_RATE_OUT };
//encoder_context->audio_stream->time_base = encoder_context->audio_codec_context->time_base;

AVDictionary* options = nullptr;
Expand Down Expand Up @@ -299,7 +300,7 @@ namespace encoding
die("Cannot alloc audio conversion buffer", ret);
}

void set_container_options(AVDictionary* options) const
static void set_container_options(AVDictionary* options)
{
switch (codec)
{
Expand Down Expand Up @@ -340,7 +341,7 @@ namespace encoding
const auto end_time = std::chrono::system_clock::now();
const auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time);

if (milliseconds.count() > 70)
if (milliseconds.count() > 100)
{
const auto ret = av_write_trailer(encoder_context->muxer_context);
if (ret < 0)
Expand All @@ -357,12 +358,12 @@ namespace encoding
}

public:
encode_to_streamable_movie(const std::shared_ptr<std::ostream>& socket, const int in_width, const int in_height, const int fps, std::function<void()> on_write) :
socket(socket),
encode_to_movie(std::shared_ptr<std::ostream> socket, const int in_width, const int in_height, const int fps, std::function<void()> on_write) :
socket(std::move(socket)),
width(in_width),
height(in_height),
fps(fps),
on_write(on_write)
on_write(std::move(on_write))
{
//av_log_set_level(AV_LOG_DEBUG);

Expand Down Expand Up @@ -410,9 +411,21 @@ namespace encoding

init_video();
init_audio();

std::cout
<< "Video" << std::endl
<< "-bit_rate: " << encoder_context->video_codec_context->bit_rate << std::endl
<< "-bit_rate_tolerance: " << encoder_context->video_codec_context->bit_rate_tolerance << std::endl
<< "-max_b_frames: " << encoder_context->video_codec_context->max_b_frames << std::endl
<< "-has_b_frames: " << encoder_context->video_codec_context->has_b_frames << std::endl
<< "-delay: " << encoder_context->video_codec_context->delay << std::endl
<< "-gop_size: " << encoder_context->video_codec_context->gop_size << std::endl
<< "Audio" << std::endl
<< "-bit_rate: " << encoder_context->audio_codec_context->bit_rate << std::endl
<< std::endl;
}

~encode_to_streamable_movie()
~encode_to_movie()
{
avformat_close_input(&encoder_context->muxer_context);
avformat_free_context(encoder_context->muxer_context);
Expand Down
6 changes: 3 additions & 3 deletions src/lib/util/streaming_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <unordered_map>

#include "server_ws_impl.hpp"
#include "encoding/encode_to_streamable_movie.hpp"
#include "encoding/encode_to_movie.hpp"
#include "modules/input/input_common.h"

namespace webpp
Expand All @@ -41,7 +41,7 @@ namespace webpp
std::unique_ptr<std::thread> game_thread;

bool encoding_initialized = false;
std::unique_ptr<encoding::encode_to_streamable_movie> encoder = nullptr;
std::unique_ptr<encoding::encode_to_movie> encoder = nullptr;
std::shared_ptr<ws_server::SendStream> encoder_socket = nullptr;

event_based_device<SDL_Event>* keyboard = nullptr;
Expand Down Expand Up @@ -246,7 +246,7 @@ namespace webpp

send_video_size_to_client(w, h);

encoder = std::make_unique<encoding::encode_to_streamable_movie>(encoder_socket, w, h, fps, [&]()
encoder = std::make_unique<encoding::encode_to_movie>(encoder_socket, w, h, fps, [&]()
{
send(encoder_socket, 130);

Expand Down

0 comments on commit 3c98be3

Please sign in to comment.