hrev49985 adds 4 changesets to branch 'master'
old head: b0c69e8490312c7dacdce7429c5f811c4037c4e9
new head: 6f5971cf52bcab0f9cfcc203bdc8b62e3c9d8fec
overview:
http://cgit.haiku-os.org/haiku/log/?qt=range&q=6f5971cf52bc+%5Eb0c69e849031
----------------------------------------------------------------------------
beddc8eefa12: MediaPlayer: Add missing null check
Signed-off-by: Dario Casalinuovo <b.vitruvio@xxxxxxxxx>
[ Markus Himmel <markus@xxxxxxxxxxxxxxxxx> ]
1c68b67a36bd: MediaPlayer: Show total playlist length
Signed-off-by: Dario Casalinuovo <b.vitruvio@xxxxxxxxx>
[ Markus Himmel <markus@xxxxxxxxxxxxxxxxx> ]
466081d08a99: When realloc(address, size) returns NULL, address must be freed
manually.
Signed-off-by: Dario Casalinuovo <b.vitruvio@xxxxxxxxx>
[ Phil Costin <philcostin@xxxxxxxxxxx> ]
6f5971cf52bc: Follow-up fix for #12152 from axeld suggestions
[ Dario Casalinuovo <b.vitruvio@xxxxxxxxx> ]
----------------------------------------------------------------------------
7 files changed, 239 insertions(+), 15 deletions(-)
src/add-ons/kernel/network/stack/interfaces.cpp | 5 +-
src/apps/mediaplayer/Controller.cpp | 3 +-
.../mediaplayer/playlist/FilePlaylistItem.cpp | 18 +-
src/apps/mediaplayer/playlist/FilePlaylistItem.h | 2 +-
src/apps/mediaplayer/playlist/PlaylistItem.h | 5 +-
src/apps/mediaplayer/playlist/PlaylistWindow.cpp | 187 ++++++++++++++++++-
src/apps/mediaplayer/playlist/PlaylistWindow.h | 34 +++-
############################################################################
Commit: beddc8eefa12b83e06b959605bda94a6a9ec83ed
URL: http://cgit.haiku-os.org/haiku/commit/?id=beddc8eefa12
Author: Markus Himmel <markus@xxxxxxxxxxxxxxxxx>
Date: Mon Jan 4 22:06:28 2016 UTC
Committer: Dario Casalinuovo <b.vitruvio@xxxxxxxxx>
Commit-Date: Wed Jan 6 12:17:39 2016 UTC
MediaPlayer: Add missing null check
Signed-off-by: Dario Casalinuovo <b.vitruvio@xxxxxxxxx>
----------------------------------------------------------------------------
diff --git a/src/apps/mediaplayer/Controller.cpp
b/src/apps/mediaplayer/Controller.cpp
index 5176a3d..f555cc8 100644
--- a/src/apps/mediaplayer/Controller.cpp
+++ b/src/apps/mediaplayer/Controller.cpp
@@ -302,7 +302,8 @@ Controller::SetTo(const PlaylistItemRef& item)
trackSupplierDeleter.Detach();
// prevent blocking the creation of new overlay buffers
- fVideoView->DisableOverlay();
+ if (fVideoView)
+ fVideoView->DisableOverlay();
// get video properties (if there is video at all)
bool useOverlays = fVideoView ? fVideoView->UseOverlays() : true;
############################################################################
Commit: 1c68b67a36bddb3f444094c305c6a5f3868d77ee
URL: http://cgit.haiku-os.org/haiku/commit/?id=1c68b67a36bd
Author: Markus Himmel <markus@xxxxxxxxxxxxxxxxx>
Date: Mon Jan 4 22:08:04 2016 UTC
Committer: Dario Casalinuovo <b.vitruvio@xxxxxxxxx>
Commit-Date: Wed Jan 6 12:17:40 2016 UTC
MediaPlayer: Show total playlist length
Signed-off-by: Dario Casalinuovo <b.vitruvio@xxxxxxxxx>
----------------------------------------------------------------------------
diff --git a/src/apps/mediaplayer/playlist/FilePlaylistItem.cpp
b/src/apps/mediaplayer/playlist/FilePlaylistItem.cpp
index 4b1cafd..9279fe1 100644
--- a/src/apps/mediaplayer/playlist/FilePlaylistItem.cpp
+++ b/src/apps/mediaplayer/playlist/FilePlaylistItem.cpp
@@ -190,7 +190,13 @@ status_t
FilePlaylistItem::SetAttribute(const Attribute& attribute,
const int64& value)
{
- return B_NOT_SUPPORTED;
+ switch (attribute) {
+ case ATTR_INT64_DURATION:
+ return _SetAttribute("Media:Length", B_INT64_TYPE,
&value,
+ sizeof(int64));
+ default:
+ return B_NOT_SUPPORTED;
+ }
}
@@ -198,7 +204,13 @@ status_t
FilePlaylistItem::GetAttribute(const Attribute& attribute,
int64& value) const
{
- return B_NOT_SUPPORTED;
+ switch (attribute) {
+ case ATTR_INT64_DURATION:
+ return _GetAttribute("Media:Length", B_INT64_TYPE,
&value,
+ sizeof(int64));
+ default:
+ return B_NOT_SUPPORTED;
+ }
}
@@ -407,7 +419,7 @@ FilePlaylistItem::_SetAttribute(const char* attrName,
type_code type,
status_t
FilePlaylistItem::_GetAttribute(const char* attrName, type_code type,
- void* data, size_t size)
+ void* data, size_t size) const
{
BEntry entry(&fRefs[0], true);
BNode node(&entry);
diff --git a/src/apps/mediaplayer/playlist/FilePlaylistItem.h
b/src/apps/mediaplayer/playlist/FilePlaylistItem.h
index a0c4da4..fb72f9e 100644
--- a/src/apps/mediaplayer/playlist/FilePlaylistItem.h
+++ b/src/apps/mediaplayer/playlist/FilePlaylistItem.h
@@ -67,7 +67,7 @@ private:
size_t
size);
status_t _GetAttribute(const
char* attrName,
type_code type, void* data,
- size_t
size);
+ size_t
size) const;
status_t
_MoveIntoTrash(vector<entry_ref>* refs,
vector<BString>* namesInTrash);
status_t
_RestoreFromTrash(vector<entry_ref>* refs,
diff --git a/src/apps/mediaplayer/playlist/PlaylistItem.h
b/src/apps/mediaplayer/playlist/PlaylistItem.h
index b896df5..73de81a 100644
--- a/src/apps/mediaplayer/playlist/PlaylistItem.h
+++ b/src/apps/mediaplayer/playlist/PlaylistItem.h
@@ -49,11 +49,12 @@ public:
ATTR_STRING_TITLE = 'titl',
ATTR_STRING_AUDIO_BITRATE = 'abtr',
ATTR_STRING_VIDEO_BITRATE = 'vbtr',
- ATTR_STRING_DURATION = 'drtn',
ATTR_INT32_TRACK = 'trck',
ATTR_INT32_YEAR = 'year',
- ATTR_INT32_RATING = 'rtng'
+ ATTR_INT32_RATING = 'rtng',
+
+ ATTR_INT64_DURATION = 'drtn'
} Attribute;
virtual status_t SetAttribute(const Attribute&
attribute,
diff --git a/src/apps/mediaplayer/playlist/PlaylistWindow.cpp
b/src/apps/mediaplayer/playlist/PlaylistWindow.cpp
index 08ce627..fbea517 100644
--- a/src/apps/mediaplayer/playlist/PlaylistWindow.cpp
+++ b/src/apps/mediaplayer/playlist/PlaylistWindow.cpp
@@ -22,6 +22,8 @@
#include <File.h>
#include <FilePanel.h>
#include <Locale.h>
+#include <MediaFile.h>
+#include <MediaTrack.h>
#include <Menu.h>
#include <MenuBar.h>
#include <MenuItem.h>
@@ -31,12 +33,16 @@
#include <ScrollBar.h>
#include <ScrollView.h>
#include <String.h>
+#include <StringView.h>
+#include "AudioTrackSupplier.h"
#include "CommandStack.h"
+#include "DurationToString.h"
#include "MainApp.h"
#include "PlaylistListView.h"
#include "RWLocker.h"
-
+#include "TrackSupplier.h"
+#include "VideoTrackSupplier.h"
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "MediaPlayer-PlaylistWindow"
@@ -82,7 +88,8 @@ PlaylistWindow::PlaylistWindow(BRect frame, Playlist*
playlist,
fPlaylist(playlist),
fLocker(new RWLocker("command stack lock")),
fCommandStack(new CommandStack(fLocker)),
- fCommandStackListener(this)
+ fCommandStackListener(this),
+ fDurationListener(new DurationListener(*this))
{
frame = Bounds();
@@ -90,6 +97,7 @@ PlaylistWindow::PlaylistWindow(BRect frame, Playlist*
playlist,
// will adjust frame to account for menubar
frame.right -= B_V_SCROLL_BAR_WIDTH;
+ frame.bottom -= B_H_SCROLL_BAR_HEIGHT;
fListView = new PlaylistListView(frame, playlist, controller,
fCommandStack);
@@ -104,7 +112,23 @@ PlaylistWindow::PlaylistWindow(BRect frame, Playlist*
playlist,
// make it so the frame of the menubar is also the frame of
// the scroll bar (appears to be)
scrollBar->MoveBy(0, -1);
- scrollBar->ResizeBy(0, -(B_H_SCROLL_BAR_HEIGHT - 2));
+ scrollBar->ResizeBy(0, 2);
+ }
+
+ frame.top += frame.Height();
+ frame.bottom += B_H_SCROLL_BAR_HEIGHT;
+
+ fTotalDuration = new BStringView(frame, "fDuration", "",
+ B_FOLLOW_BOTTOM | B_FOLLOW_LEFT_RIGHT);
+ AddChild(fTotalDuration);
+
+ _UpdateTotalDuration(0);
+
+ {
+ BAutolock _(fPlaylist);
+
+ _QueryInitialDurations();
+ fPlaylist->AddListener(fDurationListener);
}
fCommandStack->AddListener(&fCommandStackListener);
@@ -121,6 +145,9 @@ PlaylistWindow::~PlaylistWindow()
fCommandStack->RemoveListener(&fCommandStackListener);
delete fCommandStack;
delete fLocker;
+
+ fPlaylist->RemoveListener(fDurationListener);
+ BMessenger(fDurationListener).SendMessage(B_QUIT_REQUESTED);
}
@@ -422,3 +449,157 @@ PlaylistWindow::_SavePlaylist(BEntry& origEntry, BEntry&
tempEntry,
info.SetType("application/x-vnd.haiku-playlist");
}
+
+void
+PlaylistWindow::_QueryInitialDurations()
+{
+ BAutolock lock(fPlaylist);
+
+ BMessage addMessage(MSG_PLAYLIST_ITEM_ADDED);
+ for (int32 i = 0; i < fPlaylist->CountItems(); i++) {
+ addMessage.AddPointer("item", fPlaylist->ItemAt(i));
+ addMessage.AddInt32("index", i);
+ }
+
+ BMessenger(fDurationListener).SendMessage(&addMessage);
+}
+
+
+void
+PlaylistWindow::_UpdateTotalDuration(bigtime_t duration)
+{
+ BAutolock lock(this);
+
+ char buffer[64];
+ duration /= 1000000;
+ duration_to_string(duration, buffer, sizeof(buffer));
+
+ BString text;
+ text.SetToFormat(B_TRANSLATE("Total duration : %s"), buffer);
+
+ fTotalDuration->SetText(text.String());
+}
+
+
+// #pragma mark -
+
+
+PlaylistWindow::DurationListener::DurationListener(PlaylistWindow& parent)
+ :
+ PlaylistObserver(this),
+ fKnown(20, true),
+ fTotalDuration(0),
+ fParent(parent)
+{
+ Run();
+}
+
+
+PlaylistWindow::DurationListener::~DurationListener()
+{
+}
+
+
+void
+PlaylistWindow::DurationListener::MessageReceived(BMessage* message)
+{
+ switch (message->what) {
+ case MSG_PLAYLIST_ITEM_ADDED:
+ {
+ void* item;
+ int32 index;
+
+ int32 currentItem = 0;
+ while (message->FindPointer("item", currentItem, &item)
== B_OK
+ && message->FindInt32("index", currentItem,
&index) == B_OK) {
+
_HandleItemAdded(static_cast<PlaylistItem*>(item), index);
+ ++currentItem;
+ }
+
+ break;
+ }
+
+ case MSG_PLAYLIST_ITEM_REMOVED:
+ {
+ int32 index;
+
+ if (message->FindInt32("index", &index) == B_OK) {
+ _HandleItemRemoved(index);
+ }
+
+ break;
+ }
+
+ default:
+ BLooper::MessageReceived(message);
+ break;
+ }
+}
+
+
+bigtime_t
+PlaylistWindow::DurationListener::TotalDuration()
+{
+ return fTotalDuration;
+}
+
+
+void
+PlaylistWindow::DurationListener::_HandleItemAdded(PlaylistItem* item,
+ int32 index)
+{
+ bigtime_t duration = _DetermineItemDuration(item);
+ fTotalDuration += duration;
+ fParent._UpdateTotalDuration(fTotalDuration);
+ fKnown.AddItem(new bigtime_t(duration), index);
+}
+
+
+void
+PlaylistWindow::DurationListener::_HandleItemRemoved(int32 index)
+{
+ bigtime_t* deleted = fKnown.RemoveItemAt(index);
+ fTotalDuration -= *deleted;
+ fParent._UpdateTotalDuration(fTotalDuration);
+
+ delete deleted;
+}
+
+
+bigtime_t
+PlaylistWindow::DurationListener::_DetermineItemDuration(PlaylistItem* item)
+{
+ bigtime_t duration;
+ if (item->GetAttribute(PlaylistItem::ATTR_INT64_DURATION, duration) ==
B_OK)
+ return duration;
+
+ // We have to find out the duration ourselves
+ if (FilePlaylistItem* file = dynamic_cast<FilePlaylistItem*>(item)) {
+ // We are dealing with a file
+ BMediaFile mediaFile(&file->Ref());
+
+ if (mediaFile.InitCheck() != B_OK || mediaFile.CountTracks() <
1)
+ return 0;
+
+ duration = mediaFile.TrackAt(0)->Duration();
+ } else {
+ // Not a file, so fall back to the generic TrackSupplier
solution
+ TrackSupplier* supplier = item->CreateTrackSupplier();
+
+ AudioTrackSupplier* au = supplier->CreateAudioTrackForIndex(0);
+ VideoTrackSupplier* vi = supplier->CreateVideoTrackForIndex(0);
+
+ duration = max_c(au == NULL ? 0 : au->Duration(),
+ vi == NULL ? 0 : vi->Duration());
+
+ delete vi;
+ delete au;
+ delete supplier;
+ }
+
+ // Store the duration for later use
+ item->SetAttribute(PlaylistItem::ATTR_INT64_DURATION, duration);
+
+ return duration;
+}
+
diff --git a/src/apps/mediaplayer/playlist/PlaylistWindow.h
b/src/apps/mediaplayer/playlist/PlaylistWindow.h
index 2372385..6b70e76 100644
--- a/src/apps/mediaplayer/playlist/PlaylistWindow.h
+++ b/src/apps/mediaplayer/playlist/PlaylistWindow.h
@@ -11,8 +11,10 @@
#include <Entry.h>
+#include <ObjectList.h>
#include <Window.h>
+#include "PlaylistObserver.h"
#include "ListenerAdapter.h"
@@ -21,11 +23,11 @@ class BMenuItem;
class CommandStack;
class Controller;
class Notifier;
-class Playlist;
class PlaylistListView;
class RWLocker;
class BButton;
class BFilePanel;
+class BStringView;
enum {
@@ -53,12 +55,39 @@ public:
virtual void MessageReceived(BMessage*
message);
private:
+
+ class DurationListener : public PlaylistObserver, public BLooper {
+ public:
+
+
DurationListener(PlaylistWindow& parent);
+
~DurationListener();
+
+ void
MessageReceived(BMessage* message);
+
+ bigtime_t TotalDuration();
+
+ private:
+ void
_HandleItemAdded(PlaylistItem* item,
+ int32
index);
+ void
_HandleItemRemoved(int32 index);
+ bigtime_t
_DetermineItemDuration(PlaylistItem* item);
+
+ BObjectList<bigtime_t>
+ fKnown;
+ bigtime_t fTotalDuration;
+ PlaylistWindow& fParent;
+ };
+
+ friend class DurationListener;
+
void _CreateMenu(BRect&
frame);
void _ObjectChanged(const
Notifier* object);
void _SavePlaylist(const
BMessage* filePanelMessage);
void _SavePlaylist(const
entry_ref& ref);
void _SavePlaylist(BEntry&
origEntry,
BEntry&
tempEntry, const char* finalName);
+ void
_QueryInitialDurations();
+ void
_UpdateTotalDuration(bigtime_t duration);
Playlist* fPlaylist;
PlaylistListView* fListView;
@@ -72,6 +101,9 @@ private:
ListenerAdapter fCommandStackListener;
entry_ref fSavedPlaylistRef;
+
+ DurationListener* fDurationListener;
+ BStringView* fTotalDuration;
};
############################################################################
Commit: 466081d08a9933dd508b2e8d8bcfe42140e0b1b7
URL: http://cgit.haiku-os.org/haiku/commit/?id=466081d08a99
Author: Phil Costin <philcostin@xxxxxxxxxxx>
Date: Sat Jun 13 23:34:56 2015 UTC
Committer: Dario Casalinuovo <b.vitruvio@xxxxxxxxx>
Commit-Date: Wed Jan 6 12:17:40 2016 UTC
When realloc(address, size) returns NULL, address must be freed manually.
Signed-off-by: Dario Casalinuovo <b.vitruvio@xxxxxxxxx>
----------------------------------------------------------------------------
diff --git a/src/add-ons/kernel/network/stack/interfaces.cpp
b/src/add-ons/kernel/network/stack/interfaces.cpp
index ab2fa2d..fb13c5c 100644
--- a/src/add-ons/kernel/network/stack/interfaces.cpp
+++ b/src/add-ons/kernel/network/stack/interfaces.cpp
@@ -410,9 +410,14 @@ InterfaceAddress::Prepare(sockaddr** _address, size_t size)
sockaddr* address = *_address;
if (address == NULL || size > address->sa_len) {
- address = (sockaddr*)realloc(address, size);
- if (address == NULL)
+ sockaddr* resized = (sockaddr*)realloc(address, size);
+
+ if (resized == NULL) {
+ free(address);
return NULL;
+ }
+
+ address = resized;
}
address->sa_len = size;
############################################################################
Revision: hrev49985
Commit: 6f5971cf52bcab0f9cfcc203bdc8b62e3c9d8fec
URL: http://cgit.haiku-os.org/haiku/commit/?id=6f5971cf52bc
Author: Dario Casalinuovo <b.vitruvio@xxxxxxxxx>
Date: Wed Jan 6 11:46:22 2016 UTC
Ticket: https://dev.haiku-os.org/ticket/12152
Follow-up fix for #12152 from axeld suggestions
----------------------------------------------------------------------------
diff --git a/src/add-ons/kernel/network/stack/interfaces.cpp
b/src/add-ons/kernel/network/stack/interfaces.cpp
index fb13c5c..f7f6a4d 100644
--- a/src/add-ons/kernel/network/stack/interfaces.cpp
+++ b/src/add-ons/kernel/network/stack/interfaces.cpp
@@ -409,16 +409,8 @@ InterfaceAddress::Prepare(sockaddr** _address, size_t size)
sockaddr* address = *_address;
- if (address == NULL || size > address->sa_len) {
- sockaddr* resized = (sockaddr*)realloc(address, size);
-
- if (resized == NULL) {
- free(address);
- return NULL;
- }
-
- address = resized;
- }
+ if (address == NULL || size > address->sa_len)
+ address = (sockaddr*)realloc(address, size);
address->sa_len = size;