video_capture_vlc
VlcCapture.h
Go to the documentation of this file.
1 /*
2  * VlcCapture.h
3  *
4  * Created on: 03.03.2014
5  * Author: planthaber
6  */
7 
8 #ifndef VLCCAPTURE_H_
9 #define VLCCAPTURE_H_
10 
11 
12 //https://wiki.videolan.org/Stream_to_memory_%28smem%29_tutorial/
13 
14 #include <stdio.h>
15 #include <stdint.h>
16 #include <string>
17 
18 #include <vlc/vlc.h>
19 
20 #include <pthread.h>
21 #include <opencv2/opencv.hpp>
22 
23 
27 void pf_video_prerender_callback ( void* p_video_data, uint8_t** pp_pixel_buffer, size_t size );
28 
32 void pf_video_postrender_callback ( void* p_video_data, uint8_t* p_pixel_buffer, int width, int height, int pixel_pitch, size_t size, libvlc_time_t pts );
33 
34 void pf_audio_prerender_callback ( void* p_audio_data, uint8_t** pp_pcm_buffer, size_t size );
35 void pf_audio_postrender_callback ( void* p_audio_data, uint8_t* p_pcm_buffer, unsigned int channels, unsigned int rate, unsigned int nb_samples, unsigned int bits_per_sample, size_t size, libvlc_time_t pts );
36 
37 
39  public:
40  /*
41  * get called when a new image is arrived
42  */
43  virtual void imageCallback()=0;
44 };
45 
46 class VlcCapture {
47 public:
48  VlcCapture(std::string url = "", int input_buffer_ms = 10);
49  virtual ~VlcCapture();
50 
51 
52  void open(std::string &url);
53 
54  //bool grab();
55 
56  //bool retrieve();
57 
58  bool read(cv::Mat &image);
59 
60  int start();
61 
62  void stop();
63 
64 
65  pthread_mutex_t imagemutex;
66 
67  static pthread_mutex_t callbackmutex;
68 
70 
71  //cv::Mat imagebuf;
72  uint8_t* buffer;
73  unsigned int buffersize;
74 
76 
77  std::string _url;
78 
79 
80  void prerender_callback(void* p_video_data, uint8_t** pp_pixel_buffer, size_t size);
81  void postrender_callback(void* p_video_data, uint8_t* p_pixel_buffer, int width, int height, int pixel_pitch, size_t size, libvlc_time_t pts );
82 
83  std::vector<VlcCaptureConsumer*> callbacks;
84 private:
85 
86 
87 
88  int buffer_ms;
89 
90  //options
91  char smem_options[256];
92 
93  //callback pointer addess string
94  char str_smem_vid_prerender[100], str_smem_vid_postrender[100];
95  char str_smem_aud_prerender[100], str_smem_aud_postrender[100];
96  char str_smem_data[100],str_netbuf[100];
97 
98  libvlc_instance_t *vlc;
99  libvlc_media_player_t *vlcmp;
100  libvlc_media_t *vlcm;
101 
102 };
103 
104 #endif /* VLCTOMEMORY_H_ */
VlcCapture(std::string url="", int input_buffer_ms=10)
Definition: VlcCapture.cpp:11
virtual void imageCallback()=0
unsigned int buffersize
Definition: VlcCapture.h:73
std::vector< VlcCaptureConsumer * > callbacks
Definition: VlcCapture.h:83
void open(std::string &url)
Definition: VlcCapture.cpp:46
int start()
Definition: VlcCapture.cpp:95
void pf_audio_postrender_callback(void *p_audio_data, uint8_t *p_pcm_buffer, unsigned int channels, unsigned int rate, unsigned int nb_samples, unsigned int bits_per_sample, size_t size, libvlc_time_t pts)
Definition: VlcCapture.cpp:141
std::string _url
Definition: VlcCapture.h:77
bool imageAvailable
Definition: VlcCapture.h:75
void postrender_callback(void *p_video_data, uint8_t *p_pixel_buffer, int width, int height, int pixel_pitch, size_t size, libvlc_time_t pts)
bool read(cv::Mat &image)
Definition: VlcCapture.cpp:74
int width
Definition: VlcCapture.h:69
int height
Definition: VlcCapture.h:69
void pf_video_prerender_callback(void *p_video_data, uint8_t **pp_pixel_buffer, size_t size)
Definition: VlcCapture.cpp:103
void prerender_callback(void *p_video_data, uint8_t **pp_pixel_buffer, size_t size)
uint8_t * buffer
Definition: VlcCapture.h:72
Definition: VlcCapture.h:46
static pthread_mutex_t callbackmutex
Definition: VlcCapture.h:67
void stop()
Definition: VlcCapture.cpp:99
void pf_video_postrender_callback(void *p_video_data, uint8_t *p_pixel_buffer, int width, int height, int pixel_pitch, size_t size, libvlc_time_t pts)
Definition: VlcCapture.cpp:119
virtual ~VlcCapture()
Definition: VlcCapture.cpp:68
pthread_mutex_t imagemutex
Definition: VlcCapture.h:65
void pf_audio_prerender_callback(void *p_audio_data, uint8_t **pp_pcm_buffer, size_t size)
Definition: VlcCapture.cpp:133
Definition: VlcCapture.h:38