def on_chunk_generated(self, chunk_id, tag_array): """ Regular mode on chunk be generated. """ if not self._skip_flv_head: #todo: pack flv head data data = pack_head(self._head) if self._meta_tag: data += pack_tag(self._meta_tag) if self._head.video_flag: data += pack_tag(self._first_video_tag) if self._head.audio_flag: data += pack_tag(self._first_audio_tag) self._flv_head_no = chunk_id - 1 #store head num to flv_head_no self.write_flv_head(self._flv_head_no, data) self._skip_flv_head = True data = reduce(lambda x, y: self.pack(x)+self.pack(y), tag_array) self.write_chunk(chunk_id, data) last_tag_timestamp = tag_array[-1].timestamp logger.info('src=%s,seq=%d,chunk_seq=%d,ts=%d,data_name=%s,step=%d' % (\ self._channel, self._seq, self._chunk_seq, last_tag_timestamp,\ hex(chunk_id)[2:], self._step_length)) #==============Report=================================== if hasattr(self, 'report'): #chunk_id = max(self._flv_head_no + 1, chunk_id - ( self.delay_seconds / self._step_length )) report_chunk_id = max(0, chunk_id - ( self.delay_seconds / self._step_length )) #self.report(self._channel, report_chunk_id, self._flv_head_no) #todo: mini chunk id have no report self.report(self._channel, hex(chunk_id)[2:], self._flv_head_no) #todo: mini chunk id have no report self.notify(self._channel, self._seq, self._chunk_seq, last_tag_timestamp, chunk_id, self._step_length) else: logger.warn("%s no report module" % self._channel)
def pack(self, tag): if type(tag) is str: return tag if self._start_timestamp_num > 0: tag.timestamp += self._start_timestamp_num return pack_tag(tag)