1
/* This file is part of the KDE project
2
* Copyright (C) 2010 Casian Andrei <skeletk13@gmail.com>
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2.1 of the License, or (at your option) version 3, or any
8
* later version accepted by the membership of KDE e.V. (or its
9
* successor approved by the membership of KDE e.V.), Nokia Corporation
10
* (or its successors, if any) and the KDE Free Qt Foundation, which shall
11
* act as a proxy defined in Section 6 of version 3 of the license.
13
* This library is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Lesser General Public License for more details.
18
* You should have received a copy of the GNU Lesser General Public
19
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
23
#include "capture_test.h"
25
MediaPlayer::MediaPlayer(QWidget *parent)
28
m_videoDeviceModel = NULL;
29
m_audioDeviceModel = NULL;
31
QVBoxLayout *layout = new QVBoxLayout(this);
33
m_vwidget = new Phonon::VideoWidget(this);
34
m_vwidget->setMinimumSize(QSize(400, 300));
35
m_vwidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
36
layout->addWidget(m_vwidget);
38
m_aoutput = new Phonon::AudioOutput();
40
m_avcapture = new Phonon::Experimental::AvCapture();
42
Phonon::createPath(m_avcapture, m_aoutput);
43
Phonon::createPath(m_avcapture, m_vwidget);
45
QHBoxLayout *deviceNameLayout = new QHBoxLayout(this);
47
m_videoDeviceCombo = new QComboBox(this);
48
m_videoDeviceCombo->setEditable(false);
49
m_audioDeviceCombo = new QComboBox(this);
50
m_audioDeviceCombo->setEditable(false);
51
deviceNameLayout->addWidget(m_videoDeviceCombo);
52
deviceNameLayout->addWidget(m_audioDeviceCombo);
53
connect(m_videoDeviceCombo, SIGNAL(activated(int)), this, SLOT(setVideoDeviceIndex(int)));
54
connect(m_audioDeviceCombo, SIGNAL(activated(int)), this, SLOT(setAudioDeviceIndex(int)));
57
layout->addItem(deviceNameLayout);
59
m_playButton = new QPushButton(this);
60
m_playButton->setText("Start");
61
connect(m_playButton, SIGNAL(clicked()), m_avcapture, SLOT(start()));
63
m_stopButton = new QPushButton(this);
64
m_stopButton->setText("Stop");
65
connect(m_stopButton, SIGNAL(clicked()), m_avcapture, SLOT(stop()));
67
QHBoxLayout *buttonsLayout = new QHBoxLayout(this);
68
buttonsLayout->addWidget(m_playButton);
69
buttonsLayout->addWidget(m_stopButton);
70
layout->addItem(buttonsLayout);
72
m_volumeSlider = new Phonon::VolumeSlider(this);
73
layout->addWidget(m_volumeSlider);
74
m_volumeSlider->setAudioOutput(m_aoutput);
79
MediaPlayer::~MediaPlayer()
85
void MediaPlayer::setVideoDeviceIndex(int index)
87
#ifndef QT_NO_PHONON_VIDEOCAPTURE
88
QModelIndex mi = m_videoDeviceModel->index(index, 0, QModelIndex());
89
Q_ASSERT(mi.isValid());
91
Phonon::VideoCaptureDevice vc = m_videoDeviceModel->modelData(mi);
92
Q_ASSERT(vc.isValid());
94
m_avcapture->setVideoCaptureDevice(vc);
98
void MediaPlayer::setAudioDeviceIndex(int index)
100
#ifndef QT_NO_PHONON_AUDIOCAPTURE
101
QModelIndex mi = m_audioDeviceModel->index(index, 0, QModelIndex());
102
Q_ASSERT(mi.isValid());
104
Phonon::AudioCaptureDevice ac = m_audioDeviceModel->modelData(mi);
105
Q_ASSERT(ac.isValid());
107
m_avcapture->setAudioCaptureDevice(ac);
108
#endif // QT_NO_PHONON_AUDIOCAPTURE
111
void MediaPlayer::updateDeviceList()
113
#ifndef QT_NO_PHONON_VIDEOCAPTURE
114
QList<Phonon::VideoCaptureDevice> vl = Phonon::BackendCapabilities::availableVideoCaptureDevices();
116
if (!m_videoDeviceModel)
117
m_videoDeviceModel = new Phonon::VideoCaptureDeviceModel(vl, 0);
118
m_videoDeviceCombo->setModel(m_videoDeviceModel);
120
Q_ASSERT(m_videoDeviceModel->rowCount() >= 0);
122
if (m_videoDeviceModel->rowCount() == 0)
123
QMessageBox::critical(this, "Error", "No video capture devices found.");
125
QMessageBox::critical(this, "Error", "Video capture is disabled.");
128
#ifndef QT_NO_PHONON_AUDIOCAPTURE
129
QList<Phonon::AudioCaptureDevice> al = Phonon::BackendCapabilities::availableAudioCaptureDevices();
131
if (!m_audioDeviceModel)
132
m_audioDeviceModel = new Phonon::AudioCaptureDeviceModel(al, 0);
133
m_audioDeviceCombo->setModel(m_audioDeviceModel);
135
Q_ASSERT(m_audioDeviceModel->rowCount() >= 0);
137
if (m_audioDeviceModel->rowCount() == 0)
138
QMessageBox::critical(this, "Error", "No audio capture devices found.");
140
QMessageBox::critical(this, "Error", "Audio capture is disabled.");