TIMELIB_API __int64 TIMELIB_CALL tlCurrentTimestamp(bool in_local_time) { __int64 result = 0; #ifdef _WIN32 struct _timeb now; _ftime_s(&now); result = (now.time * I64C(1000000)) + (now.millitm * 1000); #else struct timeval tv; if (gettimeofday(&tv, NULL) == 0) { result = (tv.tv_sec * I64C(1000000)) + tv.tv_usec; } #endif if (in_local_time) { result += (static_cast<__int64>(tlLocalTimeZoneOffset()) * I64C(1000000)); } return result; }
unsigned __int64 CBlobWriteNode::makeBlobId(offset_t nodepos, unsigned offset) { assertex(nodepos != 0); assertex((nodepos & I64C(0xffff000000000000)) == 0); assertex((offset & 0xf) == 0); return (((unsigned __int64) offset) << 44) | nodepos; }
void testBitsetHelpers() { CPPUNIT_ASSERT_EQUAL(0U, countTrailingUnsetBits(1U)); CPPUNIT_ASSERT_EQUAL(31U, countLeadingUnsetBits(1U)); CPPUNIT_ASSERT_EQUAL(1U, getMostSignificantBit(1U)); CPPUNIT_ASSERT_EQUAL(4U, countTrailingUnsetBits(0x110U)); CPPUNIT_ASSERT_EQUAL(23U, countLeadingUnsetBits(0x110U)); CPPUNIT_ASSERT_EQUAL(9U, getMostSignificantBit(0x110U)); CPPUNIT_ASSERT_EQUAL(0U, countTrailingUnsetBits(0xFFFFFFFFU)); CPPUNIT_ASSERT_EQUAL(0U, countLeadingUnsetBits(0xFFFFFFFFU)); CPPUNIT_ASSERT_EQUAL(32U, getMostSignificantBit(0xFFFFFFFFU)); CPPUNIT_ASSERT_EQUAL(52U, countTrailingUnsetBits(I64C(0x1010000000000000U))); }
/***************************************************************************** * reduce a fraction * (adapted from libavcodec, author Michael Niedermayer <*****@*****.**>) *****************************************************************************/ vlc_bool_t vlc_ureduce( unsigned *pi_dst_nom, unsigned *pi_dst_den, uint64_t i_nom, uint64_t i_den, uint64_t i_max ) { vlc_bool_t b_exact = 1; uint64_t i_gcd; if( i_den == 0 ) { *pi_dst_nom = 0; *pi_dst_den = 1; return 1; } i_gcd = GCD( i_nom, i_den ); i_nom /= i_gcd; i_den /= i_gcd; if( i_max == 0 ) i_max = I64C(0xFFFFFFFF); if( i_nom > i_max || i_den > i_max ) { uint64_t i_a0_num = 0, i_a0_den = 1, i_a1_num = 1, i_a1_den = 0; b_exact = 0; for( ; ; ) { uint64_t i_x = i_nom / i_den; uint64_t i_a2n = i_x * i_a1_num + i_a0_num; uint64_t i_a2d = i_x * i_a1_den + i_a0_den; if( i_a2n > i_max || i_a2d > i_max ) break; i_nom %= i_den; i_a0_num = i_a1_num; i_a0_den = i_a1_den; i_a1_num = i_a2n; i_a1_den = i_a2d; if( i_nom == 0 ) break; i_x = i_nom; i_nom = i_den; i_den = i_x; } i_nom = i_a1_num; i_den = i_a1_den; } *pi_dst_nom = i_nom; *pi_dst_den = i_den; return b_exact; }
/**************************************************************************** * DecodeBlock: the whole thing **************************************************************************** * This function must be fed with complete frames. ****************************************************************************/ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) { decoder_sys_t *p_sys = p_dec->p_sys; block_t *p_block; void *p_buf; if( !pp_block || !*pp_block ) return NULL; p_block = *pp_block; if( !p_sys->i_pts && !p_block->i_pts && !p_block->i_dts ) { /* We've just started the stream, wait for the first PTS. */ block_Release( p_block ); return NULL; } /* Date management */ if( p_block->i_pts > 0 || p_block->i_dts > 0 ) { if( p_block->i_pts > 0 ) p_sys->i_pts = p_block->i_pts; else if( p_block->i_dts > 0 ) p_sys->i_pts = p_block->i_dts; } if( p_block->i_buffer < p_sys->i_raw_size ) { msg_Warn( p_dec, "invalid frame size (%d < %d)", p_block->i_buffer, p_sys->i_raw_size ); block_Release( p_block ); return NULL; } if( p_sys->b_packetizer ) { p_buf = SendFrame( p_dec, p_block ); } else { p_buf = DecodeFrame( p_dec, p_block ); } /* Date management: 1 frame per packet */ p_sys->i_pts += ( I64C(1000000) * 1.0 / 25 /*FIXME*/ ); *pp_block = NULL; return p_buf; }
/**************************************************************************** * HttpCallback: Return the index.html file ****************************************************************************/ static int HttpCallback( httpd_file_sys_t *p_args, httpd_file_t *p_file, uint8_t *_psz_request, uint8_t **_pp_data, int *pi_data ) { access_sys_t *p_sys = p_args->p_access->p_sys; char *psz_request = (char *)_psz_request; char **pp_data = (char **)_pp_data; vlc_mutex_lock( &p_sys->httpd_mutex ); p_sys->i_httpd_timeout = mdate() + I64C(3000000); /* 3 s */ p_sys->psz_request = psz_request; p_sys->b_request_frontend_info = VLC_TRUE; if ( p_sys->i_ca_handle ) { p_sys->b_request_mmi_info = VLC_TRUE; } else { p_sys->psz_mmi_info = strdup( "No available CAM interface\n" ); } do { vlc_cond_wait( &p_sys->httpd_cond, &p_sys->httpd_mutex ); } while ( p_sys->b_request_frontend_info || p_sys->b_request_mmi_info ); p_sys->i_httpd_timeout = 0; vlc_mutex_unlock( &p_sys->httpd_mutex ); *pi_data = strlen( psz_constant_header ) + strlen( p_sys->psz_mmi_info ) + strlen( psz_constant_middle ) + strlen( p_sys->psz_frontend_info ) + strlen( psz_constant_footer ) + 1; *pp_data = malloc( *pi_data ); sprintf( *pp_data, "%s%s%s%s%s", psz_constant_header, p_sys->psz_mmi_info, psz_constant_middle, p_sys->psz_frontend_info, psz_constant_footer ); free( p_sys->psz_frontend_info ); free( p_sys->psz_mmi_info ); return VLC_SUCCESS; }
/***************************************************************************** * GtkDisplayDate: display stream date ***************************************************************************** * This function displays the current date related to the position in * the stream. It is called whenever the slider changes its value. * The lock has to be taken before you call the function. *****************************************************************************/ void E_(GtkDisplayDate)( GtkAdjustment *p_adj, gpointer userdata ) { intf_thread_t *p_intf; p_intf = (intf_thread_t*) userdata; if (p_intf == NULL) return; if( p_intf->p_sys->p_input ) { char psz_time[ MSTRTIME_MAX_SIZE ]; int64_t i_seconds; i_seconds = var_GetTime( p_intf->p_sys->p_input, "time" ) / I64C(1000000 ); secstotimestr( psz_time, i_seconds ); gtk_label_set_text( GTK_LABEL( p_intf->p_sys->p_slider_label ), psz_time ); } }
gulong GetUptimeMs() { char buf[BUF_128]; int fd = -1; size_t n; double uptime = 0; if(( fd = open( "/proc/uptime", O_RDONLY )) < 0) return -1; n = read( fd, buf, BUF_128 - 1 ); if ( n == BUF_128 - 1 || n <= 0 ) { close(fd); return -1; } close(fd); buf[n] = '\0'; sscanf(buf, "%lf", &uptime ); return I64C(uptime*1000); }
CReadSeq(int _fh, offset_t _offset, unsigned maxrecs, size32_t _size, size32_t _bufsize, bool _compressed) { assertex(_size); fh = _fh; size = _size; bufSize = (_bufsize==(unsigned) -1)?DEFAULTBUFFERSIZE:_bufsize; bytesInBuffer = 0; startpos = _offset; nextbufpos = _offset; compressed = ((size<bufSize/2)&&(size>=MINCOMPRESSEDROWSIZE)&&(size<=MAXCOMPRESSEDROWSIZE))?_compressed:false; if (compressed) { maxcompsize = size+size/3+3; // migger than needed buffer = (char *) malloc(bufSize+size); prev = buffer+bufSize; } else buffer = (char *) malloc(bufSize); ptr = buffer; first = true; endpos = (maxrecs!=(unsigned)-1)?(_offset+(offset_t)maxrecs*(offset_t)_size):I64C(0x7ffffffffff); }
static mtime_t ObjectGarbageCollector( playlist_t *p_playlist, int i_type, mtime_t destroy_date ) { vlc_object_t *p_obj; if( destroy_date > mdate() ) return destroy_date; if( destroy_date == 0 ) { /* give a little time */ return mdate() + I64C(1000000); } else { while( ( p_obj = vlc_object_find( p_playlist, i_type, FIND_CHILD ) ) ) { if( p_obj->p_parent != (vlc_object_t*)p_playlist ) { /* only first child (ie unused) */ vlc_object_release( p_obj ); break; } if( i_type == VLC_OBJECT_VOUT ) { msg_Dbg( p_playlist, "garbage collector destroying 1 vout" ); vlc_object_detach( p_obj ); vlc_object_release( p_obj ); vout_Destroy( (vout_thread_t *)p_obj ); } else if( i_type == VLC_OBJECT_SOUT ) { vlc_object_release( p_obj ); sout_DeleteInstance( (sout_instance_t*)p_obj ); } } return 0; } }
void TransferServer::appendTransformed(unsigned chunkIndex, ITransformer * input) { OutputProgress & curProgress = progress.item(chunkIndex); PartitionPoint & curPartition = partition.item(chunkIndex); input->beginTransform(out); const offset_t startInputOffset = curPartition.inputOffset; const offset_t startOutputOffset = curPartition.outputOffset; loop { unsigned gotLength = input->getBlock(out); totalLengthRead += gotLength; if (gpfFrequency || !gotLength || ((unsigned)(msTick() - lastTick)) > updateFrequency) { out->flush(); lastTick = msTick(); offset_t outputOffset = out->tell(); offset_t inputOffset = input->tell(); if (totalLengthToRead) LOG(MCdebugProgress, unknownJob, "Progress: %d%% done. [%" I64F "u]", (unsigned)(totalLengthRead*100/totalLengthToRead), (unsigned __int64)totalLengthRead); curProgress.status = (gotLength == 0) ? OutputProgress::StatusCopied : OutputProgress::StatusActive; curProgress.inputLength = input->tell()-startInputOffset; curProgress.outputLength = out->tell()-startOutputOffset; if (crcOut) curProgress.outputCRC = crcOut->getCRC(); if (calcInputCRC) curProgress.hasInputCRC = input->getInputCRC(curProgress.inputCRC); sendProgress(curProgress); } if (!gotLength) break; if (blockDelay) MilliSleep(blockDelay); else if (throttleNicSpeed) { unsigned delay = (unsigned)(((unsigned __int64)gotLength*10*1000*(numParallelSlaves-1))/(throttleNicSpeed * I64C(0x100000))); if (delay) MilliSleep(delay*(getRandom()%100)/50); } #ifdef _WIN32 if (gpfFrequency && ((rand() % gpfFrequency) == 0)) { LOG(MCdebugInfo, unknownJob, "About to crash...."); *(char *)0 = 0; } #endif } input->endTransform(out); }
/**************************************************************************** * EncodeVideo: the whole thing ****************************************************************************/ static block_t *EncodeVideo( encoder_t *p_enc, picture_t *p_pict ) { encoder_sys_t *p_sys = p_enc->p_sys; AVFrame frame; int i_out, i_plane; #if LIBAVCODEC_BUILD >= 4702 if ( !p_sys->b_inited && p_enc->i_threads >= 1 ) { struct thread_context_t ** pp_contexts; int i; p_sys->b_inited = 1; pp_contexts = malloc( sizeof(struct thread_context_t *) * p_enc->i_threads ); p_sys->p_context->thread_opaque = (void *)pp_contexts; for ( i = 0; i < p_enc->i_threads; i++ ) { pp_contexts[i] = vlc_object_create( p_enc, sizeof(struct thread_context_t) ); pp_contexts[i]->p_context = p_sys->p_context; vlc_mutex_init( p_enc, &pp_contexts[i]->lock ); vlc_cond_init( p_enc, &pp_contexts[i]->cond ); pp_contexts[i]->b_work = 0; pp_contexts[i]->b_done = 0; if ( vlc_thread_create( pp_contexts[i], "encoder", FfmpegThread, VLC_THREAD_PRIORITY_VIDEO, VLC_FALSE ) ) { msg_Err( p_enc, "cannot spawn encoder thread, expect to die soon" ); return NULL; } } p_sys->p_context->execute = FfmpegExecute; } #endif memset( &frame, 0, sizeof( AVFrame ) ); for( i_plane = 0; i_plane < p_pict->i_planes; i_plane++ ) { frame.data[i_plane] = p_pict->p[i_plane].p_pixels; frame.linesize[i_plane] = p_pict->p[i_plane].i_pitch; } /* Let ffmpeg select the frame type */ frame.pict_type = 0; frame.repeat_pict = 2 - p_pict->i_nb_fields; #if LIBAVCODEC_BUILD >= 4685 frame.interlaced_frame = !p_pict->b_progressive; frame.top_field_first = !!p_pict->b_top_field_first; #endif #if LIBAVCODEC_BUILD < 4702 /* Set the pts of the frame being encoded (segfaults with mpeg4!)*/ if( p_enc->fmt_out.i_codec == VLC_FOURCC( 'm', 'p', 'g', 'v' ) || p_enc->fmt_out.i_codec == VLC_FOURCC( 'm', 'p', '1', 'v' ) || p_enc->fmt_out.i_codec == VLC_FOURCC( 'm', 'p', '2', 'v' ) ) #else if( 1 ) #endif { frame.pts = p_pict->date ? p_pict->date : AV_NOPTS_VALUE; if ( p_sys->b_hurry_up && frame.pts != AV_NOPTS_VALUE ) { mtime_t current_date = mdate(); if ( current_date + HURRY_UP_GUARD3 > frame.pts ) { p_sys->p_context->mb_decision = FF_MB_DECISION_SIMPLE; p_sys->p_context->flags &= ~CODEC_FLAG_TRELLIS_QUANT; msg_Dbg( p_enc, "hurry up mode 3" ); } else { p_sys->p_context->mb_decision = p_sys->i_hq; if ( current_date + HURRY_UP_GUARD2 > frame.pts ) { p_sys->p_context->flags &= ~CODEC_FLAG_TRELLIS_QUANT; #if LIBAVCODEC_BUILD >= 4690 p_sys->p_context->noise_reduction = p_sys->i_noise_reduction + (HURRY_UP_GUARD2 + current_date - frame.pts) / 500; #endif msg_Dbg( p_enc, "hurry up mode 2" ); } else { if ( p_sys->b_trellis ) p_sys->p_context->flags |= CODEC_FLAG_TRELLIS_QUANT; #if LIBAVCODEC_BUILD >= 4690 p_sys->p_context->noise_reduction = p_sys->i_noise_reduction; #endif } } if ( current_date + HURRY_UP_GUARD1 > frame.pts ) { frame.pict_type = FF_P_TYPE; /* msg_Dbg( p_enc, "hurry up mode 1 %lld", current_date + HURRY_UP_GUARD1 - frame.pts ); */ } } } else { frame.pts = AV_NOPTS_VALUE; } if ( frame.pts != AV_NOPTS_VALUE && frame.pts != 0 ) { if ( p_sys->i_last_pts == frame.pts ) { msg_Warn( p_enc, "almost fed libavcodec with two frames with the " "same PTS (" I64Fd ")", frame.pts ); return NULL; } else if ( p_sys->i_last_pts > frame.pts ) { msg_Warn( p_enc, "almost fed libavcodec with a frame in the " "past (current: " I64Fd ", last: "I64Fd")", frame.pts, p_sys->i_last_pts ); return NULL; } else { p_sys->i_last_pts = frame.pts; } } frame.quality = p_sys->i_quality; /* Ugly work-around for stupid libavcodec behaviour */ #if LIBAVCODEC_BUILD >= 4722 p_sys->i_framenum++; p_sys->pi_delay_pts[p_sys->i_framenum % MAX_FRAME_DELAY] = frame.pts; frame.pts = p_sys->i_framenum * AV_TIME_BASE * p_enc->fmt_in.video.i_frame_rate_base; frame.pts += p_enc->fmt_in.video.i_frame_rate - 1; frame.pts /= p_enc->fmt_in.video.i_frame_rate; #endif /* End work-around */ i_out = avcodec_encode_video( p_sys->p_context, p_sys->p_buffer_out, AVCODEC_MAX_VIDEO_FRAME_SIZE, &frame ); if( i_out > 0 ) { block_t *p_block = block_New( p_enc, i_out ); memcpy( p_block->p_buffer, p_sys->p_buffer_out, i_out ); /* FIXME, 3-2 pulldown is not handled correctly */ p_block->i_length = I64C(1000000) * p_enc->fmt_in.video.i_frame_rate_base / p_enc->fmt_in.video.i_frame_rate; if( !p_sys->p_context->max_b_frames || !p_sys->p_context->delay ) { /* No delay -> output pts == input pts */ p_block->i_pts = p_block->i_dts = p_pict->date; } else if( p_sys->p_context->coded_frame->pts != AV_NOPTS_VALUE && p_sys->p_context->coded_frame->pts != 0 && p_sys->i_buggy_pts_detect != p_sys->p_context->coded_frame->pts ) { p_sys->i_buggy_pts_detect = p_sys->p_context->coded_frame->pts; p_block->i_pts = p_sys->p_context->coded_frame->pts; /* Ugly work-around for stupid libavcodec behaviour */ #if LIBAVCODEC_BUILD >= 4722 { int64_t i_framenum = p_block->i_pts * p_enc->fmt_in.video.i_frame_rate / p_enc->fmt_in.video.i_frame_rate_base / AV_TIME_BASE; p_block->i_pts = p_sys->pi_delay_pts[i_framenum % MAX_FRAME_DELAY]; } #endif /* End work-around */ if( p_sys->p_context->coded_frame->pict_type != FF_I_TYPE && p_sys->p_context->coded_frame->pict_type != FF_P_TYPE ) { p_block->i_dts = p_block->i_pts; } else { if( p_sys->i_last_ref_pts ) { p_block->i_dts = p_sys->i_last_ref_pts; } else { /* Let's put something sensible */ p_block->i_dts = p_block->i_pts; } p_sys->i_last_ref_pts = p_block->i_pts; } } else { /* Buggy libavcodec which doesn't update coded_frame->pts * correctly */ p_block->i_dts = p_block->i_pts = p_pict->date; } switch ( p_sys->p_context->coded_frame->pict_type ) { case FF_I_TYPE: p_block->i_flags |= BLOCK_FLAG_TYPE_I; break; case FF_P_TYPE: p_block->i_flags |= BLOCK_FLAG_TYPE_P; break; case FF_B_TYPE: p_block->i_flags |= BLOCK_FLAG_TYPE_B; break; } return p_block; } return NULL; }
/***************************************************************************** * DecodeVideo: Called to decode one or more frames *****************************************************************************/ picture_t *E_(DecodeVideo)( decoder_t *p_dec, block_t **pp_block ) { decoder_sys_t *p_sys = p_dec->p_sys; int b_drawpicture; int b_null_size = VLC_FALSE; block_t *p_block; if( !pp_block || !*pp_block ) return NULL; p_block = *pp_block; if( p_block->i_flags & BLOCK_FLAG_DISCONTINUITY ) { p_sys->i_buffer = 0; p_sys->i_pts = 0; /* To make sure we recover properly */ p_sys->input_pts = p_sys->input_dts = 0; p_sys->i_late_frames = 0; block_Release( p_block ); return NULL; } if( !p_dec->b_pace_control && p_sys->i_late_frames > 0 && mdate() - p_sys->i_late_frames_start > I64C(5000000) ) { if( p_sys->i_pts ) { msg_Err( p_dec, "more than 5 seconds of late video -> " "dropping frame (computer too slow ?)" ); p_sys->i_pts = 0; /* To make sure we recover properly */ } block_Release( p_block ); p_sys->i_late_frames--; return NULL; } if( p_block->i_pts > 0 || p_block->i_dts > 0 ) { p_sys->input_pts = p_block->i_pts; p_sys->input_dts = p_block->i_dts; /* Make sure we don't reuse the same timestamps twice */ p_block->i_pts = p_block->i_dts = 0; } /* TODO implement it in a better way */ /* A good idea could be to decode all I pictures and see for the other */ if( !p_dec->b_pace_control && p_sys->b_hurry_up && p_sys->i_late_frames > 4 ) { b_drawpicture = 0; if( p_sys->i_late_frames < 8 ) { p_sys->p_context->hurry_up = 2; } else { /* picture too late, won't decode * but break picture until a new I, and for mpeg4 ...*/ p_sys->i_late_frames--; /* needed else it will never be decrease */ block_Release( p_block ); p_sys->i_buffer = 0; return NULL; } } else { b_drawpicture = 1; p_sys->p_context->hurry_up = 0; } if( p_sys->p_context->width <= 0 || p_sys->p_context->height <= 0 ) { p_sys->p_context->hurry_up = 5; b_null_size = VLC_TRUE; } /* * Do the actual decoding now */ /* Check if post-processing was enabled */ p_sys->b_pp = p_sys->b_pp_async; /* Don't forget that ffmpeg requires a little more bytes * that the real frame size */ if( p_block->i_buffer > 0 ) { p_sys->i_buffer = p_block->i_buffer; if( p_sys->i_buffer + FF_INPUT_BUFFER_PADDING_SIZE > p_sys->i_buffer_orig ) { free( p_sys->p_buffer_orig ); p_sys->i_buffer_orig = p_block->i_buffer + FF_INPUT_BUFFER_PADDING_SIZE; p_sys->p_buffer_orig = malloc( p_sys->i_buffer_orig ); } p_sys->p_buffer = p_sys->p_buffer_orig; p_sys->i_buffer = p_block->i_buffer; p_dec->p_vlc->pf_memcpy( p_sys->p_buffer, p_block->p_buffer, p_block->i_buffer ); memset( p_sys->p_buffer + p_block->i_buffer, 0, FF_INPUT_BUFFER_PADDING_SIZE ); p_block->i_buffer = 0; } while( p_sys->i_buffer > 0 ) { int i_used, b_gotpicture; picture_t *p_pic; i_used = avcodec_decode_video( p_sys->p_context, p_sys->p_ff_pic, &b_gotpicture, p_sys->p_buffer, p_sys->i_buffer ); if( b_null_size && p_sys->p_context->width > 0 && p_sys->p_context->height > 0 ) { /* Reparse it to not drop the I frame */ b_null_size = VLC_FALSE; p_sys->p_context->hurry_up = 0; i_used = avcodec_decode_video( p_sys->p_context, p_sys->p_ff_pic, &b_gotpicture, p_sys->p_buffer, p_sys->i_buffer ); } if( i_used < 0 ) { msg_Warn( p_dec, "cannot decode one frame (%d bytes)", p_sys->i_buffer ); block_Release( p_block ); return NULL; } else if( i_used > p_sys->i_buffer ) { i_used = p_sys->i_buffer; } /* Consumed bytes */ p_sys->i_buffer -= i_used; p_sys->p_buffer += i_used; /* Nothing to display */ if( !b_gotpicture ) { if( i_used == 0 ) break; continue; } /* Update frame late count*/ if( p_sys->i_pts && p_sys->i_pts <= mdate() ) { p_sys->i_late_frames++; if( p_sys->i_late_frames == 1 ) p_sys->i_late_frames_start = mdate(); } else { p_sys->i_late_frames = 0; } if( !b_drawpicture || !p_sys->p_ff_pic->linesize[0] ) { /* Do not display the picture */ continue; } if( !p_sys->p_ff_pic->opaque ) { /* Get a new picture */ p_pic = ffmpeg_NewPictBuf( p_dec, p_sys->p_context ); if( !p_pic ) { block_Release( p_block ); return NULL; } /* Fill p_picture_t from AVVideoFrame and do chroma conversion * if needed */ ffmpeg_CopyPicture( p_dec, p_pic, p_sys->p_ff_pic ); } else { p_pic = (picture_t *)p_sys->p_ff_pic->opaque; } /* Set the PTS */ if( p_sys->p_ff_pic->pts ) p_sys->i_pts = p_sys->p_ff_pic->pts; /* Sanity check (seems to be needed for some streams ) */ if( p_sys->p_ff_pic->pict_type == FF_B_TYPE ) { p_sys->b_has_b_frames = VLC_TRUE; } /* Send decoded frame to vout */ if( p_sys->i_pts ) { p_pic->date = p_sys->i_pts; /* interpolate the next PTS */ if( p_sys->p_context->frame_rate > 0 ) { p_sys->i_pts += I64C(1000000) * (2 + p_sys->p_ff_pic->repeat_pict) * p_sys->p_context->frame_rate_base / (2 * p_sys->p_context->frame_rate); } if( p_sys->b_first_frame ) { /* Hack to force display of still pictures */ p_sys->b_first_frame = VLC_FALSE; p_pic->b_force = VLC_TRUE; } p_pic->i_nb_fields = 2 + p_sys->p_ff_pic->repeat_pict; #if LIBAVCODEC_BUILD >= 4685 p_pic->b_progressive = !p_sys->p_ff_pic->interlaced_frame; p_pic->b_top_field_first = p_sys->p_ff_pic->top_field_first; #endif return p_pic; } else { p_dec->pf_vout_buffer_del( p_dec, p_pic ); } } block_Release( p_block ); return NULL; }
// IDynamicIndexReadArg virtual void addFilter(const char *filter) override final { filters.addFilter(in->queryRecordAccessor(true), filter); flags |= TDRkeyed; } private: StringAttr fileName; UnexpectedVirtualFieldCallback fieldCallback; unsigned flags = 0; Owned<IOutputMetaData> in; Owned<IOutputMetaData> projected; Owned<IOutputMetaData> out; Owned<const IDynamicTransform> translator; RowFilter filters; unsigned __int64 chooseN = I64C(0x7fffffffffffffff); // constant(s) should be commoned up somewhere unsigned __int64 skipN = 0; unsigned __int64 rowLimit = (unsigned __int64) -1; }; class ECLRTL_API CDynamicIndexReadArg : public CThorIndexReadArg, implements IDynamicIndexReadArg { public: CDynamicIndexReadArg(const char *_fileName, IOutputMetaData *_in, IOutputMetaData *_projected, IOutputMetaData *_out, unsigned __int64 _chooseN, unsigned __int64 _skipN, unsigned __int64 _rowLimit, IVirtualFieldCallback &_callback) : fileName(_fileName), in(_in), projected(_projected), out(_out), chooseN(_chooseN), skipN(_skipN), rowLimit(_rowLimit), callback(_callback) { translator.setown(createRecordTranslator(out->queryRecordAccessor(true), in->queryRecordAccessor(true))); #ifdef _DEBUG translator->describe(); #endif
inline unsigned __int64 rtliCastUInt7(unsigned __int64 value) { return (value & I64C(0xffffffffffffff)); }
/** * Return high precision date * * Uses the gettimeofday() function when possible (1 MHz resolution) or the * ftime() function (1 kHz resolution). */ mtime_t mdate( void ) { #if defined( HAVE_KERNEL_OS_H ) return( real_time_clock_usecs() ); #elif defined( WIN32 ) || defined( UNDER_CE ) /* We don't need the real date, just the value of a high precision timer */ static mtime_t freq = I64C(-1); mtime_t usec_time; if( freq == I64C(-1) ) { /* Extract from the Tcl source code: * (http://www.cs.man.ac.uk/fellowsd-bin/TIP/7.html) * * Some hardware abstraction layers use the CPU clock * in place of the real-time clock as a performance counter * reference. This results in: * - inconsistent results among the processors on * multi-processor systems. * - unpredictable changes in performance counter frequency * on "gearshift" processors such as Transmeta and * SpeedStep. * There seems to be no way to test whether the performance * counter is reliable, but a useful heuristic is that * if its frequency is 1.193182 MHz or 3.579545 MHz, it's * derived from a colorburst crystal and is therefore * the RTC rather than the TSC. If it's anything else, we * presume that the performance counter is unreliable. */ freq = ( QueryPerformanceFrequency( (LARGE_INTEGER *)&freq ) && (freq == I64C(1193182) || freq == I64C(3579545) ) ) ? freq : 0; } if( freq != 0 ) { /* Microsecond resolution */ QueryPerformanceCounter( (LARGE_INTEGER *)&usec_time ); return ( usec_time * 1000000 ) / freq; } else { /* Fallback on GetTickCount() which has a milisecond resolution * (actually, best case is about 10 ms resolution) * GetTickCount() only returns a DWORD thus will wrap after * about 49.7 days so we try to detect the wrapping. */ static CRITICAL_SECTION date_lock; static mtime_t i_previous_time = I64C(-1); static int i_wrap_counts = -1; if( i_wrap_counts == -1 ) { /* Initialization */ i_previous_time = I64C(1000) * GetTickCount(); InitializeCriticalSection( &date_lock ); i_wrap_counts = 0; } EnterCriticalSection( &date_lock ); usec_time = I64C(1000) * (i_wrap_counts * I64C(0x100000000) + GetTickCount()); if( i_previous_time > usec_time ) { /* Counter wrapped */ i_wrap_counts++; usec_time += I64C(0x100000000000); } i_previous_time = usec_time; LeaveCriticalSection( &date_lock ); return usec_time; } #else struct timeval tv_date; /* gettimeofday() could return an error, and should be tested. However, the * only possible error, according to 'man', is EFAULT, which can not happen * here, since tv is a local variable. */ gettimeofday( &tv_date, NULL ); return( (mtime_t) tv_date.tv_sec * 1000000 + (mtime_t) tv_date.tv_usec ); #endif }
/***************************************************************************** * Demux: reads and demuxes data packets ***************************************************************************** * Returns -1 in case of error, 0 in case of EOF, 1 otherwise *****************************************************************************/ static int Demux( demux_t *p_demux ) { demux_sys_t *p_sys = p_demux->p_sys; block_t *p_block_in, *p_block_out; /* Align stream */ int64_t i_pos = stream_Tell( p_demux->s ); if( i_pos % 2 ) stream_Read( p_demux->s, NULL, 1 ); if( !( p_block_in = stream_Block( p_demux->s, A52_PACKET_SIZE ) ) ) { return 0; } if( !p_sys->b_big_endian && p_block_in->i_buffer ) { /* Convert to big endian */ #ifdef HAVE_SWAB swab(p_block_in->p_buffer, p_block_in->p_buffer, p_block_in->i_buffer); #else int i; byte_t *p_tmp, tmp; p_tmp = p_block_in->p_buffer; for( i = p_block_in->i_buffer / 2 ; i-- ; ) { tmp = p_tmp[0]; p_tmp[0] = p_tmp[1]; p_tmp[1] = tmp; p_tmp += 2; } #endif } if( p_sys->b_start ) p_block_in->i_pts = p_block_in->i_dts = 1; else p_block_in->i_pts = p_block_in->i_dts = 0; while( (p_block_out = p_sys->p_packetizer->pf_packetize( p_sys->p_packetizer, &p_block_in )) ) { p_sys->b_start = VLC_FALSE; while( p_block_out ) { block_t *p_next = p_block_out->p_next; /* We assume a constant bitrate */ if( p_block_out->i_length ) { p_sys->i_mux_rate = p_block_out->i_buffer * I64C(1000000)/p_block_out->i_length; } /* set PCR */ es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block_out->i_dts ); es_out_Send( p_demux->out, p_sys->p_es, p_block_out ); p_block_out = p_next; } } return 1; }
static time_t tlFileTimeToSeconds(const FILETIME* f) { const __int64 offset = I64C(11644473600); // Number of seconds between 1601 and 1970 (Jan 1 of each) return static_cast<time_t>((tlFileTimeToInt64(*f) / _onesec_in100ns) - offset); }