GithubHelp home page GithubHelp logo

steam-fish / sdl-renderer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jhuster/sdl-renderer

0.0 0.0 0.0 30.78 MB

A pcm & yuv raw data render library written with C++ based on SDL2.

License: Apache License 2.0

Shell 2.25% C++ 91.00% CMake 6.75%

sdl-renderer's Introduction

SDL-renderer

A pcm & yuv raw data render library written with C++ based on SDL2. The Mac platform is supported now and the other platforms will be supported later.

Dependence

Please download & install SDL2 first.

You should install the SDL2.framework into /Library/Frameworks on Mac OS platform.

Build

$ ./build.sh

The output files will be export to output dir.

Usage

1. Audio Player

// first define a class inherit from `SDLRenderer::AudioCallback`
class AudioSource : public SDLRenderer::AudioCallback
{
public:
    // when the audio driver need audio data, the callback will be triggered
    int OnReadAudioData(unsigned char* buffer, int size) override
    {
        // you should copy the audio pcm data to the `buffer` with `size` avalable space
        // and return the actual avalable data size
    }
}

int main(int argc, char* argv[])
{
    SDLRenderer::Init();
  
    // create sdl renderer
    auto renderer = SDLRenderer::CreateSDLRenderer();
  
    // create audio player
    AudioSource source;
    renderer->CreateAudioPlayer(samplerate, channels, format, samples, &source)
  
    // start audio play, the callback will be triggered later.
    renderer->SetAudioPlayPaused(false);
  
    // wait for audio playing
    while(!gExit);
  
    // destroy the audio player
    renderer->DestroyAudioPlayer();
      
    SDLRenderer::Exit();
  
    return 0;
}

2. Video Player

int main(int argc, char* argv[])
{
    SDLRenderer::Init
      
    // create sdl renderer
    auto renderer = SDLRenderer::CreateSDLRenderer();
  
    // create video player
    auto videoPlayer = renderer->CreateVideoPlayer("Window Title", videoWidth, videoHeight, SDLRenderer::VIDEO_FORMAT_IYUV);
    if (videoPlayer == 0) {
        return -1;
    }
  
    // create a YUV file reader
    VideoSource source;
  
    int size = videoWidth * videoHeight * 3 / 2;
    auto* buffer = new unsigned char[size];
  
    while (!gExit) {
        // read one yuv frame
        if (!source.ReadFrame(buffer, size)) {
            continue;
        }
        // render the yuv frame
        if (!renderer->RenderVideoFrame(videoPlayer, buffer, videoWidth, videoHeight)) {
            break;
        }
        usleep(30 * 1000);
    }
  
    // destroy the video player
    renderer->DestroyVideoPlayer(videoPlayer);
  
    SDLRenderer::Exit();
  
    return 0;
}

Test

Usage: ./example.out [options]
  -a audio pcm file path [required]
  -v video yuv file path [required]
  -s audio samplerate, [default]: 16000
  -m audio format, [default]: 1
  -c audio channels, [default]: 1
  -n audio sample size, [default]: 1024
  -w video width, [default]: 416
  -h video height, [default]: 240
$ cd output
$ ./example.out -a data/speech_16k_16bit.pcm -s 16000 -m 1 -c 1 -n 1024 -v data/horses_416x240_30.yuv -w 416 -h 240

Contracts

Email:[email protected]

sdl-renderer's People

Contributors

jhuster avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.