private void Run() { System.Diagnostics.Debug.Write("VideoCtrl Thread Start"); while (true) { Command command = GetCommand(); if (command != null) { if (command.kind_ == Command.Kind.EndThread) { break; } else { DoCommand(command); } } switch (state_) { case StateKind.Waiting: if ((!avcodec_manager_.HasVideo || avcodec_manager_.IsPreparedVideo(current_frame_) && avcodec_manager_.IsPreparedVideo(Math.Min(current_frame_ + 2, FrameLength - 1))) && (!avcodec_manager_.HasAudio || avcodec_manager_.IsPreparedAudio(current_wave_pos_, waveout_.BufferLength * 2))) { start_tick_time_ = Environment.TickCount; start_frame_ = current_frame_; if (avcodec_manager_.HasVideo) { user_.DisplayLoad(false); BufferContainer buffer = avcodec_manager_.GetFrame(current_frame_); if (buffer != null) { drawing_thread_.Draw(buffer.Buffer); } } if (avcodec_manager_.HasAudio) { waveout_.Play(); is_wave_playing_ = true; } state_ = StateKind.Playing; } break; case StateKind.Playing: int update_frame = (int)((Environment.TickCount - start_tick_time_) * frame_per_sec_ / 1000) + start_frame_; if (update_frame > end_frame_ || JudgeStoppingPoint(update_frame)) { lock (command_queue_) { command_queue_.Add(new Command(Command.Kind.Stop)); } } if (update_frame != current_frame_) { current_frame_ = update_frame; if (avcodec_manager_.HasVideo) { if (avcodec_manager_.IsPreparedVideo(update_frame)) { RequestDraw(current_frame_); } else { avcodec_manager_.RequireSeeking(current_frame_); state_ = StateKind.Waiting; user_.DisplayLoad(true); if (avcodec_manager_.HasAudio) { waveout_.Stop(); is_wave_playing_ = false; } } } user_.InformChangingFrame(current_frame_); } break; } Thread.Sleep(1); } thread_end_event_.Set(); }