RESULT eServiceMP3::trickSeek(gdouble ratio) { m_currentTrickRatio = ratio; if (!m_gst_playbin) return -1; if (ratio > -0.01 && ratio < 0.01) { gst_element_set_state(m_gst_playbin, GST_STATE_PAUSED); return 0; } gint64 pos; pts_t pts; getPlayPosition(pts); pos = pts * 11111LL; gst_element_set_state(m_gst_playbin, GST_STATE_PLAYING); if (ratio >= 0.0) { gst_element_seek(m_gst_playbin, ratio, GST_FORMAT_TIME, (GstSeekFlags)(GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_SKIP), GST_SEEK_TYPE_SET, pos, GST_SEEK_TYPE_SET, -1); } else { /* note that most elements will not support negative speed */ gst_element_seek(m_gst_playbin, ratio, GST_FORMAT_TIME, (GstSeekFlags)(GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_SKIP), GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_SET, pos); } m_subtitle_pages.clear(); m_prev_decoder_time = -1; m_decoder_time_valid_state = 0; return 0; }
//-------------------------------------------------------------- void GrainPlayer::drawWaveform(){ ofSetColor(255); ofFill(); const float waveformWidth = ofGetWidth() - 40; const float waveformHeight = 220; float top = ofGetHeight() - waveformHeight - 20; float left = 20; // draw the audio waveform for(int i= 0; i < LENGTH; i+=bufferSize){ curXpos = ofMap(i,0,LENGTH,left,waveformWidth); curYpos = ofMap(samp.temp[i],-32768,32768,top,waveformHeight+top); ofEllipse(curXpos, curYpos, 2, 2); ofLine(curXpos, curYpos, prevXpos, prevYpos); if(i < LENGTH-bufferSize){ prevXpos = curXpos; prevYpos = curYpos; } else { prevXpos = left; prevYpos = waveformHeight+top; } } // draw a playhead over the waveform ofSetColor(ofColor::white); ofLine(left + getPlayPosition() * waveformWidth, top, left + getPlayPosition() * waveformWidth, top + waveformHeight); ofDrawBitmapString("PlayHead", left + getPlayPosition() * waveformWidth-69, top+30); // Draw Current Recording Position ofSetColor(ofColor::red); ofLine(left + getRecordPostion() * waveformWidth, top, left + getRecordPostion() * waveformWidth, top + waveformHeight); ofDrawBitmapString("RecPos", left + getRecordPostion() * waveformWidth-52, top+15); // draw a frame around the whole thing ofSetColor(ofColor::white); ofNoFill(); ofRect(left, top, waveformWidth, waveformHeight); ofFill(); // For some reason I need to call ofFill() again to remove the memeory glitch? wtf }
void eServiceMP3::pushSubtitles() { while ( !m_subtitle_pages.empty() ) { SubtitlePage &frontpage = m_subtitle_pages.front(); pts_t running_pts; gint64 diff_ms = 0; gint64 show_pts = 0; getPlayPosition(running_pts); if (m_decoder_time_valid_state < 4) { ++m_decoder_time_valid_state; if (m_prev_decoder_time == running_pts) m_decoder_time_valid_state = 0; if (m_decoder_time_valid_state < 4) { m_subtitle_sync_timer->start(50, true); m_prev_decoder_time = running_pts; break; } } if (frontpage.type == SubtitlePage::Pango) show_pts = frontpage.pango_page.m_show_pts; diff_ms = ( show_pts - running_pts ) / 90; eDebug("check subtitle: decoder: %lld, show_pts: %lld, diff: %lld ms", running_pts/90, show_pts/90, diff_ms); if ( diff_ms < -100 ) { eDebug("subtitle too late... drop"); m_subtitle_pages.pop_front(); } else if ( diff_ms > 20 ) { eDebug("start timer, %lldms", diff_ms); m_subtitle_sync_timer->start(diff_ms, true); break; } else // immediate show { if ( m_subtitle_widget ) { eDebug("show!\n"); if ( frontpage.type == SubtitlePage::Pango) m_subtitle_widget->setPage(frontpage.pango_page); m_subtitle_widget->show(); } m_subtitle_pages.pop_front(); } } }
RESULT eServiceMP3::seekRelative(int direction, pts_t to) { if (!m_gst_playbin) return -1; pts_t ppos; getPlayPosition(ppos); ppos += to * direction; if (ppos < 0) ppos = 0; seekTo(ppos); return 0; }
RESULT eServiceMP3::selectTrack(unsigned int i) { pts_t ppos; getPlayPosition(ppos); ppos -= 90000; if (ppos < 0) ppos = 0; int ret = selectAudioStream(i); if (!ret) { /* flush */ //seekTo(ppos); } return ret; }