void ts::demuxer::show(void) { u_int64_t beg_pts=0,end_pts=0; for(std::map<u_int16_t,ts::stream>::const_iterator i=streams.begin();i!=streams.end();++i) { const ts::stream& s=i->second; if(s.type!=0xff) { if(s.first_pts<beg_pts || !beg_pts) beg_pts=s.first_pts; u_int64_t n=s.last_pts+s.frame_length; if(n>end_pts || !end_pts) end_pts=n; } } for(std::map<u_int16_t,ts::stream>::const_iterator i=streams.begin();i!=streams.end();++i) { u_int16_t pid=i->first; const ts::stream& s=i->second; if(s.type!=0xff) { u_int64_t end=s.last_pts+s.frame_length; u_int64_t len=end-s.first_pts; fprintf(stderr,"pid=%i (0x%.4x), ch=%i, id=%.i, type=0x%.2x (%s), stream=0x%.2x", pid,pid,s.channel,s.id,s.type,get_stream_ext(get_stream_type(s.type)),s.stream_id); if(s.frame_length>0) fprintf(stderr,", fps=%.2f",90000./(double)s.frame_length); if(len>0) fprintf(stderr,", len=%llums",len/90); if(s.frame_num>0) fprintf(stderr,", fn=%llu",s.frame_num); u_int64_t esfn=s.get_es_frame_num(); if(esfn>0) fprintf(stderr,", esfn=%llu",esfn); if(s.first_pts>beg_pts) { u_int32_t n=(u_int32_t)(s.first_pts-beg_pts)/90; fprintf(stderr,", head=+%ums",n); } if(end<end_pts) { u_int32_t n=(u_int32_t)(end_pts-end)/90; fprintf(stderr,", tail=-%ums",n); } fprintf(stderr,"\n"); } } }
int ts::demuxer::demux_ts_packet(const char* ptr) { u_int32_t timecode=0; if(hdmv) { timecode=to_int32(ptr)&0x3fffffff; ptr+=4; } const char* end_ptr=ptr+188; if(ptr[0]!=0x47) // ts sync byte return -1; u_int16_t pid=to_int(ptr+1); u_int8_t flags=to_byte(ptr+3); bool transport_error=pid&0x8000; bool payload_unit_start_indicator=pid&0x4000; bool adaptation_field_exist=flags&0x20; bool payload_data_exist=flags&0x10; u_int8_t continuity_counter=flags&0x0f; pid&=0x1fff; if(transport_error) return -2; if(pid==0x1fff || !payload_data_exist) return 0; ptr+=4; // skip adaptation field if(adaptation_field_exist) { ptr+=to_byte(ptr)+1; if(ptr>=end_ptr) return -3; } #ifdef VERBOSE if(dump==1) printf("%.4x: [%c%c%c%c] %u.%i\n", pid, transport_error?'e':'-', payload_data_exist?'p':'-', payload_unit_start_indicator?'s':'-', adaptation_field_exist?'a':'-', timecode, continuity_counter ); #endif stream& s=streams[pid]; if(!pid || (s.channel!=0xffff && s.type==0xff)) { // PSI if(payload_unit_start_indicator) { // begin of PSI table ptr++; if(ptr>=end_ptr) return -4; if(*ptr!=0x00 && *ptr!=0x02) return 0; if(end_ptr-ptr<3) return -5; u_int16_t l=to_int(ptr+1); if((l&0x3000)!=0x3000) return -6; l&=0x0fff; ptr+=3; int len=end_ptr-ptr; if(l>len) { if(l>ts::table::max_buf_len) return -7; s.psi.reset(); memcpy(s.psi.buf,ptr,len); s.psi.offset+=len; s.psi.len=l; return 0; }else end_ptr=ptr+l; }else { // next part of PSI if(!s.psi.offset) return -8; int len=end_ptr-ptr; if(len>ts::table::max_buf_len-s.psi.offset) return -9; memcpy(s.psi.buf+s.psi.offset,ptr,len); s.psi.offset+=len; if(s.psi.offset<s.psi.len) return 0; else { ptr=s.psi.buf; end_ptr=ptr+s.psi.len; } } if(!pid) { // PAT ptr+=5; if(ptr>=end_ptr) return -10; int len=end_ptr-ptr-4; if(len<0 || len%4) return -11; int n=len/4; for(int i=0;i<n;i++,ptr+=4) { u_int16_t channel=to_int(ptr); u_int16_t pid=to_int(ptr+2); if((pid&0xe000)!=0xe000) return -12; pid&=0x1fff; if(!demuxer::channel || demuxer::channel==channel) { stream& ss=streams[pid]; ss.channel=channel; ss.type=0xff; } } }else { // PMT ptr+=7; if(ptr>=end_ptr) return -13; u_int16_t info_len=to_int(ptr)&0x0fff; ptr+=info_len+2; end_ptr-=4; if(ptr>=end_ptr) return -14; while(ptr<end_ptr) { if(end_ptr-ptr<5) return -15; u_int8_t type=to_byte(ptr); u_int16_t pid=to_int(ptr+1); if((pid&0xe000)!=0xe000) return -16; pid&=0x1fff; info_len=to_int(ptr+3)&0x0fff; ptr+=5+info_len; // ignore unknown streams if(validate_type(type)) { stream& ss=streams[pid]; if(ss.channel!=s.channel || ss.type!=type) { ss.channel=s.channel; ss.type=type; ss.id=++s.id; if(!parse_only && !ss.file.is_opened()) { if(dst.length()) { ss.file.open(file::out,"%s%c%s%s",dst.c_str(),os_slash,prefix.c_str(),get_stream_ext(get_stream_type(ss.type))); fprintf(stderr,"%s%c%s%s\n",dst.c_str(),os_slash,prefix.c_str(),get_stream_ext(get_stream_type(ss.type))); } else ss.file.open(file::out,"%s%s",prefix.c_str(),get_stream_ext(get_stream_type(ss.type))); } } } } if(ptr!=end_ptr) return -18; } }else { if(s.type!=0xff) { // PES if(payload_unit_start_indicator) { s.psi.reset(); s.psi.len=9; } while(s.psi.offset<s.psi.len) { int len=end_ptr-ptr; if(len<=0) return 0; int n=s.psi.len-s.psi.offset; if(len>n) len=n; memcpy(s.psi.buf+s.psi.offset,ptr,len); s.psi.offset+=len; ptr+=len; if(s.psi.len==9) s.psi.len+=to_byte(s.psi.buf+8); } if(s.psi.len) { if(memcmp(s.psi.buf,"\x00\x00\x01",3)) return -19; s.stream_id=to_byte(s.psi.buf+3); u_int8_t flags=to_byte(s.psi.buf+7); s.frame_num++; switch(flags&0xc0) { case 0x80: // PTS only { u_int64_t pts=decode_pts(s.psi.buf+9); #ifdef VERBOSE if(dump==2) printf("%.4x: %llu\n",pid,pts); else if(dump==3) printf("%.4x: track=%.4x.%.2i, type=%.2x, stream=%.2x, pts=%llums\n",pid,s.channel,s.id,s.type,s.stream_id,pts/90); #endif if(s.dts>0 && pts>s.dts) s.frame_length=(u_int32_t)(pts-s.dts); s.dts=pts; if(pts>s.last_pts) s.last_pts=pts; if(!s.first_pts) s.first_pts=pts; } break; case 0xc0: // PTS,DTS { u_int64_t pts=decode_pts(s.psi.buf+9); u_int64_t dts=decode_pts(s.psi.buf+14); #ifdef VERBOSE if(dump==2) printf("%.4x: %llu %llu\n",pid,pts,dts); else if(dump==3) printf("%.4x: track=%.4x.%.2i, type=%.2x, stream=%.2x, pts=%llums, dts=%llums\n",pid,s.channel,s.id,s.type,s.stream_id,pts/90,dts/90); #endif if(s.dts>0 && dts>s.dts) s.frame_length=(u_int32_t)(dts-s.dts); s.dts=dts; if(pts>s.last_pts) s.last_pts=pts; if(!s.first_dts) s.first_dts=dts; } break; } if(pes_output && s.file.is_opened()) s.file.write(s.psi.buf,s.psi.len); s.psi.reset(); } if(s.frame_num) { int len=end_ptr-ptr; if(es_parse) { switch(s.type) { case 0x1b: s.frame_num_h264.parse(ptr,len); break; case 0x06: case 0x81: case 0x83: s.frame_num_ac3.parse(ptr,len); break; } } if(s.file.is_opened()) s.file.write(ptr,len); } } } return 0; }
Bonobo_Unknown bonobo_stream_extender_resolve (BonoboMonikerExtender *extender, const Bonobo_Moniker m, const Bonobo_ResolveOptions *options, const CORBA_char *display_name, const CORBA_char *requested_interface, CORBA_Environment *ev) { char *mime_type; char *requirements; Bonobo_Unknown object; Bonobo_Unknown stream; Bonobo_Persist persist; #ifdef G_ENABLE_DEBUG g_message ("Stream extender: '%s'", display_name); #endif if (!m) return CORBA_OBJECT_NIL; stream = Bonobo_Moniker_resolve (m, options, "IDL:Bonobo/Stream:1.0", ev); if (!stream) return CORBA_OBJECT_NIL; mime_type = get_stream_type (stream, ev); if (!mime_type) goto unref_stream_exception; requirements = g_strdup_printf ( "bonobo:supported_mime_types.has ('%s') AND repo_ids.has ('%s') AND " "repo_ids.has ('IDL:Bonobo/PersistStream:1.0')", mime_type, requested_interface); object = bonobo_activation_activate (requirements, NULL, 0, NULL, ev); #ifdef G_ENABLE_DEBUG g_message ("Attempt activate object satisfying '%s': %p", requirements, object); #endif g_free (requirements); if (ev->_major != CORBA_NO_EXCEPTION) goto unref_stream_exception; if (object == CORBA_OBJECT_NIL) { #ifdef G_ENABLE_DEBUG g_warning ("Can't find object satisfying requirements"); #endif CORBA_exception_set (ev, CORBA_USER_EXCEPTION, ex_Bonobo_Moniker_InterfaceNotFound, NULL); goto unref_stream_exception; } persist = Bonobo_Unknown_queryInterface ( object, "IDL:Bonobo/PersistStream:1.0", ev); if (ev->_major != CORBA_NO_EXCEPTION) goto unref_object_exception; if (persist != CORBA_OBJECT_NIL) { Bonobo_PersistStream_load ( persist, stream, (const Bonobo_Persist_ContentType) mime_type, ev); bonobo_object_release_unref (persist, ev); bonobo_object_release_unref (stream, ev); return bonobo_moniker_util_qi_return ( object, requested_interface, ev); } g_free (mime_type); unref_object_exception: bonobo_object_release_unref (object, ev); unref_stream_exception: bonobo_object_release_unref (stream, ev); return CORBA_OBJECT_NIL; }
std::shared_ptr<pipeline_profile> pipeline_config::resolve(std::shared_ptr<pipeline> pipe) { std::lock_guard<std::mutex> lock(_mtx); _resolved_profile.reset(); auto requested_device = resolve_device_requests(pipe); std::vector<stream_profile> resolved_profiles; //if the user requested all streams, or if the requested device is from file and the user did not request any stream if (_enable_all_streams || (!_device_request.filename.empty() && _stream_requests.empty())) { if (!requested_device) { requested_device = get_first_or_default_device(pipe); } util::config config; config.enable_all(util::best_quality); _resolved_profile = std::make_shared<pipeline_profile>(requested_device, config, _device_request.record_output); return _resolved_profile; } else { util::config config; //If the user did not request anything, give it the default if (_stream_requests.empty()) { if (!requested_device) { requested_device = get_first_or_default_device(pipe); } auto default_profiles = get_default_configuration(requested_device); for (auto prof : default_profiles) { auto p = dynamic_cast<video_stream_profile*>(prof.get()); if (!p) { LOG_ERROR("prof is not video_stream_profile"); throw std::logic_error("Failed to resolve request. internal error"); } config.enable_stream(p->get_stream_type(), p->get_stream_index(), p->get_width(), p->get_height(), p->get_format(), p->get_framerate()); } _resolved_profile = std::make_shared<pipeline_profile>(requested_device, config, _device_request.record_output); return _resolved_profile; } else { //User enabled some stream, enable only them for(auto&& req : _stream_requests) { auto r = req.second; config.enable_stream(r.stream, r.stream_index, r.width, r.height, r.format, r.fps); } auto devs = pipe->get_context()->query_devices(); if (devs.empty()) { auto dev = get_first_or_default_device(pipe); _resolved_profile = std::make_shared<pipeline_profile>(dev, config, _device_request.record_output); return _resolved_profile; } else { for (auto dev_info : devs) { try { auto dev = dev_info->create_device(); _resolved_profile = std::make_shared<pipeline_profile>(dev, config, _device_request.record_output); return _resolved_profile; } catch (...) {} } } throw std::runtime_error("Failed to resolve request. No device found that satisfies all requirements"); } } assert(0); //Unreachable code }
rs_stream rs_get_detached_frame_stream_type(const rs_frame_ref * frame_ref, rs_error ** error) try { VALIDATE_NOT_NULL(frame_ref); return frame_ref->get_stream_type(); }