TizenRT Public API  v2.0 M2
HttpInputDataSource.h
Go to the documentation of this file.
1 /* ****************************************************************
2  *
3  * Copyright 2018 Samsung Electronics All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  ******************************************************************/
18 
29 #ifndef __MEDIA_HTTPINPUTDATASOURCE_H
30 #define __MEDIA_HTTPINPUTDATASOURCE_H
31 
32 #include <media/InputDataSource.h>
34 #include <curl/curl.h>
35 #include <curl/easy.h>
36 #include <pthread.h>
37 #include <thread>
38 #include <mutex>
39 #include <condition_variable>
40 #include <string>
41 
42 namespace media {
43 namespace stream {
44 
45 class HttpStream;
46 class StreamBuffer;
47 class StreamBufferReader;
48 class StreamBufferWriter;
49 
57 {
58 public:
65  HttpInputDataSource() = delete;
71  virtual ~HttpInputDataSource();
78  HttpInputDataSource(const std::string &url);
91 
98  bool isPrepared() override;
105  bool open() override;
112  bool close() override;
121  ssize_t read(unsigned char *buf, size_t size) override;
122 
123 public:
127  void onBufferOverrun() override;
128  void onBufferUnderrun() override;
129  void onBufferUpdated(ssize_t change, size_t current) override;
130 
131 private:
132  static size_t HeaderCallback(char *data, size_t size, size_t nmemb, void *userp);
133  static size_t WriteCallback(char *data, size_t size, size_t nmemb, void *userp);
134  static void *workerMain(void *arg);
135 
136 private:
137  std::string mContentType;
138  std::string mUrl;
139  pthread_t mThread;
140  std::mutex mMutex;
141  std::condition_variable mCondv;
142  bool mIsHeaderReceived;
143  bool mIsDataReceived;
144  std::shared_ptr<HttpStream> mHttpStream;
145  std::shared_ptr<StreamBuffer> mStreamBuffer;
146  std::shared_ptr<StreamBufferReader> mBufferReader;
147  std::shared_ptr<StreamBufferWriter> mBufferWriter;
148 };
149 
150 } // namespace stream
151 } // namespace media
152 
153 #endif // __MEDIA_HTTPINPUTDATASOURCE_H
154  // end of MEDIA group
bool isPrepared() override
Whether http source is ready to be read.
void onBufferUpdated(ssize_t change, size_t current) override
Called when buffer updated.
bool close() override
Close the http source.
virtual ~HttpInputDataSource()
Deconstructs an HttpInputDataSource.
void onBufferUnderrun() override
Called when buffer underrun.
Media BufferObserverInterface APIs.
bool open() override
Open the http source.
ssize_t read(unsigned char *buf, size_t size) override
Read the audio stream data.
HttpInputDataSource()=delete
Constructs an empty HttpInputDataSource.
HttpInputDataSource & operator=(const HttpInputDataSource &source)
Operator= for HttpInputDataSource.