이곳은 다양한 오픈소스 프로젝트를 소개하고 리뷰, 활용 방법을 공유합니다.
조회 수 2563 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부

라즈베리파이 4 미디어 플레이어를 개발하기 위해 Qt와 GStreamer 로 아주 단간하게 테스트용도로 작성한 flac 오디오 재생 프로그램. (Qt Multimedia 가 아님) GStreamer의 Hello world 소스코드 일부를 수정하였고 flac 오디오 파일을 재생 시킨다.. 

 

#include <gst/gst.h>

class MediaPlayer::MediaPlayerImpl
{
public:
    MediaPlayerImpl()
        : pipeline(nullptr), source(nullptr), demuxer(nullptr), decoder(nullptr), conv(nullptr), sink(nullptr)
        , bus(nullptr), bus_watch_id(0)
    {

    }

    static gboolean bus_call (GstBus *bus, GstMessage *msg, gpointer data)
    {
      switch (GST_MESSAGE_TYPE (msg)) {

        case GST_MESSAGE_EOS:
          g_print ("End of stream\n");

          break;

        case GST_MESSAGE_ERROR: {
          gchar  *debug;
          GError *error;

          gst_message_parse_error (msg, &error, &debug);
          g_free (debug);

          g_printerr ("Error: %s\n", error->message);
          g_error_free (error);

          break;
        }
        default:
          break;
      }

      return TRUE;
    }

    GstElement *pipeline, *source, *demuxer, *decoder, *conv, *sink;
    GstBus *bus;
    guint bus_watch_id;
};


MediaPlayer::MediaPlayer()
    :pImpl(std::make_shared<MediaPlayerImpl>())
{

}

MediaPlayer::~MediaPlayer()
{
    /* Out of the main loop, clean up nicely */
     g_print ("Returned, stopping playback\n");
     gst_element_set_state (pImpl->pipeline, GST_STATE_NULL);

     g_print ("Deleting pipeline\n");
     gst_object_unref (GST_OBJECT (pImpl->pipeline));
     g_source_remove (pImpl->bus_watch_id);
}

int MediaPlayer::init(int *argc, char **argv[])
{
    /* Initialisation */
    gst_init (argc, argv);

    /* Create gstreamer elements */
    pImpl->pipeline = gst_pipeline_new ("audio-player");
    pImpl->source   = gst_element_factory_make ("filesrc",       "file-source");
    pImpl->demuxer  = gst_element_factory_make ("flacparse",      "flacparse-demuxer");
    pImpl->decoder  = gst_element_factory_make ("flacdec",     "flacdec-decoder");
    pImpl->sink     = gst_element_factory_make ("autoaudiosink", "audio-output");

    if (!pImpl->pipeline || !pImpl->source || !pImpl->demuxer || !pImpl->decoder || !pImpl->sink) {
        g_printerr ("One element could not be created. Exiting.\n");
        return -1;
    }

    /* we add a message handler */
    pImpl->bus = gst_pipeline_get_bus (GST_PIPELINE (pImpl->pipeline));
    pImpl->bus_watch_id = gst_bus_add_watch (pImpl->bus, pImpl->bus_call, nullptr);
    gst_object_unref (pImpl->bus);

    /* we add all elements into the pipeline */
    /* file-source | flacparse | flacdec-decoder | alsa-output */
    gst_bin_add_many (GST_BIN (pImpl->pipeline),
                      pImpl->source, pImpl->demuxer, pImpl->decoder, pImpl->sink, NULL);

    /* we link the elements together */
    /* file-source -> flacparse ~> flacdec-decoder -> alsa-output */

    gst_element_link_many (pImpl->source, pImpl->demuxer, pImpl->decoder, pImpl->sink, NULL);

    return 0;
}

void MediaPlayer::setSourcePath(const QString &path)
{
    /* we set the input filename to the source element */
    g_object_set (G_OBJECT (pImpl->source), "location", path.toStdString().c_str(), NULL);
}

void MediaPlayer::play()
{
    /* Set the pipeline to "playing" state*/
    gst_element_set_state (pImpl->pipeline, GST_STATE_PLAYING);
}

void MediaPlayer::pause()
{
    /* Set the pipeline to "pause" state*/
    gst_element_set_state (pImpl->pipeline, GST_STATE_PAUSED);
}

void MediaPlayer::stop()
{
    /* Set the pipeline to "stop" state*/
    gst_element_set_state (pImpl->pipeline, GST_STATE_NULL);
}

 

예제의 GStreamer 파이프라인

 

FLAC Audio Playback

Audio Playback.png

 

mediaplayer.tar.gz

 

https://gstreamer.freedesktop.org/documentation/application-development/basics/helloworld.html


  1. 라즈베리파이4에서 openFrameworks 예제 실행

    Date2020.12.13 Bymakersweb Views2201
    Read More
  2. Dear ImGui, 경량의 C++ 용 GUI 및 Widget 라이브러리

    Date2020.11.28 Bymakersweb Views11885
    Read More
  3. GENIVI DLT(Diagnostic Log and Trace) 활용

    Date2020.11.19 Bymakersweb Views13491
    Read More
  4. 윈도우에서 안드로이드 flutter 프로그래밍 개발환경 구축(with Visual Studio Code)

    Date2020.09.16 Bymakersweb Views2873
    Read More
  5. 가볍고 쉬운 임베디드용 그래픽 라이브러리 - LVGL

    Date2020.09.16 Bymakersweb Views6006
    Read More
  6. Qt와 GStreamer 로 작성한 flac 오디오 재생 예제

    Date2020.09.05 Bymakersweb Views2563
    Read More
  7. ZeroMQ 비동기 클라이언트/서버 패턴

    Date2020.08.13 Bymakersweb Views3962
    Read More
  8. ZeroMQ의 기본 메세지 패턴들

    Date2020.07.31 Bymakersweb Views11124
    Read More
  9. [SDL2 와 OpenGL]윈도우 생성과 2D그래픽

    Date2020.04.11 Bymakersweb Views4701
    Read More
  10. Pluma(C++ Plug-in Management Framework) 튜토리얼

    Date2019.12.07 Bymakersweb Views15661
    Read More
  11. No Image

    도커(docker)설치 및 기본 명령어

    Date2019.12.02 Bymakersweb Views2193
    Read More
  12. webOS소개 및 Raspberry Pi 3 에서 실행

    Date2019.10.13 Bymakersweb Views5550
    Read More
  13. 리눅스에서 SDL2 최신버전 컴파일과 Qt Creator로 개발환경 구성

    Date2019.10.06 Bymakersweb Views4886
    Read More
  14. 텔레그램(Telegram) Bot 개발

    Date2019.07.21 Bymakersweb Views7721
    Read More
  15. No Image

    GDBus 튜토리얼(GDBus tutorial)

    Date2019.06.30 Bymakersweb Views13512
    Read More
  16. Wayland IVI Extension 간단 리뷰

    Date2019.05.12 Bymakersweb Views3799
    Read More
Board Pagination Prev 1 2 Next
/ 2