OSDN Git Service

EPG予約、キーワード予約の不具合修正
[iptd/iPTd.git] / src / ry0 / iPTd / HTTPLiveStreaming.cpp
1 //
2 //
3 //
4
5 #define DBG_LEVEL 3
6 #include "Raym/Log.h"
7
8 #include "HTTPLiveStreaming.h"
9
10 using namespace Raym;
11
12 namespace ry0
13 {
14 namespace iPTd
15 {
16
17 HTTPLiveStreaming::HTTPLiveStreaming()
18 {
19     DebugLog2("HTTPLiveStreaming::HTTPLiveStreaming()");
20
21     _source      = NULL;
22     _output_path = NULL;
23     _index_name  = NULL;
24     _base_url    = NULL;
25     _counter     = 0;
26 }
27
28 HTTPLiveStreaming::~HTTPLiveStreaming()
29 {
30     RELEASE(_source);
31     RELEASE(_output_path);
32     RELEASE(_index_name);
33     RELEASE(_base_url);
34
35     DebugLog2("HTTPLiveStreaming::~HTTPLiveStreaming()");
36 }
37
38 HTTPLiveStreaming *HTTPLiveStreaming::alloc()
39 {
40     DebugLog2("HTTPLiveStreaming::alloc()");
41
42     return new HTTPLiveStreaming();
43 }
44
45 HTTPLiveStreaming *HTTPLiveStreaming::init()
46 {
47     DebugLog2("HTTPLiveStreaming::init()");
48
49     if (FFmpeg::init() == NULL)
50     {
51         release();
52         return NULL;
53     }
54
55     return this;
56 }
57
58 HTTPLiveStreaming *HTTPLiveStreaming::retain()
59 {
60     DebugLog2("HTTPLiveStreaming::retain()");
61
62     FFmpeg::retain();
63     return this;
64 }
65
66 HTTPLiveStreaming *HTTPLiveStreaming::autorelease()
67 {
68     DebugLog2("HTTPLiveStreaming::autorelease()");
69
70     FFmpeg::autorelease();
71     return this;
72 }
73
74 void HTTPLiveStreaming::setSource(String *source)
75 {
76     DebugLog2("HTTPLiveStreaming::setSource()");
77
78     RELEASE(_source);
79     if (source != NULL)
80     {
81         _source = source->retain();
82     }
83 }
84
85 void HTTPLiveStreaming::setOutputPath(String *output_path)
86 {
87     DebugLog2("HTTPLiveStreaming::setOutputPath()");
88
89     RELEASE(_output_path);
90     if (output_path != NULL)
91     {
92         _output_path = output_path->retain();
93     }
94 }
95
96 String *HTTPLiveStreaming::outputPath()
97 {
98     return _output_path;
99 }
100
101 void HTTPLiveStreaming::setIndexName(String *index_name)
102 {
103     DebugLog2("HTTPLiveStreaming::setIndexName()");
104
105     RELEASE(_index_name);
106     if (index_name != NULL)
107     {
108         _index_name = index_name->retain();
109     }
110 }
111
112 bool HTTPLiveStreaming::start()
113 {
114     DebugLog2("%s", __FUNCTION__);
115
116     if ((_output_path == NULL) || (_source == NULL) || (_index_name == NULL))
117     {
118         return false;
119     }
120
121     DebugLog2("output path: %s", _output_path->cString());
122     DebugLog2("source: %s", _source->cString());
123     DebugLog2("index: %s", _index_name->cString());
124
125     String *index_path = indexPath();
126     if (index_path != NULL)
127     {
128         FileManager::defaultManager()->removeItemAtPath(index_path, NULL);
129     }
130
131     //
132     // %>ffmpeg -i C:\WORK\20151024_211758_086_PT2@050000-01.ts -vcodec libx264 -r 30000/1001 -aspect 16:9 -s 1280x720
133     // -bufsize 20000k -maxrate 25000k -acodec libvo_aacenc -ac
134     // 2 -ar 48000 -ab 128k -threads 2 -f segment -segment_format mpegts -segment_time 10 -segment_list index.m3u8 test%03d.ts
135     //
136
137     // 暫定処理
138 //    Array *args = STR_ARRAY("-i",              "C:\\WORK\\20151024_211758_086_PT2@050000-01.ts",
139 //    Array *args = STR_ARRAY("-i",              "udp://0.0.0.0:51027",
140 #if 0
141     Array *arg2 = STR_ARRAY("-i",              "udp://@0.0.0.0:51027?overrun_nonfatal=1&fifo_size=50000000",
142 //    Array *args = STR_ARRAY("-i",              "udp://@51027?overrun_nonfatal=1&fifo_size=50000000",
143                               "-vcodec",         "libx264",
144                               "-r",              "30000/1001",
145                               "-aspect",         "16:9",
146                               "-s",              "1280x720",
147                               "-bufsize",        "20000k",
148                               "-maxrate",        "25000k",
149                               "-acodec",         "libvo_aacenc",
150                               "-ac",             "2",
151                               "-ar",             "48000",
152                               "-ab",             "128k",
153                               "-threads",        "2",
154 //                              "-programid",      "1074",
155                               "-f",              "segment",
156                               "-segment_format", "mpegts",
157                               "-segment_time",   "10",
158                               "-segment_list",   "C:\\WORK\\www\\index.m3u8",
159                               "C:\\WORK\\www\\test%03d.ts",
160                               NULL);
161 #endif
162
163     Array *args = Array::arrayWithCapacity(0);
164     args->addObject(String::stringWithUTF8String("-i"));
165 //    args->addObject(String::stringWithUTF8String("udp://@0.0.0.0:51027?overrun_nonfatal=1&fifo_size=50000000"));
166     if (_source->hasPrefix("udp://"))
167     {
168         args->addObject(String::stringWithFormat("%s?overrun_nonfatal=1&fifo_size=50000000", _source->cString()));
169     }
170     else
171     {
172         args->addObject(String::stringWithUTF8String("hogehoge"));
173     }
174
175     args->addObject(String::stringWithUTF8String("-vcodec"));
176     args->addObject(String::stringWithUTF8String("libx264"));
177     args->addObject(String::stringWithUTF8String("-r"));
178     args->addObject(String::stringWithUTF8String("30000/1001"));
179     args->addObject(String::stringWithUTF8String("-aspect"));
180     args->addObject(String::stringWithUTF8String("16:9"));
181 //    args->addObject(String::stringWithUTF8String("-s"));
182 //    args->addObject(String::stringWithUTF8String("1280x720"));
183     args->addObject(String::stringWithUTF8String("-g"));
184     args->addObject(String::stringWithUTF8String("150"));
185     args->addObject(String::stringWithUTF8String("-bufsize"));
186     args->addObject(String::stringWithUTF8String("20000k"));
187     args->addObject(String::stringWithUTF8String("-maxrate"));
188     args->addObject(String::stringWithUTF8String("25000k"));
189     args->addObject(String::stringWithUTF8String("-acodec"));
190     args->addObject(String::stringWithUTF8String("libvo_aacenc"));
191     args->addObject(String::stringWithUTF8String("-ac"));
192     args->addObject(String::stringWithUTF8String("2"));
193     args->addObject(String::stringWithUTF8String("-ar"));
194     args->addObject(String::stringWithUTF8String("48000"));
195     args->addObject(String::stringWithUTF8String("-ab"));
196     args->addObject(String::stringWithUTF8String("128k"));
197     args->addObject(String::stringWithUTF8String("-threads"));
198     args->addObject(String::stringWithUTF8String("2"));
199     args->addObject(String::stringWithUTF8String("-f"));
200     args->addObject(String::stringWithUTF8String("segment"));
201     args->addObject(String::stringWithUTF8String("-segment_format"));
202     args->addObject(String::stringWithUTF8String("mpegts"));
203     args->addObject(String::stringWithUTF8String("-segment_time"));
204     args->addObject(String::stringWithUTF8String("10"));
205
206     args->addObject(String::stringWithUTF8String("-segment_list"));
207     args->addObject(_output_path->stringByAppendingPathComponent(String::stringWithFormat("%s.m3u8", _index_name->cString())));
208
209     args->addObject(_output_path->stringByAppendingPathComponent(String::stringWithUTF8String("streaming-%05d.ts")));
210
211     setArguments(args);
212
213     return FFmpeg::start();
214 }
215
216 String * HTTPLiveStreaming::indexPath()
217 {
218     if ((_output_path == NULL) || (_index_name == NULL))
219     {
220         return false;
221     }
222     return _output_path->stringByAppendingPathComponent(String::stringWithFormat("%s.m3u8", _index_name->cString()));
223 }
224
225
226 bool HTTPLiveStreaming::readLine(String *line)
227 {
228     if (line != NULL)
229     {
230 //        DebugLog3("ffmpeg: %s", line->cString());
231     }
232     return false;
233 }
234
235 const char *HTTPLiveStreaming::className()
236 {
237     return "HTTPLiveStreaming";
238 }
239
240 } // iPTd
241 } // ry0