X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=remote%2Fsource%2Fxinemacontrol.cpp;h=7a013dfd0ad0e0880b92b3b5122294d6cc0b710d;hb=9050978f3b1c47e5dd64380637eb3a430bbe7a4c;hp=63399a6e4a0bcde7bfd9861b2193c9db9570a44d;hpb=6fd809bbdbfe628ef1e63b68665f374751838baf;p=xinema.git diff --git a/remote/source/xinemacontrol.cpp b/remote/source/xinemacontrol.cpp index 63399a6..7a013df 100644 --- a/remote/source/xinemacontrol.cpp +++ b/remote/source/xinemacontrol.cpp @@ -1,6 +1,12 @@ #include "xinemacontrol.h" -XinemaControl::XinemaControl() +XinemaControl::XinemaControl(): + playback_state(STOPPED), + duration(0.0f), + position(0.0f), + framerate(0.0f), + current_audio_channel(-1), + current_spu_channel(-1) { QObject::connect(&socket, &QAbstractSocket::connected, this, &XinemaControl::connected); QObject::connect(&socket, &QAbstractSocket::disconnected, this, &XinemaControl::disconnected); @@ -33,6 +39,42 @@ void XinemaControl::play_file(const QString &fn) send_request("play_file "+fn); } +void XinemaControl::play() +{ + send_request("play"); +} + +void XinemaControl::seek(float time) +{ + send_request(QString("seek %1").arg(time)); +} + +void XinemaControl::pause() +{ + send_request("pause"); +} + +void XinemaControl::stop() +{ + send_request("stop"); +} + +void XinemaControl::select_audio_channel(int chan) +{ + if(chan<0) + send_request("select_audio off"); + else + send_request(QString("select_audio %1").arg(chan)); +} + +void XinemaControl::select_spu_channel(int chan) +{ + if(chan<0) + send_request("select_spu off"); + else + send_request(QString("select_spu %1").arg(chan)); +} + void XinemaControl::send_request(const QString &req) { socket.write(req.toUtf8()); @@ -41,12 +83,16 @@ void XinemaControl::send_request(const QString &req) void XinemaControl::data_available() { - char rbuf[1024]; - int len = socket.read(rbuf, sizeof(rbuf)); - if(len<0) - return; + while(socket.bytesAvailable()) + { + char rbuf[1024]; + int len = socket.read(rbuf, sizeof(rbuf)); + if(len<0) + break; + + buffer.append(rbuf, len); + } - buffer.append(rbuf, len); unsigned start = 0; while(1) { @@ -77,6 +123,16 @@ void XinemaControl::process_reply(const QString &reply) emit subdirectory_added(args); else if(keyword=="file") emit file_added(args); + else if(keyword=="state") + { + if(args=="STOPPED") + playback_state = STOPPED; + else if(args=="PAUSED") + playback_state = PAUSED; + else if(args=="PLAYING") + playback_state = PLAYING; + emit playback_state_changed(playback_state); + } else if(keyword=="title") { title = args; @@ -92,4 +148,67 @@ void XinemaControl::process_reply(const QString &reply) position = args.toFloat(); emit position_changed(position); } + else if(keyword=="video_size") + { + space = args.indexOf(' '); + video_size = QSize(args.mid(0, space).toInt(), args.mid(space+1).toInt()); + emit size_changed(video_size); + } + else if(keyword=="framerate") + { + framerate = args.toFloat(); + emit framerate_changed(framerate); + } + else if(keyword=="video_codec") + { + video_codec = args; + emit codecs_changed(video_codec, audio_codec); + } + else if(keyword=="audio_codec") + { + audio_codec = args; + emit codecs_changed(video_codec, audio_codec); + } + else if(keyword=="audio_count") + resize_list(audio_channels, args.toInt()); + else if(keyword=="audio") + { + space = args.indexOf(' '); + audio_channels[args.mid(0, space).toInt()] = args.mid(space+1); + } + else if(keyword=="spu_count") + resize_list(spu_channels, args.toInt()); + else if(keyword=="spu") + { + space = args.indexOf(' '); + spu_channels[args.mid(0, space).toInt()] = args.mid(space+1); + } + else if(keyword=="channels_end") + emit channels_changed(); + else if(keyword=="current_audio") + { + current_audio_channel = convert_channel(args); + emit current_audio_channel_changed(current_audio_channel); + } + else if(keyword=="current_spu") + { + current_spu_channel = convert_channel(args); + emit current_spu_channel_changed(current_spu_channel); + } +} + +int XinemaControl::convert_channel(const QString &arg) +{ + if(arg=="off") + return OFF; + else + return arg.toInt(); +} + +void XinemaControl::resize_list(QStringList &list, int size) +{ + while(list.size()>size) + list.removeLast(); + while(list.size()