[haiku-commits] haiku: hrev50379 - src/apps/mediaplayer src/apps/mediaplayer/playlist src/kits/media src/add-ons/media/plugins/http_streamer headers/private/media

  • From: b.vitruvio@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 30 Jun 2016 16:55:33 +0200 (CEST)

hrev50379 adds 5 changesets to branch 'master'
old head: 936696c78a28791dd33597fe47ea35bcdb58c2b8
new head: 1acb1f504ddcefa7134a12c6c3873d88bc58a274
overview: 
http://cgit.haiku-os.org/haiku/log/?qt=range&q=1acb1f504ddc+%5E936696c78a28

----------------------------------------------------------------------------

70efd0db0ae7: MediaPlayer: Avoid to recreate the supplier more than needed
  
  * MediaPlayer attempted to recreate each time the media supplier(s),
  and implictly it recreated also the BMediaFile. This works fine with
  local data that can be accessed fastly, but makes lots of troubles
  with network streams such as BMediaIO. The result of this was that
  the Streamer plugin has been recreated each time having memory and
  network wasted other than performances.
  * I tried to keep intact the previous logic, and it looks OK for me,
  this has been done by moving out of the Controller the ownership of
  the TrackSupplier and adding a little utility class that do the
  releasing job previously done by the ObjectDeleter.
  * Reviews are appreciated.

92cb0c5d18d6: MediaPlayer: Add GUI to open network streams

345dba541685: AdapterIO: Further development of the interface
  
  * Implement Open/Close mechanism.
  * Implement SetBuffer.
  * Implement timeout handling.
  * Improve Seek mechanism, this is now working by locking the
  thread until the backend call SeekCompleted.

93a1f9d274a4: http_streamer: Sync with BAdapterIO changes

1acb1f504ddc: Style fixes

                                [ Dario Casalinuovo <b.vitruvio@xxxxxxxxx> ]

----------------------------------------------------------------------------

24 files changed, 440 insertions(+), 151 deletions(-)
headers/private/media/AdapterIO.h                |  14 ++-
.../media/plugins/http_streamer/HTTPMediaIO.cpp  |  82 +++++++------
.../media/plugins/http_streamer/HTTPMediaIO.h    |  10 +-
.../plugins/http_streamer/HTTPStreamerPlugin.cpp |  11 +-
src/apps/mediaplayer/Controller.cpp              |  97 +++++++++------
src/apps/mediaplayer/Controller.h                |   1 -
src/apps/mediaplayer/Jamfile                     |   2 +
src/apps/mediaplayer/MainApp.h                   |   4 +-
src/apps/mediaplayer/MainWin.cpp                 |  18 +++
src/apps/mediaplayer/NetworkStreamWin.cpp        |  86 +++++++++++++
src/apps/mediaplayer/NetworkStreamWin.h          |  28 +++++
.../mediaplayer/playlist/FilePlaylistItem.cpp    |   4 +-
src/apps/mediaplayer/playlist/FilePlaylistItem.h |   7 +-
.../playlist/ImportPLItemsCommand.cpp            |   2 +-
src/apps/mediaplayer/playlist/Playlist.cpp       |  11 +-
src/apps/mediaplayer/playlist/Playlist.h         |   3 +-
src/apps/mediaplayer/playlist/PlaylistItem.cpp   |  35 +++++-
src/apps/mediaplayer/playlist/PlaylistItem.h     |  13 +-
.../mediaplayer/playlist/PlaylistListView.cpp    |   6 +-
src/apps/mediaplayer/playlist/PlaylistListView.h |   2 +-
src/apps/mediaplayer/playlist/PlaylistWindow.cpp |   3 +-
.../mediaplayer/playlist/UrlPlaylistItem.cpp     |  27 +++--
src/apps/mediaplayer/playlist/UrlPlaylistItem.h  |   5 +-
src/kits/media/AdapterIO.cpp                     | 120 ++++++++++++++-----

############################################################################

Commit:      70efd0db0ae7443c76011f57b55cab99f66e9789
URL:         http://cgit.haiku-os.org/haiku/commit/?id=70efd0db0ae7
Author:      Dario Casalinuovo <b.vitruvio@xxxxxxxxx>
Date:        Wed Jun 29 16:30:53 2016 UTC

MediaPlayer: Avoid to recreate the supplier more than needed

* MediaPlayer attempted to recreate each time the media supplier(s),
and implictly it recreated also the BMediaFile. This works fine with
local data that can be accessed fastly, but makes lots of troubles
with network streams such as BMediaIO. The result of this was that
the Streamer plugin has been recreated each time having memory and
network wasted other than performances.
* I tried to keep intact the previous logic, and it looks OK for me,
this has been done by moving out of the Controller the ownership of
the TrackSupplier and adding a little utility class that do the
releasing job previously done by the ObjectDeleter.
* Reviews are appreciated.

----------------------------------------------------------------------------

diff --git a/src/apps/mediaplayer/Controller.cpp 
b/src/apps/mediaplayer/Controller.cpp
index f555cc8..76d839a 100644
--- a/src/apps/mediaplayer/Controller.cpp
+++ b/src/apps/mediaplayer/Controller.cpp
@@ -53,6 +53,31 @@
 using std::nothrow;
 
 
+class TrackSupplierReleaser {
+public:
+       TrackSupplierReleaser(PlaylistItemRef& owner)
+               :
+               fOwner(owner),
+               fRelease(true)
+               {}
+
+       virtual ~TrackSupplierReleaser()
+       {
+               if (fRelease)
+                       fOwner.Get()->ReleaseTrackSupplier();
+       }
+
+       void Detach()
+       {
+               fRelease = false;
+       }
+
+private:
+       PlaylistItemRef&        fOwner;
+       bool                            fRelease;
+};
+
+
 void
 HandleError(const char *text, status_t err)
 {
@@ -100,7 +125,6 @@ Controller::Controller()
        fMuted(false),
 
        fItem(NULL),
-       fTrackSupplier(NULL),
 
        fVideoSupplier(new ProxyVideoSupplier()),
        fAudioSupplier(new ProxyAudioSupplier(this)),
@@ -235,13 +259,13 @@ Controller::SetTo(const PlaylistItemRef& item)
                return B_OK;
        }
 
-       fItem = item;
-
        fAudioSupplier->SetSupplier(NULL, fVideoFrameRate);
        fVideoSupplier->SetSupplier(NULL);
 
-       ObjectDeleter<TrackSupplier> oldTrackSupplierDeleter(fTrackSupplier);
-       fTrackSupplier = NULL;
+       if (fItem != NULL)
+               TrackSupplierReleaser oldSupplierReleaser(fItem);
+
+       fItem = item;
 
        // Do not delete the supplier chain until after we called
        // NodeManager::Init() to setup a new media node chain
@@ -266,12 +290,12 @@ Controller::SetTo(const PlaylistItemRef& item)
        if (fItem.Get() == NULL)
                return B_BAD_VALUE;
 
-       TrackSupplier* trackSupplier = fItem->CreateTrackSupplier();
+       TrackSupplier* trackSupplier = fItem->GetTrackSupplier();
        if (trackSupplier == NULL) {
                _NotifyFileChanged(item.Get(), B_NO_MEMORY);
                return B_NO_MEMORY;
        }
-       ObjectDeleter<TrackSupplier> trackSupplierDeleter(trackSupplier);
+       TrackSupplierReleaser trackSupplierReleaser(fItem);
 
        status_t err = trackSupplier->InitCheck();
        if (err != B_OK) {
@@ -286,20 +310,17 @@ Controller::SetTo(const PlaylistItemRef& item)
                return B_MEDIA_NO_HANDLER;
        }
 
-       fTrackSupplier = trackSupplier;
-
        SelectAudioTrack(0);
        SelectVideoTrack(0);
 
        if (fAudioTrackSupplier == NULL && fVideoTrackSupplier == NULL) {
                printf("Controller::SetTo: no audio or video tracks found or "
                        "no decoders\n");
-               fTrackSupplier = NULL;
                _NotifyFileChanged(item.Get(), B_MEDIA_NO_HANDLER);
                return B_MEDIA_NO_HANDLER;
        }
 
-       trackSupplierDeleter.Detach();
+       trackSupplierReleaser.Detach();
 
        // prevent blocking the creation of new overlay buffers
        if (fVideoView)
@@ -423,8 +444,8 @@ Controller::AudioTrackCount()
 {
        BAutolock _(this);
 
-       if (fTrackSupplier != NULL)
-               return fTrackSupplier->CountAudioTracks();
+       if (fItem != NULL && fItem->HasTrackSupplier())
+               return fItem->GetTrackSupplier()->CountAudioTracks();
        return 0;
 }
 
@@ -434,8 +455,8 @@ Controller::VideoTrackCount()
 {
        BAutolock _(this);
 
-       if (fTrackSupplier != NULL)
-               return fTrackSupplier->CountVideoTracks();
+       if (fItem != NULL && fItem->HasTrackSupplier())
+               return fItem->GetTrackSupplier()->CountVideoTracks();
        return 0;
 }
 
@@ -445,8 +466,8 @@ Controller::SubTitleTrackCount()
 {
        BAutolock _(this);
 
-       if (fTrackSupplier != NULL)
-               return fTrackSupplier->CountSubTitleTracks();
+       if (fItem != NULL && fItem->HasTrackSupplier())
+               return fItem->GetTrackSupplier()->CountSubTitleTracks();
        return 0;
 }
 
@@ -455,11 +476,12 @@ status_t
 Controller::SelectAudioTrack(int n)
 {
        BAutolock _(this);
-       if (fTrackSupplier == NULL)
+       if (fItem == NULL || !fItem->HasTrackSupplier())
                return B_NO_INIT;
 
        ObjectDeleter<AudioTrackSupplier> deleter(fAudioTrackSupplier);
-       fAudioTrackSupplier = fTrackSupplier->CreateAudioTrackForIndex(n);
+       fAudioTrackSupplier
+               = fItem->GetTrackSupplier()->CreateAudioTrackForIndex(n);
        if (fAudioTrackSupplier == NULL)
                return B_BAD_INDEX;
 
@@ -505,11 +527,12 @@ Controller::SelectVideoTrack(int n)
 {
        BAutolock _(this);
 
-       if (fTrackSupplier == NULL)
+       if (fItem == NULL || !fItem->HasTrackSupplier())
                return B_NO_INIT;
 
        ObjectDeleter<VideoTrackSupplier> deleter(fVideoTrackSupplier);
-       fVideoTrackSupplier = fTrackSupplier->CreateVideoTrackForIndex(n);
+       fVideoTrackSupplier
+               = fItem->GetTrackSupplier()->CreateVideoTrackForIndex(n);
        if (fVideoTrackSupplier == NULL)
                return B_BAD_INDEX;
 
@@ -550,11 +573,12 @@ Controller::SelectSubTitleTrack(int n)
 {
        BAutolock _(this);
 
-       if (fTrackSupplier == NULL)
+       if (fItem == NULL || !fItem->HasTrackSupplier())
                return B_NO_INIT;
 
        fSubTitlesIndex = n;
-       fSubTitles = fTrackSupplier->SubTitleTrackForIndex(n);
+       fSubTitles =
+               fItem->GetTrackSupplier()->SubTitleTrackForIndex(n);
 
        const SubTitle* subTitle = NULL;
        if (fSubTitles != NULL)
@@ -586,10 +610,11 @@ Controller::SubTitleTrackName(int n)
 {
        BAutolock _(this);
 
-       if (fTrackSupplier == NULL)
+       if (fItem == NULL || !fItem->HasTrackSupplier())
                return NULL;
 
-       const SubTitles* subTitles = fTrackSupplier->SubTitleTrackForIndex(n);
+       const SubTitles* subTitles
+               = fItem->GetTrackSupplier()->SubTitleTrackForIndex(n);
        if (subTitles == NULL)
                return NULL;
 
@@ -800,7 +825,7 @@ bool
 Controller::HasFile()
 {
        // you need to hold the data lock
-       return fTrackSupplier != NULL;
+       return fItem != NULL && fItem->HasTrackSupplier();
 }
 
 
@@ -808,9 +833,9 @@ status_t
 Controller::GetFileFormatInfo(media_file_format* fileFormat)
 {
        // you need to hold the data lock
-       if (!fTrackSupplier)
+       if (fItem == NULL || !fItem->HasTrackSupplier())
                return B_NO_INIT;
-       return fTrackSupplier->GetFileFormatInfo(fileFormat);
+       return fItem->GetTrackSupplier()->GetFileFormatInfo(fileFormat);
 }
 
 
@@ -818,9 +843,9 @@ status_t
 Controller::GetCopyright(BString* copyright)
 {
        // you need to hold the data lock
-       if (!fTrackSupplier)
+       if (fItem == NULL || !fItem->HasTrackSupplier())
                return B_NO_INIT;
-       return fTrackSupplier->GetCopyright(copyright);
+       return fItem->GetTrackSupplier()->GetCopyright(copyright);
 }
 
 
@@ -890,9 +915,9 @@ status_t
 Controller::GetMetaData(BMessage* metaData)
 {
        // you need to hold the data lock
-       if (fTrackSupplier == NULL)
+       if (fItem == NULL || !fItem->HasTrackSupplier())
                return B_NO_INIT;
-       return fTrackSupplier->GetMetaData(metaData);
+       return fItem->GetTrackSupplier()->GetMetaData(metaData);
 }
 
 
@@ -900,9 +925,9 @@ status_t
 Controller::GetVideoMetaData(int32 index, BMessage* metaData)
 {
        // you need to hold the data lock
-       if (fTrackSupplier == NULL)
+       if (fItem == NULL || !fItem->HasTrackSupplier())
                return B_NO_INIT;
-       return fTrackSupplier->GetVideoMetaData(index, metaData);
+       return fItem->GetTrackSupplier()->GetVideoMetaData(index, metaData);
 }
 
 
@@ -910,9 +935,9 @@ status_t
 Controller::GetAudioMetaData(int32 index, BMessage* metaData)
 {
        // you need to hold the data lock
-       if (fTrackSupplier == NULL)
+       if (fItem == NULL || !fItem->HasTrackSupplier())
                return B_NO_INIT;
-       return fTrackSupplier->GetAudioMetaData(index, metaData);
+       return fItem->GetTrackSupplier()->GetAudioMetaData(index, metaData);
 }
 
 
diff --git a/src/apps/mediaplayer/Controller.h 
b/src/apps/mediaplayer/Controller.h
index 1eeda17..e271cb1 100644
--- a/src/apps/mediaplayer/Controller.h
+++ b/src/apps/mediaplayer/Controller.h
@@ -197,7 +197,6 @@ private:
                        bool                            fMuted;
 
                        PlaylistItemRef         fItem;
-                       TrackSupplier*          fTrackSupplier;
 
                        ProxyVideoSupplier*     fVideoSupplier;
                        ProxyAudioSupplier*     fAudioSupplier;
diff --git a/src/apps/mediaplayer/playlist/FilePlaylistItem.cpp 
b/src/apps/mediaplayer/playlist/FilePlaylistItem.cpp
index 976cff4..56d3cec 100644
--- a/src/apps/mediaplayer/playlist/FilePlaylistItem.cpp
+++ b/src/apps/mediaplayer/playlist/FilePlaylistItem.cpp
@@ -288,7 +288,7 @@ FilePlaylistItem::RestoreFromTrash()
 // #pragma mark -
 
 TrackSupplier*
-FilePlaylistItem::CreateTrackSupplier() const
+FilePlaylistItem::_CreateTrackSupplier() const
 {
        MediaFileTrackSupplier* supplier
                = new(std::nothrow) MediaFileTrackSupplier();
@@ -400,7 +400,7 @@ FilePlaylistItem::ImageRef() const
 
 
 bigtime_t
-FilePlaylistItem::_CalculateDuration() const
+FilePlaylistItem::_CalculateDuration()
 {
        BMediaFile mediaFile(&Ref());
 
diff --git a/src/apps/mediaplayer/playlist/FilePlaylistItem.h 
b/src/apps/mediaplayer/playlist/FilePlaylistItem.h
index 5ca3e43..82b6235 100644
--- a/src/apps/mediaplayer/playlist/FilePlaylistItem.h
+++ b/src/apps/mediaplayer/playlist/FilePlaylistItem.h
@@ -52,9 +52,6 @@ public:
        virtual status_t                        MoveIntoTrash();
        virtual status_t                        RestoreFromTrash();
 
-       // playback
-       virtual TrackSupplier*          CreateTrackSupplier() const;
-
                        status_t                        AddRef(const entry_ref& 
ref);
                        const entry_ref&        Ref() const { return fRefs[0]; }
 
@@ -62,7 +59,9 @@ public:
                        const entry_ref&        ImageRef() const;
 
 protected:
-       virtual bigtime_t                       _CalculateDuration() const;
+       virtual bigtime_t                       _CalculateDuration();
+       // playback
+       virtual TrackSupplier*          _CreateTrackSupplier() const;
 
 private:
                        status_t                        _SetAttribute(const 
char* attrName,
diff --git a/src/apps/mediaplayer/playlist/PlaylistItem.cpp 
b/src/apps/mediaplayer/playlist/PlaylistItem.cpp
index e3ec718..e6c1003 100644
--- a/src/apps/mediaplayer/playlist/PlaylistItem.cpp
+++ b/src/apps/mediaplayer/playlist/PlaylistItem.cpp
@@ -42,7 +42,8 @@ static vint32 sInstanceCount = 0;
 
 PlaylistItem::PlaylistItem()
        :
-       fPlaybackFailed(false)
+       fPlaybackFailed(false),
+       fTrackSupplier(NULL)
 {
 #ifdef DEBUG_INSTANCE_COUNT
        atomic_add(&sInstanceCount, 1);
@@ -60,6 +61,31 @@ PlaylistItem::~PlaylistItem()
 }
 
 
+TrackSupplier*
+PlaylistItem::GetTrackSupplier()
+{
+       if (fTrackSupplier == NULL)
+               fTrackSupplier = _CreateTrackSupplier();
+
+       return fTrackSupplier;
+}
+
+
+void
+PlaylistItem::ReleaseTrackSupplier()
+{
+       delete fTrackSupplier;
+       fTrackSupplier = NULL;
+}
+
+
+bool
+PlaylistItem::HasTrackSupplier() const
+{
+       return fTrackSupplier != NULL;
+}
+
+
 BString
 PlaylistItem::Name() const
 {
@@ -160,10 +186,10 @@ PlaylistItem::_NotifyListeners() const
 }
 
 
-bigtime_t PlaylistItem::_CalculateDuration() const
+bigtime_t PlaylistItem::_CalculateDuration()
 {
        // To be overridden in subclasses with more efficient methods
-       TrackSupplier* supplier = CreateTrackSupplier();
+       TrackSupplier* supplier = GetTrackSupplier();
 
        AudioTrackSupplier* au = supplier->CreateAudioTrackForIndex(0);
        VideoTrackSupplier* vi = supplier->CreateVideoTrackForIndex(0);
@@ -173,7 +199,6 @@ bigtime_t PlaylistItem::_CalculateDuration() const
 
        delete vi;
        delete au;
-       delete supplier;
 
        return duration;
 }
diff --git a/src/apps/mediaplayer/playlist/PlaylistItem.h 
b/src/apps/mediaplayer/playlist/PlaylistItem.h
index 5c7e94c..7331c21 100644
--- a/src/apps/mediaplayer/playlist/PlaylistItem.h
+++ b/src/apps/mediaplayer/playlist/PlaylistItem.h
@@ -90,8 +90,13 @@ public:
        virtual status_t                        MoveIntoTrash() = 0;
        virtual status_t                        RestoreFromTrash() = 0;
 
-       // playback
-       virtual TrackSupplier*          CreateTrackSupplier() const = 0;
+       // Create and return the TrackSupplier if it doesn't exist,
+       // this object is used for media playback.
+                       TrackSupplier*          GetTrackSupplier();
+       // Delete and reset the TrackSupplier
+                       void                            ReleaseTrackSupplier();
+       // Return whether the supplier has been initialized
+                       bool                            HasTrackSupplier() 
const;
 
                        void                            SetPlaybackFailed();
                        bool                            PlaybackFailed() const
@@ -103,11 +108,13 @@ public:
 
 protected:
                        void                            _NotifyListeners() 
const;
-       virtual bigtime_t                       _CalculateDuration() const;
+       virtual bigtime_t                       _CalculateDuration();
+       virtual TrackSupplier*          _CreateTrackSupplier() const = 0;
 
 private:
                        BList                           fListeners;
                        bool                            fPlaybackFailed;
+                       TrackSupplier*          fTrackSupplier;
 };
 
 typedef BReference<PlaylistItem> PlaylistItemRef;
diff --git a/src/apps/mediaplayer/playlist/UrlPlaylistItem.cpp 
b/src/apps/mediaplayer/playlist/UrlPlaylistItem.cpp
index a811fa9..d987ef6 100644
--- a/src/apps/mediaplayer/playlist/UrlPlaylistItem.cpp
+++ b/src/apps/mediaplayer/playlist/UrlPlaylistItem.cpp
@@ -32,7 +32,6 @@ UrlPlaylistItem::UrlPlaylistItem(const BMessage* archive)
 
 UrlPlaylistItem::~UrlPlaylistItem()
 {
-       delete fUrl;
 }
 
 
@@ -128,7 +127,7 @@ UrlPlaylistItem::RestoreFromTrash()
 
 
 TrackSupplier*
-UrlPlaylistItem::CreateTrackSupplier() const
+UrlPlaylistItem::_CreateTrackSupplier() const
 {
        MediaFileTrackSupplier* supplier
                = new(std::nothrow) MediaFileTrackSupplier();
diff --git a/src/apps/mediaplayer/playlist/UrlPlaylistItem.h 
b/src/apps/mediaplayer/playlist/UrlPlaylistItem.h
index cf911f0..234f6d8 100644
--- a/src/apps/mediaplayer/playlist/UrlPlaylistItem.h
+++ b/src/apps/mediaplayer/playlist/UrlPlaylistItem.h
@@ -45,10 +45,11 @@ public:
        virtual status_t                        MoveIntoTrash();
        virtual status_t                        RestoreFromTrash();
 
-       virtual TrackSupplier*          CreateTrackSupplier() const;
-
                        BUrl                            Url() const;
 
+protected:
+       virtual TrackSupplier*          _CreateTrackSupplier() const;
+
 private:
                        BUrl                            fUrl;
 };

############################################################################

Commit:      92cb0c5d18d60b3ce7dc816341444371cf9cefed
URL:         http://cgit.haiku-os.org/haiku/commit/?id=92cb0c5d18d6
Author:      Dario Casalinuovo <b.vitruvio@xxxxxxxxx>
Date:        Thu Jun 30 14:33:24 2016 UTC

MediaPlayer: Add GUI to open network streams

----------------------------------------------------------------------------

diff --git a/src/apps/mediaplayer/Jamfile b/src/apps/mediaplayer/Jamfile
index 63ec26d..cf14579 100644
--- a/src/apps/mediaplayer/Jamfile
+++ b/src/apps/mediaplayer/Jamfile
@@ -112,6 +112,7 @@ Application MediaPlayer :
        InfoWin.cpp
        MainApp.cpp
        MainWin.cpp
+       NetworkStreamWin.cpp
        VideoView.cpp
 
        : be game media tracker translation textencoding [ TargetLibstdc++ ]
@@ -128,6 +129,7 @@ DoCatalogs MediaPlayer :
        MainApp.cpp
        MainWin.cpp
        MovePLItemsCommand.cpp
+       NetworkStreamWin.cpp
        PeakView.cpp
        PlaylistItem.cpp
        PlaylistWindow.cpp
diff --git a/src/apps/mediaplayer/MainApp.h b/src/apps/mediaplayer/MainApp.h
index 5111df8..282b765 100644
--- a/src/apps/mediaplayer/MainApp.h
+++ b/src/apps/mediaplayer/MainApp.h
@@ -46,7 +46,9 @@ enum  {
        M_OPEN_PANEL_RESULT                     = 'oprs',
        M_SAVE_PANEL_RESULT                     = 'sprs',
 
-       M_OPEN_PREVIOUS_PLAYLIST        = 'oppp'
+       M_OPEN_PREVIOUS_PLAYLIST        = 'oppp',
+
+       M_URL_RECEIVED                          = 'urrc'
 };
 
 
diff --git a/src/apps/mediaplayer/MainWin.cpp b/src/apps/mediaplayer/MainWin.cpp
index 524fad0..4672728 100644
--- a/src/apps/mediaplayer/MainWin.cpp
+++ b/src/apps/mediaplayer/MainWin.cpp
@@ -33,6 +33,7 @@
 #include <Catalog.h>
 #include <Debug.h>
 #include <fs_attr.h>
+#include <LayoutBuilder.h>
 #include <Language.h>
 #include <Locale.h>
 #include <MediaRoster.h>
@@ -55,6 +56,7 @@
 #include "DurationToString.h"
 #include "FilePlaylistItem.h"
 #include "MainApp.h"
+#include "NetworkStreamWin.h"
 #include "PeakView.h"
 #include "PlaylistItem.h"
 #include "PlaylistObserver.h"
@@ -76,6 +78,7 @@ int MainWin::sNoVideoWidth = MIN_WIDTH;
 enum {
        M_DUMMY = 0x100,
        M_FILE_OPEN = 0x1000,
+       M_NETWORK_STREAM_OPEN,
        M_FILE_INFO,
        M_FILE_PLAYLIST,
        M_FILE_CLOSE,
@@ -617,8 +620,10 @@ MainWin::MessageReceived(BMessage* msg)
                }
 
                case B_REFS_RECEIVED:
+               case M_URL_RECEIVED:
                        _RefsReceived(msg);
                        break;
+
                case B_SIMPLE_DATA:
                        if (msg->HasRef("refs"))
                                _RefsReceived(msg);
@@ -831,6 +836,15 @@ MainWin::MessageReceived(BMessage* msg)
                        be_app->PostMessage(&appMessage);
                        break;
                }
+
+               case M_NETWORK_STREAM_OPEN:
+               {
+                       BMessenger target(this);
+                       NetworkStreamWin* win = new NetworkStreamWin(target);
+                       win->Show();
+                       break;
+               }
+
                case M_FILE_INFO:
                        ShowFileInfo();
                        break;
@@ -1499,6 +1513,10 @@ MainWin::_CreateMenu()
        item->SetShortcut('O', 0);
        fFileMenu->AddItem(item);
 
+       item = new BMenuItem(B_TRANSLATE("Open network stream"),
+               new BMessage(M_NETWORK_STREAM_OPEN));
+       fFileMenu->AddItem(item);
+
        fFileMenu->AddSeparatorItem();
 
        fFileMenu->AddItem(new BMenuItem(B_TRANSLATE("File info" 
B_UTF8_ELLIPSIS),
diff --git a/src/apps/mediaplayer/NetworkStreamWin.cpp 
b/src/apps/mediaplayer/NetworkStreamWin.cpp
new file mode 100644
index 0000000..e95a3fa
--- /dev/null
+++ b/src/apps/mediaplayer/NetworkStreamWin.cpp
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2016 Dario Casalinuovo. All rights reserved.
+ * Distributed under the terms of the MIT License.
+ *
+ */
+
+
+#include "NetworkStreamWin.h"
+
+#include <Alert.h>
+#include <Button.h>
+#include <Catalog.h>
+#include <LayoutBuilder.h>
+
+#include "MainApp.h"
+
+
+#undef B_TRANSLATION_CONTEXT
+#define B_TRANSLATION_CONTEXT "MediaPlayer-NetworkStream"
+
+
+enum  {
+       M_OPEN_URL = 0,
+       M_CANCEL
+};
+
+
+NetworkStreamWin::NetworkStreamWin(BMessenger target)
+       :
+       BWindow(BRect(0, 0, 300, 100), "Open Network Stream",
+               B_TITLED_WINDOW, B_NOT_RESIZABLE),
+       fTarget(target)
+{
+       fTextControl = new BTextControl("InputControl",
+               "Insert URL", NULL, NULL);
+
+       BLayoutBuilder::Group<>(this, B_VERTICAL)
+               .SetInsets(0, 0, 0, 0)
+               .Add(fTextControl)
+                       .AddGroup(B_HORIZONTAL)
+                               .Add(new BButton("Ok", new 
BMessage(M_OPEN_URL)))
+                               .Add(new BButton("Cancel", new 
BMessage(M_CANCEL)))
+                       .End()
+               .End();
+}
+
+
+NetworkStreamWin::~NetworkStreamWin()
+{
+}
+
+
+void
+NetworkStreamWin::MessageReceived(BMessage* message)
+{
+       switch(message->what) {
+               case M_OPEN_URL:
+               {
+                       BUrl url(fTextControl->Text());
+                       if (!url.IsValid()) {
+                               BAlert* alert = new BAlert(B_TRANSLATE("Bad 
URL"),
+                                       B_TRANSLATE("Invalid URL inserted!"),
+                                               B_TRANSLATE("OK"));
+                                       alert->Go();
+                               return;
+                       }
+
+                       BMessage archivedUrl;
+                       url.Archive(&archivedUrl);
+
+                       BMessage msg(M_URL_RECEIVED);
+                       msg.AddMessage("mediaplayer:url", &archivedUrl);
+                       fTarget.SendMessage(&msg);
+
+                       Quit();
+                       break;
+               }
+
+               case M_CANCEL:
+                       Quit();
+                       break;
+
+               default:
+                       BWindow::MessageReceived(message);
+       }
+}
diff --git a/src/apps/mediaplayer/NetworkStreamWin.h 
b/src/apps/mediaplayer/NetworkStreamWin.h
new file mode 100644
index 0000000..b88f629
--- /dev/null
+++ b/src/apps/mediaplayer/NetworkStreamWin.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2016 Dario Casalinuovo. All rights reserved.
+ * Distributed under the terms of the MIT License.
+ *
+ */
+#ifndef __NETWORK_STREAM_WIN_H
+#define __NETWORK_STREAM_WIN_H
+
+
+#include <Messenger.h>
+#include <TextControl.h>
+#include <Window.h>
+
+
+class NetworkStreamWin : public BWindow
+{
+public:
+                                                               
NetworkStreamWin(BMessenger target);
+       virtual                                         ~NetworkStreamWin();
+
+       virtual void                            MessageReceived(BMessage* 
message);
+
+private:
+                       BMessenger                      fTarget;
+                       BTextControl*           fTextControl;
+};
+
+#endif
diff --git a/src/apps/mediaplayer/playlist/ImportPLItemsCommand.cpp 
b/src/apps/mediaplayer/playlist/ImportPLItemsCommand.cpp
index be2f688..8c906c4 100644
--- a/src/apps/mediaplayer/playlist/ImportPLItemsCommand.cpp
+++ b/src/apps/mediaplayer/playlist/ImportPLItemsCommand.cpp
@@ -45,7 +45,7 @@ ImportPLItemsCommand::ImportPLItemsCommand(Playlist* playlist,
                return;
 
        Playlist temp;
-       temp.AppendRefs(refsMessage);
+       temp.AppendItems(refsMessage);
 
        fNewCount = temp.CountItems();
        if (fNewCount <= 0)
diff --git a/src/apps/mediaplayer/playlist/Playlist.cpp 
b/src/apps/mediaplayer/playlist/Playlist.cpp
index a4dd78d..dc4714a 100644
--- a/src/apps/mediaplayer/playlist/Playlist.cpp
+++ b/src/apps/mediaplayer/playlist/Playlist.cpp
@@ -429,7 +429,7 @@ Playlist::RemoveListener(Listener* listener)
 
 
 void
-Playlist::AppendRefs(const BMessage* refsReceivedMessage, int32 appendIndex)
+Playlist::AppendItems(const BMessage* refsReceivedMessage, int32 appendIndex)
 {
        // the playlist is replaced by the refs in the message
        // or the refs are appended at the appendIndex
@@ -448,6 +448,15 @@ Playlist::AppendRefs(const BMessage* refsReceivedMessage, 
int32 appendIndex)
        Playlist* playlist = add ? &temporaryPlaylist : this;
        bool sortPlaylist = true;
 
+       // TODO: This is not very fair, we should abstract from
+       // entry ref representation and support more URLs.
+       BMessage archivedUrl;
+       if (refsReceivedMessage->FindMessage("mediaplayer:url", &archivedUrl)
+                       == B_OK) {
+               BUrl url(&archivedUrl);
+               AddItem(new UrlPlaylistItem(url));
+       }
+
        entry_ref ref;
        int32 subAppendIndex = CountItems();
        for (int i = 0; refsReceivedMessage->FindRef("refs", i, &ref) == B_OK;
diff --git a/src/apps/mediaplayer/playlist/Playlist.h 
b/src/apps/mediaplayer/playlist/Playlist.h
index a048d78..1fb67e7 100644
--- a/src/apps/mediaplayer/playlist/Playlist.h
+++ b/src/apps/mediaplayer/playlist/Playlist.h
@@ -105,9 +105,10 @@ public:
                        void                            
RemoveListener(Listener* listener);
 
                        // support functions
-                       void                            AppendRefs(const 
BMessage* refsReceivedMessage,
+                       void                            AppendItems(const 
BMessage* refsReceivedMessage,
                                                                        int32 
appendIndex
                                                                                
= APPEND_INDEX_REPLACE_PLAYLIST);
+
        static  void                            AppendToPlaylistRecursive(const 
entry_ref& ref,
                                                                        
Playlist* playlist);
        static  void                            AppendPlaylistToPlaylist(const 
entry_ref& ref,
diff --git a/src/apps/mediaplayer/playlist/PlaylistItem.cpp 
b/src/apps/mediaplayer/playlist/PlaylistItem.cpp
index e6c1003..e75f835 100644
--- a/src/apps/mediaplayer/playlist/PlaylistItem.cpp
+++ b/src/apps/mediaplayer/playlist/PlaylistItem.cpp
@@ -139,6 +139,7 @@ PlaylistItem::TrackNumber() const
 bigtime_t
 PlaylistItem::Duration()
 {
+       printf("duration\n");
        bigtime_t duration;
        if (GetAttribute(ATTR_INT64_DURATION, duration) != B_OK) {
                duration = this->_CalculateDuration();
@@ -188,6 +189,7 @@ PlaylistItem::_NotifyListeners() const
 
 bigtime_t PlaylistItem::_CalculateDuration()
 {
+       printf("calc duration\n");
        // To be overridden in subclasses with more efficient methods
        TrackSupplier* supplier = GetTrackSupplier();
 
diff --git a/src/apps/mediaplayer/playlist/PlaylistListView.cpp 
b/src/apps/mediaplayer/playlist/PlaylistListView.cpp
index 005a7d5..cc28fa5 100644
--- a/src/apps/mediaplayer/playlist/PlaylistListView.cpp
+++ b/src/apps/mediaplayer/playlist/PlaylistListView.cpp
@@ -310,12 +310,12 @@ PlaylistListView::MessageReceived(BMessage* message)
 
                case B_SIMPLE_DATA:
                        if (message->HasRef("refs"))
-                               RefsReceived(message, fDropIndex);
+                               ItemsReceived(message, fDropIndex);
                        else if (message->HasPointer("list"))
                                SimpleListView::MessageReceived(message);
                        break;
                case B_REFS_RECEIVED:
-                       RefsReceived(message, fDropIndex);
+                       ItemsReceived(message, fDropIndex);
                        break;
 
                default:
@@ -506,7 +506,7 @@ PlaylistListView::DrawListItem(BView* owner, int32 index, 
BRect frame) const
 
 
 void
-PlaylistListView::RefsReceived(BMessage* message, int32 appendIndex)
+PlaylistListView::ItemsReceived(const BMessage* message, int32 appendIndex)
 {
        if (fCommandStack->Perform(new (nothrow) ImportPLItemsCommand(fPlaylist,
                        message, appendIndex)) != B_OK) {
diff --git a/src/apps/mediaplayer/playlist/PlaylistListView.h 
b/src/apps/mediaplayer/playlist/PlaylistListView.h
index dc2bf83..fabdb0f 100644
--- a/src/apps/mediaplayer/playlist/PlaylistListView.h
+++ b/src/apps/mediaplayer/playlist/PlaylistListView.h
@@ -41,7 +41,7 @@ public:
                                                                        BRect 
frame) const;
 
        // PlaylistListView
-                       void                            RefsReceived(BMessage* 
message,
+                       void                            ItemsReceived(const 
BMessage* message,
                                                                        int32 
appendIndex);
 
                        void                            Randomize();
diff --git a/src/apps/mediaplayer/playlist/PlaylistWindow.cpp 
b/src/apps/mediaplayer/playlist/PlaylistWindow.cpp
index e887ec0..1fef9dc 100644
--- a/src/apps/mediaplayer/playlist/PlaylistWindow.cpp
+++ b/src/apps/mediaplayer/playlist/PlaylistWindow.cpp
@@ -179,6 +179,7 @@ PlaylistWindow::MessageReceived(BMessage* message)
                        break;
                }
 
+               case M_URL_RECEIVED:
                case B_REFS_RECEIVED:
                        // Used for when we open a playlist from playlist window
                        if (!message->HasInt32("append_index")) {
@@ -193,7 +194,7 @@ PlaylistWindow::MessageReceived(BMessage* message)
                        // outside of the playlist!
                        int32 appendIndex;
                        if (message->FindInt32("append_index", &appendIndex) == 
B_OK)
-                               fListView->RefsReceived(message, appendIndex);
+                               fListView->ItemsReceived(message, appendIndex);
                        break;
                }
 
diff --git a/src/apps/mediaplayer/playlist/UrlPlaylistItem.cpp 
b/src/apps/mediaplayer/playlist/UrlPlaylistItem.cpp
index d987ef6..cc28d81 100644
--- a/src/apps/mediaplayer/playlist/UrlPlaylistItem.cpp
+++ b/src/apps/mediaplayer/playlist/UrlPlaylistItem.cpp
@@ -15,7 +15,6 @@ UrlPlaylistItem::UrlPlaylistItem(BUrl url)
        :
        fUrl(url)
 {
-
 }
 
 
@@ -52,7 +51,7 @@ UrlPlaylistItem::Instantiate(BMessage* archive)
 status_t
 UrlPlaylistItem::Archive(BMessage* into, bool deep) const
 {
-       return B_ERROR;
+       return B_NOT_SUPPORTED;
 }
 
 
@@ -66,35 +65,40 @@ UrlPlaylistItem::SetAttribute(const Attribute& attribute, 
const BString& string)
 status_t
 UrlPlaylistItem::GetAttribute(const Attribute& attribute, BString& string) 
const
 {
-       return B_ERROR;
+       if (attribute == ATTR_STRING_NAME) {
+               string = fUrl.UrlString();
+               return B_OK;
+       }
+
+       return B_NOT_SUPPORTED;
 }
 
 
 status_t
 UrlPlaylistItem::SetAttribute(const Attribute& attribute, const int32& value)
 {
-       return B_ERROR;
+       return B_NOT_SUPPORTED;
 }
 
 
 status_t
 UrlPlaylistItem::GetAttribute(const Attribute& attribute, int32& value) const
 {
-       return B_ERROR;
+       return B_NOT_SUPPORTED;
 }
 
 
 status_t
 UrlPlaylistItem::SetAttribute(const Attribute& attribute, const int64& value)
 {
-       return B_ERROR;
+       return B_NOT_SUPPORTED;
 }
 
 
 status_t
 UrlPlaylistItem::GetAttribute(const Attribute& attribute, int64& value) const
 {
-       return B_ERROR;
+       return B_NOT_SUPPORTED;
 }
 
 
@@ -108,21 +112,21 @@ UrlPlaylistItem::LocationURI() const
 status_t
 UrlPlaylistItem::GetIcon(BBitmap* bitmap, icon_size iconSize) const
 {
-       return B_ERROR;
+       return B_NOT_SUPPORTED;
 }
 
 
 status_t
 UrlPlaylistItem::MoveIntoTrash()
 {
-       return B_ERROR;
+       return B_NOT_SUPPORTED;
 }
 
 
 status_t
 UrlPlaylistItem::RestoreFromTrash()
 {
-       return B_ERROR;
+       return B_NOT_SUPPORTED;
 }
 
 

############################################################################

Commit:      345dba54168526b933fb00a631bb704b1f56f775
URL:         http://cgit.haiku-os.org/haiku/commit/?id=345dba541685
Author:      Dario Casalinuovo <b.vitruvio@xxxxxxxxx>
Date:        Thu Jun 30 14:27:50 2016 UTC

AdapterIO: Further development of the interface

* Implement Open/Close mechanism.
* Implement SetBuffer.
* Implement timeout handling.
* Improve Seek mechanism, this is now working by locking the
thread until the backend call SeekCompleted.

----------------------------------------------------------------------------

diff --git a/headers/private/media/AdapterIO.h 
b/headers/private/media/AdapterIO.h
index 6d48c27..ccd073e 100644
--- a/headers/private/media/AdapterIO.h
+++ b/headers/private/media/AdapterIO.h
@@ -54,26 +54,30 @@ public:
        virtual status_t                                SetSize(off_t size);
        virtual status_t                                GetSize(off_t* size) 
const;
 
+       virtual status_t                                Open();
+       virtual void                                    Close();
+
+                       void                                    SeekCompleted();
+                       status_t                                
SetBuffer(BPositionIO* buffer);
+
                        BInputAdapter*                  BuildInputAdapter();
 
 protected:
        friend class BInputAdapter;
 
-                       void                                    
SetBuffer(BPositionIO* io);
+       virtual status_t                                SeekRequested(off_t 
position);
 
                        ssize_t                                 BackWrite(const 
void* buffer, size_t size);
 
-                       status_t                                
SeekRequested(off_t position);
-                       status_t                                
SeekCompleted(off_t position);
-
 private:
                        status_t                                
_EvaluateWait(off_t position);
 
                        int32                                   fFlags;
-                       bigtime_t                               fTimeout;
 
                        RelativePositionIO*             fBuffer;
                        off_t                                   fTotalSize;
+                       bool                                    fOpened;
+                       sem_id                                  fSeekSem;
 
                        BInputAdapter*                  fInputAdapter;
 
diff --git a/src/kits/media/AdapterIO.cpp b/src/kits/media/AdapterIO.cpp
index 4cad54d..d9a5e7d 100644
--- a/src/kits/media/AdapterIO.cpp
+++ b/src/kits/media/AdapterIO.cpp
@@ -8,21 +8,23 @@
 
 #include <MediaIO.h>
 
-#include <stdio.h>
-
 #include "debug.h"
 
 
+#define TIMEOUT_QUANTA 100000
+
+
 class RelativePositionIO : public BPositionIO
 {
 public:
-       RelativePositionIO(BAdapterIO* owner, BPositionIO* buffer)
+       RelativePositionIO(BAdapterIO* owner, BPositionIO* buffer, bigtime_t 
timeout)
                :
                BPositionIO(),
                fOwner(owner),
                fBackPosition(0),
                fStartOffset(0),
-               fBuffer(buffer)
+               fBuffer(buffer),
+               fTimeout(timeout)
        {
                fOwner->GetFlags(&fFlags);
        }
@@ -84,8 +86,15 @@ public:
                if (ret != B_OK)
                        return B_ERROR;
 
-               while(bufferSize < position) {
-                       snooze(100000);
+               bigtime_t totalTimeOut = 0;
+
+               while(bufferSize <= position) {
+                       if (fTimeout != B_INFINITE_TIMEOUT && totalTimeOut >= 
fTimeout)
+                               return B_TIMED_OUT;
+
+                       snooze(TIMEOUT_QUANTA);
+
+                       totalTimeOut += TIMEOUT_QUANTA;
                        GetSize(&bufferSize);
                }
                return B_OK;
@@ -147,10 +156,15 @@ public:
        {
                AutoWriteLocker _(fLock);
 
-               off_t currentPos = Position();
                off_t ret = fBuffer->WriteAt(fBackPosition, buffer, size);
                fBackPosition += ret;
-               return fBuffer->Seek(currentPos, SEEK_SET);
+               return ret;
+       }
+
+       void SetBuffer(BPositionIO* buffer)
+       {
+               delete fBuffer;
+               fBuffer = buffer;
        }
 
        bool IsStreaming() const
@@ -188,19 +202,26 @@ private:
        int32                           fFlags;
 
        mutable RWLocker        fLock;
+
+       bigtime_t                       fTimeout;
 };
 
 
 BAdapterIO::BAdapterIO(int32 flags, bigtime_t timeout)
        :
        fFlags(flags),
-       fTimeout(timeout),
        fBuffer(NULL),
+       fTotalSize(0),
+       fOpened(false),
+       fSeekSem(-1),
        fInputAdapter(NULL)
 {
        CALLED();
 
-       fBuffer = new RelativePositionIO(this, new BMallocIO());
+       fBuffer = new RelativePositionIO(this, new BMallocIO(), timeout);
+
+       if (fBuffer->IsSeekable())
+               fSeekSem = create_sem(0, "BAdapterIO seek sem");
 }
 
 
@@ -214,6 +235,8 @@ BAdapterIO::~BAdapterIO()
 {
        CALLED();
 
+       Close();
+
        delete fInputAdapter;
        delete fBuffer;
 }
@@ -233,7 +256,8 @@ BAdapterIO::ReadAt(off_t position, void* buffer, size_t 
size)
 {
        CALLED();
 
-       printf("read at %d  %d \n", (int)position, (int)size);
+       TRACE("BAdapterIO::ReadAt %" B_PRId64 " %" B_PRId64 "\n", position, 
size);
+
        status_t ret = _EvaluateWait(position+size);
        if (ret != B_OK)
                return ret;
@@ -260,6 +284,7 @@ BAdapterIO::Seek(off_t position, uint32 seekMode)
 {
        CALLED();
 
+       // TODO: Support seekModes
        status_t ret = _EvaluateWait(position);
        if (ret != B_OK)
                return ret;
@@ -305,34 +330,43 @@ BAdapterIO::GetSize(off_t* size) const
 }
 
 
-ssize_t
-BAdapterIO::BackWrite(const void* buffer, size_t size)
+status_t
+BAdapterIO::Open()
 {
        CALLED();
 
-       return fBuffer->BackWrite(buffer, size);
+       fOpened = true;
+       return B_OK;
 }
 
 
-status_t
-BAdapterIO::_EvaluateWait(off_t pos)
+void
+BAdapterIO::Close()
 {
        CALLED();
 
-       status_t err = fBuffer->EvaluatePosition(pos);
+       fOpened = false;
+}
 
-       if (err != B_WOULD_BLOCK) {
-               if (err != B_RESOURCE_UNAVAILABLE && err != B_OK)
-                       return B_UNSUPPORTED;
 
-               if (err == B_RESOURCE_UNAVAILABLE && fBuffer->IsStreaming()
-                               && fBuffer->IsSeekable()) {
-                       if (SeekRequested(pos) != B_OK)
-                               return B_UNSUPPORTED;
-               }
-       }
+void
+BAdapterIO::SeekCompleted()
+{
+       CALLED();
+       release_sem(fSeekSem);
+}
 
-       return fBuffer->WaitForData(pos);
+
+status_t
+BAdapterIO::SetBuffer(BPositionIO* buffer)
+{
+       // We can't change the buffer while we
+       // are running.
+       if (fOpened)
+               return B_ERROR;
+
+       fBuffer->SetBuffer(buffer);
+       return B_OK;
 }
 
 
@@ -356,12 +390,37 @@ BAdapterIO::SeekRequested(off_t position)
 }
 
 
+ssize_t
+BAdapterIO::BackWrite(const void* buffer, size_t size)
+{
+       CALLED();
+
+       return fBuffer->BackWrite(buffer, size);
+}
+
+
 status_t
-BAdapterIO::SeekCompleted(off_t position)
+BAdapterIO::_EvaluateWait(off_t pos)
 {
        CALLED();
 
-       return fBuffer->ResetStartOffset(position);
+       status_t err = fBuffer->EvaluatePosition(pos);
+
+       if (err != B_WOULD_BLOCK) {
+               if (err != B_RESOURCE_UNAVAILABLE && err != B_OK)
+                       return B_UNSUPPORTED;
+
+               if (err == B_RESOURCE_UNAVAILABLE && fBuffer->IsStreaming()
+                               && fBuffer->IsSeekable()) {
+                       if (SeekRequested(pos) != B_OK)
+                               return B_UNSUPPORTED;
+
+                       acquire_sem(fSeekSem);
+                       fBuffer->ResetStartOffset(pos);
+               }
+       }
+
+       return fBuffer->WaitForData(pos);
 }
 
 

############################################################################

Commit:      93a1f9d274a4c2d0a54da4d90b5154acb26b6eb8
URL:         http://cgit.haiku-os.org/haiku/commit/?id=93a1f9d274a4
Author:      Dario Casalinuovo <b.vitruvio@xxxxxxxxx>
Date:        Thu Jun 30 14:30:07 2016 UTC

http_streamer: Sync with BAdapterIO changes

----------------------------------------------------------------------------

diff --git a/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.cpp 
b/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.cpp
index 26b79f3..fa7f72b 100644
--- a/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.cpp
+++ b/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.cpp
@@ -59,7 +59,7 @@ public:
                        delete request;
                }
 
-               off_t           TotalSize() const
+               off_t TotalSize() const
                {
                        return fTotalSize;
                }
@@ -74,43 +74,17 @@ private:
 
 HTTPMediaIO::HTTPMediaIO(BUrl url)
        :
-       BAdapterIO(
-               B_MEDIA_STREAMING | B_MEDIA_SEEK_BACKWARD,
-               B_INFINITE_TIMEOUT),
-       fInitErr(B_ERROR)
+       BAdapterIO(B_MEDIA_STREAMING | B_MEDIA_SEEK_BACKWARD, 
B_INFINITE_TIMEOUT),
+       fContext(NULL),
+       fReq(NULL),
+       fListener(NULL),
+       fUrl(url)
 {
-       fContext = new BUrlContext();
-       fContext->AcquireReference();
-
-       fListener = new FileListener(this);
-
-       fReq = BUrlProtocolRoster::MakeRequest(url,
-               fListener, fContext);
-
-       if (fReq == NULL)
-               return;
-
-       if (fReq->Run() < 0)
-               return;
-
-       fInitErr = B_OK;
 }
 
 
 HTTPMediaIO::~HTTPMediaIO()
 {
-       delete fReq;
-       delete fListener;
-
-       fContext->ReleaseReference();
-       delete fContext;
-}
-
-
-status_t
-HTTPMediaIO::InitCheck() const
-{
-       return fInitErr;
 }
 
 
@@ -134,3 +108,44 @@ HTTPMediaIO::GetSize(off_t* size) const
        *size = fListener->TotalSize();
        return B_OK;
 }
+
+
+status_t
+HTTPMediaIO::Open()
+{
+       fContext = new BUrlContext();
+       fContext->AcquireReference();
+
+       fListener = new FileListener(this);
+
+       fReq = BUrlProtocolRoster::MakeRequest(fUrl,
+               fListener, fContext);
+
+       if (fReq == NULL)
+               return B_ERROR;
+
+       if (fReq->Run() < 0)
+               return B_ERROR;
+
+       return BAdapterIO::Open();
+}
+
+
+void
+HTTPMediaIO::Close()
+{
+       delete fReq;
+       delete fListener;
+
+       fContext->ReleaseReference();
+       delete fContext;
+
+       BAdapterIO::Close();
+}
+
+
+status_t
+HTTPMediaIO::SeekRequested(off_t position)
+{
+       return BAdapterIO::SeekRequested(position);
+}
diff --git a/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.h 
b/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.h
index cc4634e..598105f 100644
--- a/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.h
+++ b/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.h
@@ -20,20 +20,24 @@ public:
                                                                                
HTTPMediaIO(BUrl url);
        virtual                                                         
~HTTPMediaIO();
 
-                       status_t                                        
InitCheck() const;
-
        virtual ssize_t                                         WriteAt(off_t 
position,
                                                                                
        const void* buffer, size_t size);
 
        virtual status_t                                        SetSize(off_t 
size);
        virtual status_t                                        GetSize(off_t* 
size) const;
 
+       virtual status_t                                        Open();
+       virtual void                                            Close();
+
+protected:
+       virtual status_t                                        
SeekRequested(off_t position);
+
 private:
        BUrlContext*                                            fContext;
        BUrlRequest*                                            fReq;
        FileListener*                                           fListener;
 
-       status_t                                                        
fInitErr;
+       BUrl                                                            fUrl;
 };
 
 #endif
diff --git a/src/add-ons/media/plugins/http_streamer/HTTPStreamerPlugin.cpp 
b/src/add-ons/media/plugins/http_streamer/HTTPStreamerPlugin.cpp
index eb49d88..60f5dac 100644
--- a/src/add-ons/media/plugins/http_streamer/HTTPStreamerPlugin.cpp
+++ b/src/add-ons/media/plugins/http_streamer/HTTPStreamerPlugin.cpp
@@ -22,13 +22,14 @@ HTTPStreamer::~HTTPStreamer()
 status_t
 HTTPStreamer::Sniff(const BUrl& url, BDataIO** source)
 {
-       HTTPMediaIO* ret = new HTTPMediaIO(url);
-       if (ret->InitCheck() == B_OK) {
-               *source = ret;
+       HTTPMediaIO* outSource = new HTTPMediaIO(url);
+       status_t ret = outSource->Open();
+       if (ret == B_OK) {
+               *source = outSource;
                return B_OK;
        }
-       delete ret;
-       return B_ERROR;
+       delete outSource;
+       return ret;
 }
 
 

############################################################################

Revision:    hrev50379
Commit:      1acb1f504ddcefa7134a12c6c3873d88bc58a274
URL:         http://cgit.haiku-os.org/haiku/commit/?id=1acb1f504ddc
Author:      Dario Casalinuovo <b.vitruvio@xxxxxxxxx>
Date:        Thu Jun 30 14:35:50 2016 UTC

Style fixes

----------------------------------------------------------------------------

diff --git a/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.cpp 
b/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.cpp
index fa7f72b..9e198d3 100644
--- a/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.cpp
+++ b/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.cpp
@@ -12,8 +12,7 @@
 #include <stdio.h>
 
 
-class FileListener : public BUrlProtocolAsynchronousListener
-{
+class FileListener : public BUrlProtocolAsynchronousListener {
 public:
                FileListener(BAdapterIO* owner)
                        :
diff --git a/src/kits/media/AdapterIO.cpp b/src/kits/media/AdapterIO.cpp
index d9a5e7d..7a7cc19 100644
--- a/src/kits/media/AdapterIO.cpp
+++ b/src/kits/media/AdapterIO.cpp
@@ -14,8 +14,7 @@
 #define TIMEOUT_QUANTA 100000
 
 
-class RelativePositionIO : public BPositionIO
-{
+class RelativePositionIO : public BPositionIO {
 public:
        RelativePositionIO(BAdapterIO* owner, BPositionIO* buffer, bigtime_t 
timeout)
                :



Other related posts:

  • » [haiku-commits] haiku: hrev50379 - src/apps/mediaplayer src/apps/mediaplayer/playlist src/kits/media src/add-ons/media/plugins/http_streamer headers/private/media - b . vitruvio