Ticket #7659: audioprops.patch
File audioprops.patch, 18.7 KB (added by , 14 years ago) |
---|
-
libs/libmythtv/nuppeldecoder.cpp
1323 1323 return true; 1324 1324 } 1325 1325 1326 int NuppelDecoder::GetAudioProperties(void) 1327 { 1328 VERBOSE(VB_AUDIO, LOC + QString("Getting Nuppel Audio Props")); 1329 1330 if (!mpa_audctx) 1331 { 1332 VERBOSE(VB_AUDIO, LOC + QString("No Audio Context, ignoring audio props")); 1333 return -1; 1334 } 1335 1336 int props = GetAudioPropertiesFromContext(mpa_audctx); 1337 1338 // no way to find AUD_HARDHEAR so ignore 1339 // DH: I don't know what AUD_VISUALIMPAIR is so ignore 1340 1341 return props; 1342 } 1343 1326 1344 void NuppelDecoder::SeekReset(long long newKey, uint skipFrames, 1327 1345 bool doFlush, bool discardFrames) 1328 1346 { -
libs/libmythtv/NuppelVideoPlayer.cpp
7914 7914 osdtheme = themename; osdtheme.detach(); 7915 7915 } 7916 7916 7917 int NuppelVideoPlayer::GetAudioProperties(void) 7918 { 7919 using_null_videoout = true; 7920 7921 VERBOSE(VB_AUDIO, LOC + "opening file for audio props"); 7922 if (OpenFile(false, 0, false) < 0) 7923 { 7924 VERBOSE(VB_IMPORTANT, LOC_ERR + "Could not open file for audio props."); 7925 return NULL; 7926 } 7927 7928 VERBOSE(VB_AUDIO, LOC + "Getting decoder for audio props"); 7929 if (GetDecoder()) 7930 { 7931 VERBOSE(VB_AUDIO, QString("Found decoder, getting audio props")); 7932 return GetDecoder()->GetAudioProperties(); 7933 } 7934 7935 VERBOSE(VB_IMPORTANT, QString("Found no decoder for audio props")); 7936 return -1; 7937 } 7938 7917 7939 // EIA-708 caption support -- end 7918 7940 7919 7941 static unsigned dbg_ident(const NuppelVideoPlayer *nvp) -
libs/libmythtv/audiopropsgenerator.cpp
1 // MythTV headers 2 #include "RingBuffer.h" 3 #include "NuppelVideoPlayer.h" 4 #include "audiopropsgenerator.h" 5 #include "tv_rec.h" 6 #include "playercontext.h" 7 #include "mythverbose.h" 8 9 #define LOC QString("Audio Props: ") 10 #define LOC_ERR QString("Audio Props Error: ") 11 #define LOC_WARN QString("Audio Props Warning: ") 12 13 /** \class AudioPropsGenerator 14 * \brief This class updates the Audio Properties of a recording. 15 * 16 * The usage is simple: First, pass a ProgramInfo whose pathname points 17 * to a local or remote recording to the constructor. Then call either 18 * Start(void) or Run(void) to update the audio props. 19 * 20 * Start(void) will create a thread that processes the request. 21 * 22 * Run(void) will process the request in the current thread, 23 * 24 * The AudioPropsGenerator will send Qt signals when the update is ready 25 * and when the thread finishes running if Start(void) was called. 26 */ 27 28 /** 29 * \brief Constructor 30 * 31 * \param pginfo ProgramInfo for the reording we want to generate audio props for 32 */ 33 AudioPropsGenerator::AudioPropsGenerator(const ProgramInfo *pginfo) 34 : programInfo(*pginfo) 35 { 36 VERBOSE(VB_AUDIO, LOC + QString("Constructing Audio Props Generator")); 37 } 38 39 AudioPropsGenerator::~AudioPropsGenerator() 40 { 41 VERBOSE(VB_AUDIO, LOC + QString("Deconstructing Audio Props Generator")); 42 43 audioPropsLock.lock(); 44 emit audioPropsThreadDone(&programInfo); 45 audioPropsLock.unlock(); 46 disconnectSafe(); 47 } 48 49 void AudioPropsGenerator::AttachSignals(QObject *obj) 50 { 51 QMutexLocker locker(&audioPropsLock); 52 qRegisterMetaType<bool>("bool &"); 53 connect(this, SIGNAL(audioPropsThreadDone(const QString&,bool&)), 54 obj, SLOT( audioPropsThreadDone(const QString&,bool&)), 55 Qt::DirectConnection); 56 connect(this, SIGNAL(audioPropsReady(const ProgramInfo*)), 57 obj, SLOT( audioPropsReady(const ProgramInfo*)), 58 Qt::DirectConnection); 59 } 60 61 /** \fn AudioProps::disconnectSafe(void) 62 * \brief disconnects signals while holding audioPropsLock, ensuring that 63 * no one will receive a signal from this class after this call. 64 */ 65 void AudioPropsGenerator::disconnectSafe(void) 66 { 67 QMutexLocker locker(&audioPropsLock); 68 QObject::disconnect(this, NULL, NULL, NULL); 69 } 70 71 /** \fn AudioProps::Start(void) 72 * \brief This call starts a thread that will update the audio props 73 */ 74 void AudioPropsGenerator::Start(void) 75 { 76 pthread_create(&audioPropsThread, NULL, AudioPropsRun, this); 77 // detach, so we don't have to join thread to free thread local mem. 78 pthread_detach(audioPropsThread); 79 } 80 81 bool AudioPropsGenerator::Run(void) 82 { 83 bool ok = UpdateAudioProps(); 84 85 if (ok) 86 { 87 QMutexLocker locker(&audioPropsLock); 88 emit audioPropsReady(&programInfo); 89 } 90 91 return ok; 92 } 93 94 void *AudioPropsGenerator::AudioPropsRun(void *param) 95 { 96 // Lower scheduling priority, to avoid problems with recordings. 97 if (setpriority(PRIO_PROCESS, 0, 9)) 98 VERBOSE(VB_IMPORTANT, LOC + "Setting priority failed." + ENO); 99 AudioPropsGenerator *gen = (AudioPropsGenerator*) param; 100 gen->Run(); 101 gen->deleteLater(); 102 return NULL; 103 } 104 105 bool AudioPropsGenerator::UpdateAudioProps(void) 106 { 107 108 VERBOSE(VB_AUDIO, LOC + QString("Starting Audio Inspection")); 109 PlayerContext *ctx = new PlayerContext(kAudioInspectorInUseID); 110 111 VERBOSE(VB_AUDIO, LOC + QString("Using file: %1").arg(programInfo.pathname)); 112 RingBuffer *rbuf = new RingBuffer(programInfo.pathname, false, false, 0); 113 114 VERBOSE(VB_AUDIO, LOC + QString("Setting player")); 115 ctx->SetRingBuffer(rbuf); 116 ctx->SetPlayingInfo(&programInfo); 117 ctx->SetNVP(new NuppelVideoPlayer()); 118 ctx->nvp->SetPlayerInfo(NULL, NULL, true, ctx); 119 120 VERBOSE(VB_AUDIO, LOC + QString("Getting audio props")); 121 int audioprops = ctx->nvp->GetAudioProperties(); 122 123 VERBOSE(VB_AUDIO, LOC + QString("Got audio props")); 124 bool updated = audioprops >= 0; 125 126 if (!updated) 127 VERBOSE(VB_IMPORTANT, LOC + QString("NOT Saving audio props for %1").arg(programInfo.title)); 128 else 129 { 130 VERBOSE(VB_IMPORTANT, LOC + QString("Saving audio props (%1) for %2").arg(audioprops).arg(programInfo.title)); 131 programInfo.SaveAudioProps(audioprops); 132 } 133 134 return updated; 135 } 136 137 /* vim: set expandtab tabstop=4 shiftwidth=4: */ -
libs/libmythtv/decoderbase.h
147 147 148 148 virtual QString GetXDS(const QString&) const { return QString::null; } 149 149 150 virtual int GetAudioProperties(void) = 0; 151 152 int GetAudioPropertiesFromContext(AVCodecContext *context); 153 150 154 // MHEG/MHI stuff 151 155 virtual bool SetAudioByComponentTag(int) { return false; } 152 156 virtual bool SetVideoByComponentTag(int) { return false; } -
libs/libmythtv/avformatdecoder.cpp
1859 1859 VERBOSE(VB_GENERAL, LOC + QString("codec %1 has %2 channels") 1860 1860 .arg(codec_id_string(enc->codec_id)) 1861 1861 .arg(enc->channels)); 1862 1863 1862 #if 0 1864 1863 // HACK MULTICHANNEL DTS passthru disabled for multichannel, 1865 1864 // dont know how to handle this … … 4383 4382 return passthru; 4384 4383 } 4385 4384 4385 // returns the AudioProperties for the current data 4386 int AvFormatDecoder::GetAudioProperties(void) 4387 { 4388 VERBOSE(VB_AUDIO, LOC + QString("Getting AFD Audio Props")); 4389 4390 if (!ic) 4391 { 4392 VERBOSE(VB_IMPORTANT, LOC + QString("No FormatContext, ignoring audio props")); 4393 return -1; 4394 } 4395 4396 int props = 0; 4397 4398 // first try to find audio properties form the audio tracks 4399 sinfo_vec_t::iterator it = tracks[kTrackTypeAudio].begin(); 4400 for (; it != tracks[kTrackTypeAudio].end(); ++it) 4401 // for (uint i = 0; i < ic->nb_streams; i++) 4402 { 4403 //AVStream *stream = ic->streams[i]; 4404 AVStream *stream = ic->streams[it->av_stream_index]; 4405 int i = it->av_stream_index; 4406 4407 VERBOSE(VB_AUDIO, LOC + QString("Inspecting Audio Stream id #%1 ").arg(i)); 4408 4409 // make sure there's a stream 4410 if (!stream) 4411 { 4412 VERBOSE(VB_IMPORTANT, LOC + QString("No Stream for Stream id #%1").arg(i)); 4413 continue; 4414 } 4415 4416 AVCodecContext *codec = stream->codec; 4417 4418 // mmake sure there's a codec 4419 if (!codec) 4420 { 4421 VERBOSE(VB_IMPORTANT, LOC + QString("No Codec for Stream id #%1").arg(i)); 4422 continue; 4423 } 4424 4425 props |= GetAudioPropertiesFromContext(codec); 4426 } 4427 4428 // if there are any of these assume hard hearing 4429 int track_count = kTrackTypeCount; 4430 if ( 4431 (track_count >= kTrackTypeSubtitle && tracks[kTrackTypeSubtitle].size() > 0) || 4432 (track_count >= kTrackTypeCC608 && tracks[kTrackTypeCC608].size() > 0) || 4433 (track_count >= kTrackTypeCC708 && tracks[kTrackTypeCC708].size() > 0) || 4434 (track_count >= kTrackTypeTeletextCaptions && tracks[kTrackTypeTeletextCaptions].size() > 0) || 4435 (track_count >= kTrackTypeTeletextMenu && tracks[kTrackTypeTeletextMenu].size() > 0) || 4436 (track_count >= kTrackTypeTextSubtitle && tracks[kTrackTypeTextSubtitle].size() > 0) 4437 ) 4438 { 4439 VERBOSE(VB_AUDIO, LOC + QString("Found HARDHEARING Track")); 4440 props |= AUD_HARDHEAR; 4441 } 4442 4443 // DH: I don't know what AUD_VISUALIMPAIR is, so ignore it 4444 4445 return props; 4446 } 4447 4386 4448 /** \fn AvFormatDecoder::SetupAudioStream(void) 4387 4449 * \brief Reinitializes audio if it needs to be reinitialized. 4388 4450 * … … 4424 4486 if (info == audioIn) 4425 4487 return false; // no change 4426 4488 4427 VERBOSE(VB_AUDIO, LOC + "Initializing audio par ms from " +4489 VERBOSE(VB_AUDIO, LOC + "Initializing audio params from " + 4428 4490 QString("audio track #%1").arg(currentTrack[kTrackTypeAudio]+1)); 4429 4491 4430 4492 audioOut = audioIn = info; -
libs/libmythtv/libmythtv.pro
151 151 HEADERS += viewschdiff.h livetvchain.h 152 152 HEADERS += playgroup.h 153 153 HEADERS += channelsettings.h previewgenerator.h 154 HEADERS += audiopropsgenerator.h 154 155 HEADERS += transporteditor.h listingsources.h 155 156 HEADERS += myth_imgconvert.h 156 157 HEADERS += channelgroup.h channelgroupsettings.h … … 173 174 SOURCES += viewschdiff.cpp 174 175 SOURCES += livetvchain.cpp playgroup.cpp 175 176 SOURCES += channelsettings.cpp previewgenerator.cpp 177 SOURCES += audiopropsgenerator.cpp 176 178 SOURCES += transporteditor.cpp 177 179 SOURCES += channelgroup.cpp channelgroupsettings.cpp 178 180 SOURCES += myth_imgconvert.cpp -
libs/libmythtv/nuppeldecoder.h
52 52 QString GetCodecDecoderName(void) const { return "nuppel"; } 53 53 MythCodecID GetVideoCodecID(void) const; 54 54 55 int GetAudioProperties(void); 56 55 57 private: 56 58 inline bool ReadFileheader(struct rtfileheader *fileheader); 57 59 inline bool ReadFrameheader(struct rtframeheader *frameheader); -
libs/libmythtv/NuppelVideoPlayer.h
211 211 QString GetXDS(const QString &key) const; 212 212 bool GetAudioBufferStatus(uint &fill, uint &total) const; 213 213 PIPLocation GetNextPIPLocation(void) const; 214 int GetAudioProperties(void); 214 215 215 216 // Bool Gets 216 217 bool GetRawAudioState(void) const; -
libs/libmythtv/decoderbase.cpp
886 886 return currentTrack[type]; 887 887 } 888 888 889 /** \fn DecoderBase::GetAudioPropertiesFromContext(AVCodecContext *context) 890 * \brief Get Audio Properties Enum from context object 891 * 892 * \return int with bitwise properties, -1 otherwise 893 */ 894 int DecoderBase::GetAudioPropertiesFromContext(AVCodecContext *context) 895 { 896 int props = 0; 897 // mmake sure there's a context 898 if (!context) 899 { 900 VERBOSE(VB_IMPORTANT, LOC + QString("No context; ignoring audio props")); 901 return -1; 902 } 903 904 // use the channel_layout to approximate the data sound type 905 // we can't use channels because it gets overwritten in AutoSelectAudioTrack 906 int channel_layout = context->channel_layout; 907 908 VERBOSE(VB_AUDIO, LOC + QString("Channel Layout: %1").arg(channel_layout)); 909 910 // assume DOLBY 911 if ( (channel_layout & CH_LAYOUT_5POINT1) == CH_LAYOUT_5POINT1 ) 912 { 913 VERBOSE(VB_AUDIO, LOC + QString("Found DOLBY")); 914 props |= AUD_DOLBY; 915 } 916 917 // assume SURROUND 918 else if ( (channel_layout & CH_LAYOUT_SURROUND) == CH_LAYOUT_SURROUND) 919 { 920 VERBOSE(VB_AUDIO, LOC + QString("Found SURROUND")); 921 props |= AUD_SURROUND; 922 } 923 924 // assume stereo 925 else if ( (channel_layout & CH_LAYOUT_STEREO) == CH_LAYOUT_STEREO ) 926 { 927 VERBOSE(VB_AUDIO, LOC + QString("Found STEREO")); 928 props |= AUD_STEREO; 929 } 930 931 // assume mono 932 else if ((channel_layout & CH_LAYOUT_MONO) == CH_LAYOUT_MONO) 933 { 934 VERBOSE(VB_AUDIO, LOC + QString("Found MONO")); 935 props |= AUD_MONO; 936 } 937 938 // otherwise unknown 939 else 940 { 941 VERBOSE(VB_AUDIO, LOC + QString("Found UNKNOWN")); 942 props |= AUD_UNKNOWN; 943 } 944 945 return props; 946 } 947 889 948 StreamInfo DecoderBase::GetTrackInfo(uint type, uint trackNo) const 890 949 { 891 950 QMutexLocker locker(avcodeclock); … … 915 974 return true; 916 975 } 917 976 977 978 918 979 /** \fn DecoderBase::AutoSelectTrack(uint) 919 980 * \brief Select best track. 920 981 * -
libs/libmythtv/avformatdecoder.h
200 200 bool GenerateDummyVideoFrame(void); 201 201 bool HasVideo(const AVFormatContext *ic); 202 202 203 virtual int GetAudioProperties(void); 204 203 205 private: 204 206 class AvFormatDecoderPrivate *d; 205 207 -
libs/libmythtv/tv_rec.cpp
30 30 #include "eitscanner.h" 31 31 #include "RingBuffer.h" 32 32 #include "previewgenerator.h" 33 #include "audiopropsgenerator.h" 33 34 #include "storagegroup.h" 34 35 #include "remoteutil.h" 35 36 #include "tvremoteutil.h" … … 1120 1151 if (!killFile) 1121 1152 { 1122 1153 (new PreviewGenerator(curRecording, PreviewGenerator::kLocal))->Start(); 1154 (new AudioPropsGenerator(curRecording))->Start(); 1123 1155 1124 1156 if (!tvchain) 1125 1157 { -
libs/libmythtv/audiopropsgenerator.h
1 // -*- Mode: c++ -*- 2 #ifndef AUDIOPROPS_GENERATOR_H_ 3 #define AUDIOPROPS_GENERATOR_H_ 4 5 #include <pthread.h> 6 7 #include <QMutex> 8 #include <QString> 9 10 #include "programinfo.h" 11 12 class MPUBLIC AudioPropsGenerator : public QObject 13 { 14 Q_OBJECT 15 16 public: 17 AudioPropsGenerator(const ProgramInfo *pginfo); 18 19 void Start(void); 20 bool Run(void); 21 22 signals: 23 void audioPropsThreadDone(const ProgramInfo*); 24 void audioPropsReady(const ProgramInfo*); 25 26 protected: 27 virtual ~AudioPropsGenerator(); 28 bool UpdateAudioProps(void); 29 void disconnectSafe(void); 30 void AttachSignals(QObject *); 31 static void *AudioPropsRun(void*); 32 33 protected: 34 QMutex audioPropsLock; 35 pthread_t audioPropsThread; 36 ProgramInfo programInfo; 37 }; 38 39 #endif //AUDIOPROPS_GENERATOR_H_ -
libs/libmythtv/dummydecoder.h
30 30 virtual MythCodecID GetVideoCodecID(void) const { return kCodec_NONE; } 31 31 32 32 virtual bool SyncPositionMap(void) { return false; } 33 34 virtual int GetAudioProperties(void) { return -1; } 33 35 }; 34 36 35 37 #endif -
libs/libmyth/programinfo.h
16 16 #include "mythdbcon.h" 17 17 18 18 MPUBLIC extern const char *kPreviewGeneratorInUseID; 19 MPUBLIC extern const char *kAudioInspectorInUseID; 19 20 20 21 typedef QHash<QString,QString> InfoMap; 21 22 … … 365 366 int GetHeight(void); 366 367 void SetVidpropHeight(int width); 367 368 369 // Audio Set 370 void SaveAudioProps(int props); 371 368 372 // In-use, autodeletion prevention stuff 369 373 void MarkAsInUse(bool inuse, QString usedFor = ""); 370 374 -
libs/libmyth/programinfo.cpp
33 33 #define LOC_ERR QString("ProgramInfo, Error: ") 34 34 35 35 const char *kPreviewGeneratorInUseID = "preview_generator"; 36 const char *kAudioInspectorInUseID = "audio_inspector"; 36 37 37 38 // works only for integer divisors of 60 38 39 static const uint kUnknownProgramLength = 30; … … 2876 2877 return m_videoWidth; 2877 2878 } 2878 2879 2880 /** \fn ProgramInfo::SaveAudioProps(int props) 2881 * \brief Saves the audio properties to DB 2882 */ 2883 void ProgramInfo::SaveAudioProps(int props) 2884 { 2885 // first set the props in the object 2886 audioproperties = props; 2887 2888 // next write it to the DB 2889 MSqlQuery query(MSqlQuery::InitCon()); 2890 2891 VERBOSE(VB_AUDIO, QString("Setting Audio Props %1").arg(props)); 2892 query.prepare("UPDATE recordedprogram SET audioprop =" 2893 " :PROP WHERE chanid = :CHANID AND starttime = :STARTTIME;"); 2894 2895 query.bindValue(":PROP", props); 2896 query.bindValue(":CHANID", chanid); 2897 query.bindValue(":STARTTIME", startts); 2898 2899 if (!query.exec()) 2900 MythDB::DBError("UpdateRes", query); 2901 2902 } 2903 2904 2879 2905 /** \fn ProgramInfo::SetVidpropHeight(int width) 2880 2906 * \brief Sets overall average height flag in videoprops. 2881 2907 */