winlin

fix bug to accept FFMPEG streaming

@@ -74,9 +74,11 @@ extern ILogContext* log_context; @@ -74,9 +74,11 @@ extern ILogContext* log_context;
74 #define srs_error(msg, ...) printf("[%s][%d][error][%s] ", log_context->format_time(), log_context->get_id(), __PRETTY_FUNCTION__);printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n") 74 #define srs_error(msg, ...) printf("[%s][%d][error][%s] ", log_context->format_time(), log_context->get_id(), __PRETTY_FUNCTION__);printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n")
75 #endif 75 #endif
76 76
77 -#if 0 77 +#if 1
78 #undef srs_verbose 78 #undef srs_verbose
79 #define srs_verbose(msg, ...) (void)0 79 #define srs_verbose(msg, ...) (void)0
  80 +#endif
  81 +#if 1
80 #undef srs_info 82 #undef srs_info
81 #define srs_info(msg, ...) (void)0 83 #define srs_info(msg, ...) (void)0
82 #endif 84 #endif
@@ -94,6 +94,8 @@ SrsSource::SrsSource(std::string _stream_url) @@ -94,6 +94,8 @@ SrsSource::SrsSource(std::string _stream_url)
94 { 94 {
95 stream_url = _stream_url; 95 stream_url = _stream_url;
96 cache_metadata = NULL; 96 cache_metadata = NULL;
  97 + cache_sh_video = NULL;
  98 + cache_sh_audio = NULL;
97 } 99 }
98 100
99 SrsSource::~SrsSource() 101 SrsSource::~SrsSource()
@@ -106,6 +108,8 @@ SrsSource::~SrsSource() @@ -106,6 +108,8 @@ SrsSource::~SrsSource()
106 consumers.clear(); 108 consumers.clear();
107 109
108 srs_freep(cache_metadata); 110 srs_freep(cache_metadata);
  111 + srs_freep(cache_sh_video);
  112 + srs_freep(cache_sh_audio);
109 } 113 }
110 114
111 int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata) 115 int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata)
@@ -183,6 +187,11 @@ int SrsSource::on_audio(SrsCommonMessage* audio) @@ -183,6 +187,11 @@ int SrsSource::on_audio(SrsCommonMessage* audio)
183 } 187 }
184 } 188 }
185 srs_info("dispatch audio success."); 189 srs_info("dispatch audio success.");
  190 +
  191 + if (!cache_sh_audio) {
  192 + srs_freep(cache_sh_audio);
  193 + cache_sh_audio = msg->copy();
  194 + }
186 195
187 return ret; 196 return ret;
188 } 197 }
@@ -213,20 +222,40 @@ int SrsSource::on_video(SrsCommonMessage* video) @@ -213,20 +222,40 @@ int SrsSource::on_video(SrsCommonMessage* video)
213 } 222 }
214 } 223 }
215 srs_info("dispatch video success."); 224 srs_info("dispatch video success.");
  225 +
  226 + if (!cache_sh_video) {
  227 + srs_freep(cache_sh_video);
  228 + cache_sh_video = msg->copy();
  229 + }
216 230
217 return ret; 231 return ret;
218 } 232 }
219 233
220 int SrsSource::create_consumer(SrsConsumer*& consumer) 234 int SrsSource::create_consumer(SrsConsumer*& consumer)
221 { 235 {
  236 + int ret = ERROR_SUCCESS;
  237 +
222 consumer = new SrsConsumer(); 238 consumer = new SrsConsumer();
223 consumers.push_back(consumer); 239 consumers.push_back(consumer);
224 240
225 - if (!cache_metadata) {  
226 - srs_info("no metadata found.");  
227 - return ERROR_SUCCESS; 241 + if (cache_metadata && (ret = consumer->enqueue(cache_metadata->copy())) != ERROR_SUCCESS) {
  242 + srs_error("dispatch metadata failed. ret=%d", ret);
  243 + return ret;
228 } 244 }
  245 + srs_info("dispatch metadata success");
229 246
230 - return consumer->enqueue(cache_metadata->copy()); 247 + if (cache_sh_video && (ret = consumer->enqueue(cache_sh_video->copy())) != ERROR_SUCCESS) {
  248 + srs_error("dispatch video sequence header failed. ret=%d", ret);
  249 + return ret;
  250 + }
  251 + srs_info("dispatch video sequence header success");
  252 +
  253 + if (cache_sh_audio && (ret = consumer->enqueue(cache_sh_audio->copy())) != ERROR_SUCCESS) {
  254 + srs_error("dispatch audio sequence header failed. ret=%d", ret);
  255 + return ret;
  256 + }
  257 + srs_info("dispatch audio sequence header success");
  258 +
  259 + return ret;
231 } 260 }
232 261
@@ -82,6 +82,10 @@ private: @@ -82,6 +82,10 @@ private:
82 std::vector<SrsConsumer*> consumers; 82 std::vector<SrsConsumer*> consumers;
83 private: 83 private:
84 SrsSharedPtrMessage* cache_metadata; 84 SrsSharedPtrMessage* cache_metadata;
  85 + // the cached video sequence header.
  86 + SrsSharedPtrMessage* cache_sh_video;
  87 + // the cached audio sequence header.
  88 + SrsSharedPtrMessage* cache_sh_audio;
85 public: 89 public:
86 SrsSource(std::string _stream_url); 90 SrsSource(std::string _stream_url);
87 virtual ~SrsSource(); 91 virtual ~SrsSource();