aboutsummaryrefslogblamecommitdiff
path: root/src/plugins/Input/ffmpeg/decoder_ffmpeg.h
blob: 39724ecb417cde68922640209d40f379ca5e4018 (plain) (tree)
1
2
                                                                            
                                                                            














                                                                            
                                                                            

                                                                             

                        

           
                                 
                               
                                  
                           
 

 
                         
 
                              

                               


                                    
                                                 



                             
                       
                  

                                             
 
        

                      


                        
 
                           
 
                   
                       
                   
                        



                                                                        
                   
 
                           
                          
                             


  
                          
/***************************************************************************
 *   Copyright (C) 2006-2014 by Ilya Kotov                                 *
 *   forkotov02@hotmail.ru                                                 *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
 ***************************************************************************/

#ifndef DECODER_FFMPEG_H
#define DECODER_FFMPEG_H

extern "C"{
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libavutil/mathematics.h>
#include <libavutil/dict.h>
}


#include <qmmp/decoder.h>

#define PROBE_BUFFER_SIZE 8192
#define INPUT_BUFFER_SIZE 16384

class DecoderFFmpeg : public Decoder
{
public:
    DecoderFFmpeg(const QString &, QIODevice *i);
    virtual ~DecoderFFmpeg();

    // Standard Decoder API
    bool initialize();
    qint64 totalTime();
    int bitrate();
    qint64 read(char *audio, qint64 maxSize);
    void seek(qint64 time);

private:
    //helper functions
    void fillBuffer();

    AVFormatContext *ic;
    AVCodecContext *c;

    int m_bitrate, wma_idx;

    QString m_path;
    qint64 m_totalTime;
    AVPacket m_pkt;
    AVPacket m_temp_pkt;
    qint64 m_output_at;
    uchar m_input_buf[INPUT_BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
    int64_t m_seekTime;
    qint64  m_skipBytes;
    int m_channels;

    qint64 ffmpeg_decode();
    AVIOContext *m_stream;
    AVFrame *m_decoded_frame;
};


#endif // DECODER_FFMPEG_H
() { m_shaded = !m_shaded; int r = m_skin->ratio(); if (m_shaded) { setPixmap(m_skin->getTitleBar(Skin::TITLEBAR_SHADED_A)); m_shade->hide(); m_shade2 = new Button(this,Skin::BT_SHADE2_N, Skin::BT_SHADE2_P, Skin::CUR_WSNORMAL); connect(m_shade2, SIGNAL(clicked()), SLOT(shade())); m_shade2->show(); m_currentTime = new SymbolDisplay(this, 6); m_currentTime->show(); connect (m_currentTime, SIGNAL (mouseClicked()), m_model, SLOT (toggleElapsed())); m_control = new TitleBarControl(this); m_control->show(); connect (m_control, SIGNAL (nextClicked()), m_mw, SLOT (next())); connect (m_control, SIGNAL (previousClicked()), m_mw, SLOT (previous())); connect (m_control, SIGNAL (playClicked()), m_mw, SLOT (play())); connect (m_control, SIGNAL (pauseClicked()), m_mw, SLOT (pause())); connect (m_control, SIGNAL (stopClicked()), m_mw, SLOT (stop())); connect (m_control, SIGNAL (ejectClicked()), m_mw, SLOT (playFiles())); m_visual = new ShadedVisual(this); Visual::add(m_visual); m_visual->show(); } else { setPixmap(m_skin->getTitleBar(Skin::TITLEBAR_A)); m_shade2->deleteLater(); m_currentTime->deleteLater(); m_control->deleteLater(); Visual::remove(m_visual); m_visual->deleteLater(); m_shade2 = 0; m_currentTime = 0; m_control = 0; m_visual = 0; m_shade->show(); } qobject_cast<MainDisplay *> (parent())->setMinimalMode(m_shaded); if (m_align) Dock::instance()->align(m_mw, m_shaded? -r*102: r*102); onModelChanged(); updatePositions(); } void TitleBar::mouseDoubleClickEvent (QMouseEvent *) { TitleBar::shade(); } QString TitleBar::formatTime (int sec) { bool sign = false; if (sec < 0) { sign = true; sec = -sec; } int minutes = sec / 60; int seconds = sec % 60; QString str_minutes = QString::number (minutes); QString str_seconds = QString::number (seconds); if (minutes < 10) str_minutes.prepend ("0"); if (seconds < 10) str_seconds.prepend ("0"); return (sign ? "-" : "") + str_minutes + ":" + str_seconds; } void TitleBar::onModelChanged() { if (!m_currentTime) return; if (!m_model->visible()) { m_currentTime->display(" : "); } else if (m_model->position() < 0) { m_currentTime->display("--:--"); } else { m_currentTime->display(formatTime(m_model->displayTime())); } }