From korli at mail.berlios.de Mon Sep 1 00:52:55 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Mon, 1 Sep 2008 00:52:55 +0200 Subject: [Haiku-commits] r27259 - haiku/trunk/src/system/libroot/posix/glibc/arch/x86 Message-ID: <200808312252.m7VMqt34014056@sheep.berlios.de> Author: korli Date: 2008-09-01 00:52:54 +0200 (Mon, 01 Sep 2008) New Revision: 27259 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27259&view=rev Modified: haiku/trunk/src/system/libroot/posix/glibc/arch/x86/Jamfile Log: added s_signbitf.c for x86 Modified: haiku/trunk/src/system/libroot/posix/glibc/arch/x86/Jamfile =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/x86/Jamfile 2008-08-31 18:40:27 UTC (rev 27258) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/x86/Jamfile 2008-08-31 22:52:54 UTC (rev 27259) @@ -60,7 +60,7 @@ s_modf.c s_modff.c # s_modfl.c s_nan.c s_nanf.c s_nextafter.c - s_signbit.c s_signbitl.c + s_signbit.c s_signbitf.c s_signbitl.c s_round.c s_roundf.c # s_roundl.c s_signgam.c s_tanh.c s_tanhf.c From michael.w.pfeiffer at gmail.com Mon Sep 1 07:43:02 2008 From: michael.w.pfeiffer at gmail.com (Michael Pfeiffer) Date: Mon, 1 Sep 2008 07:43:02 +0200 Subject: [Haiku-commits] r27258 - haiku/trunk/src/apps/deskbar In-Reply-To: <48BAF0B9.7030800@zappotek.com> References: <200808311840.m7VIeSgT022438@sheep.berlios.de> <48BAF0B9.7030800@zappotek.com> Message-ID: Am 31.08.2008 um 21:27 schrieb Alexandre Deckner: > Michael Pfeiffer wrote: >> Am 31.08.2008 um 20:40 schrieb aldeck at BerliOS: >> >> >>> Author: aldeck >>> Date: 2008-08-31 20:40:27 +0200 (Sun, 31 Aug 2008) >>> New Revision: 27258 >>> ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27258&view=rev >>> >>> Added: >>> haiku/trunk/src/apps/deskbar/LongClickTracker.cpp >>> haiku/trunk/src/apps/deskbar/LongClickTracker.h >>> Modified: >>> haiku/trunk/src/apps/deskbar/Jamfile >>> haiku/trunk/src/apps/deskbar/TimeView.cpp >>> haiku/trunk/src/apps/deskbar/TimeView.h >>> Log: >>> * Rewrote long click mouse tracking. This avoids busy looping in >>> TimeView::MouseDown and fixes >>> #591. The helper class could be reused for similar situations (ex: >>> Tracker context menu and >>> drag detection). See the brief doc in the code. Comments welcomed! >>> >> >> Hmm. This problem could be solved more elegantly by using a >> BMessageRunner. This way the polling thread could be avoided >> completely. IIRC src/apps/pairs/PairsWindow.cpp uses BMessageRunner >> for a similar problem. > Thanks for having a look, i talked about that with Ren? and he told me > the same, but i didn't find my solution that ugly :) and still more > elegant than the previous impl! I did not want to say it in my first my mail, but IMHO it is ugly ;) 1) You need to poll, although that is not necessary. 2) You access the window and view from another thread, than the window thread, which should be avoided to prevent dead locks and avoid problems with thread safety (Can you guarantee that the view is not going to be deleted while the polling thread sill accesses it?). Your implementation has the potential for a dead lock too, for example if the destructor is called while the window lock is hold, it will dead lock if the polling thread tries to lock the window after snooze, since the destructor will wait for the termination of the polling thread, the lock will never be released. 3) You start a thread for each instance of LongClickTracker, that's a waste of resources, just imagine it was used for every replicant in the Deskbar or it would be used for each button in a tool bar. From your other mail. [Modularity] Agreed. However see my post to openbeos ML "How to open Calendar from Deskbar?" Which I had already sent yesterday, from a not subscribed mail address so it did not hit the ML. I have now resent it. [Performance] I disagree, the user is the slowest part when it comes to UI interaction. If you don't care, I can create an alternative implementation. - Michael From jackburton at mail.berlios.de Mon Sep 1 08:55:25 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Mon, 1 Sep 2008 08:55:25 +0200 Subject: [Haiku-commits] r27260 - haiku/trunk/src/tools/fs_shell Message-ID: <200809010655.m816tPAC010779@sheep.berlios.de> Author: jackburton Date: 2008-09-01 08:55:22 +0200 (Mon, 01 Sep 2008) New Revision: 27260 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27260&view=rev Modified: haiku/trunk/src/tools/fs_shell/file_map.cpp Log: fix the build Modified: haiku/trunk/src/tools/fs_shell/file_map.cpp =================================================================== --- haiku/trunk/src/tools/fs_shell/file_map.cpp 2008-08-31 22:52:54 UTC (rev 27259) +++ haiku/trunk/src/tools/fs_shell/file_map.cpp 2008-09-01 06:55:22 UTC (rev 27260) @@ -368,7 +368,7 @@ } if (offset + size > fSize) { if (align > 1) { - fssh_off_t alignedSize = (fSize + align - 1) & ~(off_t)(align - 1); + fssh_off_t alignedSize = (fSize + align - 1) & ~(fssh_off_t)(align - 1); if (offset + size >= alignedSize) padLastVec = alignedSize - fSize; } From jackburton at mail.berlios.de Mon Sep 1 10:18:51 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Mon, 1 Sep 2008 10:18:51 +0200 Subject: [Haiku-commits] r27261 - haiku/trunk/src/tests/kits/game/chart Message-ID: <200809010818.m818IpsS018406@sheep.berlios.de> Author: jackburton Date: 2008-09-01 10:18:49 +0200 (Mon, 01 Sep 2008) New Revision: 27261 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27261&view=rev Modified: haiku/trunk/src/tests/kits/game/chart/ChartWindow.cpp Log: fixed some warnings (gcc4) Modified: haiku/trunk/src/tests/kits/game/chart/ChartWindow.cpp =================================================================== --- haiku/trunk/src/tests/kits/game/chart/ChartWindow.cpp 2008-09-01 06:55:22 UTC (rev 27260) +++ haiku/trunk/src/tests/kits/game/chart/ChartWindow.cpp 2008-09-01 08:18:49 UTC (rev 27261) @@ -482,7 +482,7 @@ r.Set(h, v, h+INSTANT_LOAD-1, v + (TOP_LEFT_LIMIT - 1 - 2*V_BORDER)); fInstantLoad = new InstantView(r); fTopView->AddChild(fInstantLoad); - fInstantLoad->SetViewColor(0.0, 0.0, 0.0); + fInstantLoad->SetViewColor(0, 0, 0); h += INSTANT_LOAD+H_BORDER; @@ -1209,10 +1209,10 @@ B_FLOATING_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK); frame.OffsetTo(0.0, 0.0); - slider = new BSlider(frame, "", NULL, new BMessage(REFRESH_RATE_MSG), 0.0, 1000.0); + slider = new BSlider(frame, "", NULL, new BMessage(REFRESH_RATE_MSG), 0, 1000); slider->SetViewColor(background_color); slider->SetTarget(NULL, this); - slider->SetValue(1000.0*log(fCurrentSettings.refresh_rate/REFRESH_RATE_MIN)/log(REFRESH_RATE_MAX/REFRESH_RATE_MIN)); + slider->SetValue(1000*log(fCurrentSettings.refresh_rate/REFRESH_RATE_MIN)/log(REFRESH_RATE_MAX/REFRESH_RATE_MIN)); slider->SetModificationMessage(new BMessage(REFRESH_RATE_MSG)); slider->SetLimitLabels(" 0.6 f/s (logarythmic scale)", "600.0 f/s"); slider->ResizeToPreferred(); @@ -1255,18 +1255,21 @@ /* the new level is higher than the previous. We need to draw more colored bars. */ if (level > fInstantLoadLevel) { - for (i=fInstantLoadLevel; istep) fInstantLoad->SetHighColor(255.0, 90.0, 90.0); - else if ((i/fInstantLoad->step) & 1) fInstantLoad->SetHighColor(90.0, 255.0, 90.0); - else fInstantLoad->SetHighColor(40.0, 200.0, 40.0); - fInstantLoad->FillRect(BRect(3+i*4, 2, 5+i*4, 19)); + for (i = fInstantLoadLevel; i < level; i++) { + if (i < fInstantLoad->step) + fInstantLoad->SetHighColor(255, 90, 90); + else if ((i / fInstantLoad->step) & 1) + fInstantLoad->SetHighColor(90, 255, 90); + else + fInstantLoad->SetHighColor(40, 200, 40); + fInstantLoad->FillRect(BRect(3 + i * 4, 2, 5 + i * 4, 19)); } } /* the level is lower than before, we need to erase some bars. */ else { - fInstantLoad->SetHighColor(0.0, 0.0, 0.0); - for (i=level; i< fInstantLoadLevel; i++) - fInstantLoad->FillRect(BRect(3+i*4, 2, 5+i*4, 19)); + fInstantLoad->SetHighColor(0, 0, 0); + for (i = level; i < fInstantLoadLevel; i++) + fInstantLoad->FillRect(BRect(3 + i * 4, 2, 5 +i * 4, 19)); } /* we want that drawing to be completed as soon as possible */ Flush(); From stippi at mail.berlios.de Mon Sep 1 11:04:10 2008 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Mon, 1 Sep 2008 11:04:10 +0200 Subject: [Haiku-commits] r27262 - haiku/trunk/src/apps/aboutsystem Message-ID: <200809010904.m8194ARK022625@sheep.berlios.de> Author: stippi Date: 2008-09-01 11:04:09 +0200 (Mon, 01 Sep 2008) New Revision: 27262 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27262&view=rev Modified: haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp Log: First attempt at a more balanced Credits section: * Changed the copyright line to say "The Haiku project", similar to the GNU and BSD copyrights. Then a clarifying sentence as discussed on the developer mailing list. * Removed the outdated Team list in favor of a "Most influential developers" list with the top contributors of the past and the present in order of SVN commit numbers. It could be argued that Travis should be part of this list but he is already mentioned later with a special note. I used this wording to indicate that it could also mention no longer active, but still "most influential" developers. "Lead developers" or "Core developers" would not have this aspect. * Created a new "Website, Marketing & Documentation" section which gives hopefully all or at least most people a more prominent mention which are contributing most in this area. Waldemar Kornewald could be moved to this list as well. Koki was not mentioned anywhere before, which definitely needed to be corrected! :-) * Maurice Kalinowski and Fredrik Modeen are now commiters. * Added Andrej Spielmann (Subpixel Anti-aliasing) to the developers list, since he has commit access too now. * Added David Powell to list of contributors, for his recent patch to the boot splash generator and boot loader. * Added Copyright for CQuantizer (part of the mentioned patch from David) If you have suggestions for improvements, please shoot, especially if I forgot someone! Modified: haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp =================================================================== --- haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp 2008-09-01 08:18:49 UTC (rev 27261) +++ haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp 2008-09-01 09:04:09 UTC (rev 27262) @@ -201,7 +201,7 @@ r.OffsetBy(0, labelHeight); r.bottom = r.top + textHeight; - char string[256]; + char string[1024]; strcpy(string, "Unknown"); // the version is stored in the BEOS:APP_VERSION attribute of libbe.so @@ -354,44 +354,70 @@ B_PLAIN_BORDER); AddChild(creditsScroller); + // Haiku copyright BFont font(be_bold_font); font.SetSize(font.Size() + 4); fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &kHaikuGreen); fCreditsView->Insert("Haiku\n"); - font.SetSize(be_bold_font->Size()); - font.SetFace(B_BOLD_FACE | B_ITALIC_FACE); - time_t time = ::time(NULL); struct tm* tm = localtime(&time); int32 year = tm->tm_year + 1900; - if (year < 2007) - year = 2007; + if (year < 2008) + year = 2008; snprintf(string, sizeof(string), - "Copyright " B_UTF8_COPYRIGHT "2001-%ld Haiku, Inc.\n", year); + "Copyright " B_UTF8_COPYRIGHT " 2001-%ld The Haiku project.", year); fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &kDarkGrey); fCreditsView->Insert(string); + fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &kDarkGrey); + fCreditsView->Insert("The copyright to the Haiku code is property of " + "Haiku, Inc. or of the respective authors where expressly noted " + "in the source." + "\n\n"); + + fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &kLinkBlue); - fCreditsView->InsertHyperText("http://haiku-os.org", - new URLAction("http://haiku-os.org")); + fCreditsView->InsertHyperText("http://www.haiku-os.org", + new URLAction("http://www.haiku-os.org")); fCreditsView->Insert("\n\n"); + font.SetSize(be_bold_font->Size()); + font.SetFace(B_BOLD_FACE | B_ITALIC_FACE); + fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &kHaikuOrange); - fCreditsView->Insert("Team Leads:\n"); + fCreditsView->Insert("Most influential developers:\n"); fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &kDarkGrey); fCreditsView->Insert( "Axel D?rfler\n" + "Ingo Weinhold\n" + "Stephan A?mus\n" + "J?r?me Duval\n" + "Stefano Ceccherini\n" + "Fran?ois Revol\n" + "Marcus Overhagen\n" + "Michael Lotz\n" + "Rudolf Cornelissen\n" + "\n"); + + + fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &kHaikuOrange); + fCreditsView->Insert("Website, Marketing & Documention:\n"); + + fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &kDarkGrey); + fCreditsView->Insert( "Phil Greenway\n" - "Philippe Houdoin\n" - "Marcus Overhagen\n" - "Ingo Weinhold\n" + "Gavin James\n" + "Jorge G. Mare\n" + "Urias McCullough\n" + "Niels Sascha Reedijk\n" "Jonathan Yoder\n" "\n"); + fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &kHaikuOrange); fCreditsView->Insert("Developers:\n"); @@ -399,26 +425,23 @@ fCreditsView->Insert( "Ithamar R. Adema\n" "Bruno G. Albuquerque\n" - "Stephan A?mus\n" "Andrew Bachmann\n" "Salvatore Benedetto\n" - "Stefano Ceccherini\n" - "Rudolf Cornelissen\n" "Alexandre Deckner\n" "Oliver Ruiz Dorantes\n" - "J?r?me Duval\n" "Andre Alves Garzia\n" "Ren? Gollent\n" "Karsten Heimrich\n" + "Philippe Houdoin\n" + "Maurice Kalinowski\n" "Euan Kirkhope\n" "Waldemar Kornewald\n" "Ryan Leavengood\n" - "Michael Lotz\n" "David McPaul\n" + "Fredrik Mod?en\n" "Michael Pfeiffer\n" - "Niels Sascha Reedijk\n" - "Fran?ois Revol\n" "Hugo Santos\n" + "Andrej Spielmann\n" "Jonas Sundstr?m\n" "Gerasim Troeglazov\n" "Bryan Varner\n" @@ -447,7 +470,6 @@ "Morgan Howe\n" "Erik Jaesler\n" "Carwyn Jones\n" - "Maurice Kalinowski\n" "Vasilis Kaoutsis\n" "James Kim\n" "Shintaro Kinugawa\n" @@ -471,12 +493,10 @@ "Christopher ML Zumwalt May\n" "Andrew McCall\n" "Scott McCreary\n" - "Urias McCullough\n" "Michele (zuMi)\n" "Marius Middelthon\n" "Marco Minutoli\n" "Misza\n" - "Fredrik Mod?en\n" "MrSiggler\n" "Alan Murta\n" "Frans Van Nispen\n" @@ -484,6 +504,7 @@ "Pahtz\n" "Michael Paine\n" "Michael Phipps\n" + "David Powell\n" "Jeremy Rand\n" "Hartmut Reh\n" "David Reid\n" @@ -728,6 +749,11 @@ "All rights reserved.", "http://www.matroska.org"); + // BColorQuantizer (originally CQuantizer code) + AddCopyrightEntry("CQuantizer", + "Copyright " B_UTF8_COPYRIGHT " 1996-1997 Jeff Prosise. " + "All rights reserved."); + // OpenSound // AddCopyrightEntry("OpenSound", // "Copyright " B_UTF8_COPYRIGHT " 1996-2008 4Front Technologies ", From stippi at mail.berlios.de Mon Sep 1 11:29:12 2008 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Mon, 1 Sep 2008 11:29:12 +0200 Subject: [Haiku-commits] r27263 - haiku/trunk/src/apps/aboutsystem Message-ID: <200809010929.m819TCrL029326@sheep.berlios.de> Author: stippi Date: 2008-09-01 11:29:11 +0200 (Mon, 01 Sep 2008) New Revision: 27263 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27263&view=rev Modified: haiku/trunk/src/apps/aboutsystem/HyperTextView.cpp haiku/trunk/src/apps/aboutsystem/HyperTextView.h Log: Display the hand cursor over clickable URLs and other HyperTextView actions. Modified: haiku/trunk/src/apps/aboutsystem/HyperTextView.cpp =================================================================== --- haiku/trunk/src/apps/aboutsystem/HyperTextView.cpp 2008-09-01 09:04:09 UTC (rev 27262) +++ haiku/trunk/src/apps/aboutsystem/HyperTextView.cpp 2008-09-01 09:29:11 UTC (rev 27263) @@ -5,6 +5,7 @@ #include "HyperTextView.h" +#include #include #include #include @@ -26,6 +27,13 @@ void +HyperTextAction::MouseOver(HyperTextView* view, BPoint where, BMessage* message) +{ + view->SetViewCursor(B_CURSOR_SYSTEM_DEFAULT); +} + + +void HyperTextAction::Clicked(HyperTextView* view, BPoint where, BMessage* message) { } @@ -106,19 +114,27 @@ { BMessage* message = Window()->CurrentMessage(); - int32 offset = OffsetAt(where); + HyperTextAction* action = _ActionAt(where); + if (action != NULL) + action->Clicked(this, where, message); +} - ActionInfo pointer(offset, offset + 1, NULL); - const ActionInfo* action = fActionInfos->BinarySearch(pointer, - ActionInfo::CompareEqualIfIntersecting); - if (action != NULL) { - // verify that the text region was hit - BRegion textRegion; - GetTextRegion(action->startOffset, action->endOffset, &textRegion); - if (textRegion.Contains(where)) - action->action->Clicked(this, where, message); +void +HyperTextView::MouseMoved(BPoint where, uint32 transit, + const BMessage* dragMessage) +{ + BMessage* message = Window()->CurrentMessage(); + + uint32 buttons; + HyperTextAction* action; + if (message->FindInt32("buttons", (int32*)&buttons) == B_OK + && buttons == 0 && (action = _ActionAt(where)) != NULL) { + action->MouseOver(this, where, message); + return; } + + BTextView::MouseMoved(where, transit, dragMessage); } @@ -160,3 +176,25 @@ AddHyperTextAction(startOffset, endOffset, action); } + + +HyperTextAction* +HyperTextView::_ActionAt(const BPoint& where) const +{ + int32 offset = OffsetAt(where); + + ActionInfo pointer(offset, offset + 1, NULL); + + const ActionInfo* action = fActionInfos->BinarySearch(pointer, + ActionInfo::CompareEqualIfIntersecting); + if (action != NULL) { + // verify that the text region was hit + BRegion textRegion; + GetTextRegion(action->startOffset, action->endOffset, &textRegion); + if (textRegion.Contains(where)) + return action->action; + } + + return NULL; +} + Modified: haiku/trunk/src/apps/aboutsystem/HyperTextView.h =================================================================== --- haiku/trunk/src/apps/aboutsystem/HyperTextView.h 2008-09-01 09:04:09 UTC (rev 27262) +++ haiku/trunk/src/apps/aboutsystem/HyperTextView.h 2008-09-01 09:29:11 UTC (rev 27263) @@ -20,6 +20,8 @@ HyperTextAction(); virtual ~HyperTextAction(); + virtual void MouseOver(HyperTextView* view, BPoint where, + BMessage* message); virtual void Clicked(HyperTextView* view, BPoint where, BMessage* message); }; @@ -35,6 +37,8 @@ virtual void MouseDown(BPoint where); virtual void MouseUp(BPoint where); + virtual void MouseMoved(BPoint where, uint32 transit, + const BMessage* dragMessage); void AddHyperTextAction(int32 startOffset, int32 endOffset, HyperTextAction* action); @@ -46,6 +50,8 @@ int32 inLength, HyperTextAction* action, const text_run_array* inRuns = NULL); private: + HyperTextAction* _ActionAt(const BPoint& where) const; + struct ActionInfo; class ActionInfoList; From alex at zappotek.com Mon Sep 1 13:07:38 2008 From: alex at zappotek.com (Alexandre Deckner) Date: Mon, 01 Sep 2008 13:07:38 +0200 Subject: [Haiku-commits] r27258 - haiku/trunk/src/apps/deskbar In-Reply-To: References: <200808311840.m7VIeSgT022438@sheep.berlios.de> <48BAF0B9.7030800@zappotek.com> Message-ID: <48BBCCFA.8040603@zappotek.com> Michael Pfeiffer wrote: > Am 31.08.2008 um 21:27 schrieb Alexandre Deckner: > >>>> * Rewrote long click mouse tracking. This avoids busy looping in >>>> TimeView::MouseDown and fixes >>>> #591. The helper class could be reused for similar situations (ex: >>>> Tracker context menu and >>>> drag detection). See the brief doc in the code. Comments welcomed! >>>> >>>> >>> Hmm. This problem could be solved more elegantly by using a >>> BMessageRunner. This way the polling thread could be avoided >>> completely. IIRC src/apps/pairs/PairsWindow.cpp uses BMessageRunner >>> for a similar problem. >>> >> Thanks for having a look, i talked about that with Ren? and he told me >> the same, but i didn't find my solution that ugly :) and still more >> elegant than the previous impl! >> > > I did not want to say it in my first my mail, but IMHO it is ugly ;) > 1) You need to poll, although that is not necessary. > Ah? How can you know the duration of a mouse down otherwise? > 2) You access the window and view from another thread, than the window > thread, > which should be avoided to prevent dead locks and avoid problems > with thread safety (Can you guarantee that the view is not > going to be deleted while the polling thread sill accesses it?). > Yep, the object is always deleted before the view as it is a member. > Your implementation has the potential for a dead lock too, > for example if the destructor is called while the window lock is > hold, > it will dead lock if the polling thread tries to lock the window > after snooze, since the destructor will wait for the termination > of the polling thread, the lock will never be released. > Hmm, possible, i didn't think about this scenario yet. > 3) You start a thread for each instance of LongClickTracker, that's > a waste of resources, just imagine it was used for every replicant > in the Deskbar or it would be used for each button in a tool bar. > For now there's only one instance, i didn't have time to generalize to every scenario you imagined. I've seen lots of small threading solutions like mine in the codebase, so i thought it would be such a big deal. > From your other mail. > [Modularity] > Agreed. > However see my post to openbeos ML "How to open Calendar from > Deskbar?" Which I had already sent yesterday, from a not subscribed > mail address so it did not hit the ML. I have now resent it. > Well i had a fix ready for 9 days already (#591), i had to finish and commit it, i don't like letting fixes die. But there's no problem if you change the behaviour so that it's not needed anymore, i have other uses for it :) > [Performance] > I disagree, the user is the slowest part when it comes to UI > interaction. > I was talking about the cpu usage of the threaded impl. vs BMessageRunner impl. > If you don't care, I can create an alternative implementation. > > Yep, sincerely, go for it, i'm already on something else. Best regards, Alex From michael.w.pfeiffer at gmail.com Mon Sep 1 13:49:35 2008 From: michael.w.pfeiffer at gmail.com (Michael Pfeiffer) Date: Mon, 1 Sep 2008 13:49:35 +0200 Subject: [Haiku-commits] r27258 - haiku/trunk/src/apps/deskbar In-Reply-To: <48BBCCFA.8040603@zappotek.com> References: <200808311840.m7VIeSgT022438@sheep.berlios.de> <48BAF0B9.7030800@zappotek.com> <48BBCCFA.8040603@zappotek.com> Message-ID: <1FBB57E6-3687-4DDB-96E2-B0BB09BB5DD7@gmail.com> Am 01.09.2008 um 13:07 schrieb Alexandre Deckner: > Michael Pfeiffer wrote: >> Am 31.08.2008 um 21:27 schrieb Alexandre Deckner: >> >>>>> * Rewrote long click mouse tracking. This avoids busy looping in >>>>> TimeView::MouseDown and fixes >>>>> #591. The helper class could be reused for similar situations (ex: >>>>> Tracker context menu and >>>>> drag detection). See the brief doc in the code. Comments welcomed! >>>>> >>>>> >>>> Hmm. This problem could be solved more elegantly by using a >>>> BMessageRunner. This way the polling thread could be avoided >>>> completely. IIRC src/apps/pairs/PairsWindow.cpp uses BMessageRunner >>>> for a similar problem. >>>> >>> Thanks for having a look, i talked about that with Ren? and he >>> told me >>> the same, but i didn't find my solution that ugly :) and still more >>> elegant than the previous impl! >>> >> >> I did not want to say it in my first my mail, but IMHO it is ugly ;) >> 1) You need to poll, although that is not necessary. >> > Ah? How can you know the duration of a mouse down otherwise? You don't have to if you use a BMessageRunner. A brief outline of the algorithm I have in mind follows: 1) You have single pointer to BMesageRunner in your view initialized to NULL. 2) When the mouse button is clicked you start the one time message runner with the desired delay. 3) You stop the message runner when: - the mouse button is released - mouse moves outside the view (or restart it if mouse button is still pressed) - after the message runner message has been received 4) You perform the desired action when the message runner message receives. >> If you don't care, I can create an alternative implementation. >> >> > Yep, sincerely, go for it, i'm already on something else. Hope I didn't step on your shoes. I have added an extra smile in the line with the word "ugly" on purpose :) Now that I am reading it a second time, I have to apologize, I am sorry, I should not have written it in the first place. The rest of the mail was meant to be a constructive critique, though. - Michael From julun at mail.berlios.de Mon Sep 1 15:11:30 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Mon, 1 Sep 2008 15:11:30 +0200 Subject: [Haiku-commits] r27264 - in haiku/trunk: headers/private/shared src/kits/shared Message-ID: <200809011311.m81DBUXk017275@sheep.berlios.de> Author: julun Date: 2008-09-01 15:11:29 +0200 (Mon, 01 Sep 2008) New Revision: 27264 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27264&view=rev Modified: haiku/trunk/headers/private/shared/DateTime.h haiku/trunk/src/kits/shared/DateTime.cpp Log: * implement julian day handling * more get/ set functions, operators * date until 1582 are handled in julian calendar * date above 1582 are handled in gregorian calendar Modified: haiku/trunk/headers/private/shared/DateTime.h =================================================================== --- haiku/trunk/headers/private/shared/DateTime.h 2008-09-01 09:29:11 UTC (rev 27263) +++ haiku/trunk/headers/private/shared/DateTime.h 2008-09-01 13:11:29 UTC (rev 27264) @@ -47,9 +47,16 @@ ~BDate(); bool IsValid() const; + bool IsValid(const BDate& date) const; + bool IsValid(int32 year, int32 month, int32 day) const; static BDate CurrentDate(time_type type); + + BDate Date() const; + bool SetDate(const BDate& date); + bool SetDate(int32 year, int32 month, int32 day); + void GetDate(int32* year, int32* month, int32* day); void AddDays(int32 days); void AddYears(int32 years); @@ -58,6 +65,7 @@ int32 Day() const; int32 Year() const; int32 Month() const; + int32 Difference(const BDate& date) const; int32 DayOfWeek() const; int32 DayOfYear() const; @@ -74,7 +82,24 @@ BString LongDayName(int32 day) const; BString LongMonthName(int32 month) const; + int32 DateToJulianDay() const; + static BDate JulianDayToDate(int32 julianDay); + + bool operator!=(const BDate& date) const; + bool operator==(const BDate& date) const; + + bool operator<(const BDate& date) const; + bool operator<=(const BDate& date) const; + + bool operator>(const BDate& date) const; + bool operator>=(const BDate& date) const; + private: + int32 _DaysInMonth(int32 year, int32 month) const; + bool _SetDate(int32 year, int32 month, int32 day); + int32 _DateToJulianDay(int32 year, int32 month, int32 day) const; + + private: int32 fDay; int32 fYear; int32 fMonth; Modified: haiku/trunk/src/kits/shared/DateTime.cpp =================================================================== --- haiku/trunk/src/kits/shared/DateTime.cpp 2008-09-01 09:29:11 UTC (rev 27263) +++ haiku/trunk/src/kits/shared/DateTime.cpp 2008-09-01 13:11:29 UTC (rev 27264) @@ -7,7 +7,7 @@ * Stephan A?mus */ -#include "DateTime.h" +#include #include @@ -104,7 +104,7 @@ } -// #pragma mark - +// #pragma mark - BDate BDate::BDate() @@ -116,10 +116,8 @@ BDate::BDate(int32 year, int32 month, int32 day) - : fDay(day), - fYear(year), - fMonth(month) { + _SetDate(year, month, day); } @@ -131,17 +129,36 @@ bool BDate::IsValid() const { - // fail if the year goes less 1583 - // 10/15/1582 start of Gregorian calendar - if (fYear < 1583) + return IsValid(fYear, fMonth, fDay); +} + + +bool +BDate::IsValid(const BDate& date) const +{ + return IsValid(date.fYear, date.fMonth, date.fDay); +} + + +bool +BDate::IsValid(int32 year, int32 month, int32 day) const +{ + // no year 0 in Julian and we can't handle nothing before 1.1.4713 BC + if (year == 0 || year < -4713 + || (year == -4713 && month < 1) + || (year == -4713 && month < 1 && day < 1)) return false; - if (fMonth < 1 || fMonth > 12) + // 'missing' days between switch julian - gregorian + if (year == 1582 && month == 10 && day > 4 && day < 15) return false; - if (fDay < 1 || fDay > DaysInMonth()) + if (month < 1 || month > 12) return false; + if (day < 1 || day > _DaysInMonth(year, month)) + return false; + return true; } @@ -164,41 +181,45 @@ } +BDate +BDate::Date() const +{ + return BDate(fYear, fMonth, fDay); +} + + bool +BDate::SetDate(const BDate& date) +{ + return _SetDate(date.fYear, fMonth, fDay); +} + + +bool BDate::SetDate(int32 year, int32 month, int32 day) { - fDay = day; - fYear = year; - fMonth = month; + return _SetDate(year, month, day); +} - return IsValid(); + +void +BDate::GetDate(int32* year, int32* month, int32* day) +{ + if (year) + *year = fYear; + + if (month) + *month = fMonth; + + if (day) + *day = fDay; } void BDate::AddDays(int32 days) { - days += Day(); - if (days > 0) { - while (days > DaysInMonth()) { - days -= DaysInMonth(); - fMonth ++; - if (fMonth == 13) { - fMonth = 1; - fYear ++; - } - } - } else { - while (days <= 0) { - fMonth --; - if (fMonth == 0) { - fMonth = 12; - fYear --; - } - days += DaysInMonth(); - } - } - fDay = days; + *this = JulianDayToDate(DateToJulianDay() + days); } @@ -206,38 +227,22 @@ BDate::AddYears(int32 years) { fYear += years; - fDay = min_c(fDay, DaysInMonth()); + fDay = min_c(fDay, _DaysInMonth(fYear, fMonth)); } void BDate::AddMonths(int32 months) { - if (months == 0) - return; + fYear += months / 12; + fMonth += months % 12; - if (months > 0) { - while (months > 0) { - fYear++; - months -= 12; - } - - fMonth += months; - if (fMonth < 1) { - fYear--; - fMonth += 12; - } - } else { - while (months < 0) { - fYear--; - months += 12; - } - - fMonth += months; - if (fMonth > 12) { - fYear++; - fMonth -= 12; - } + if (fMonth > 12) { + fYear++; + fMonth -= 12; + } else if (fMonth < 1) { + fYear--; + fMonth += 12; } fDay = min_c(fDay, DaysInMonth()); } @@ -265,6 +270,13 @@ int32 +BDate::Difference(const BDate& date) const +{ + return DateToJulianDay() - date.DateToJulianDay(); +} + + +int32 BDate::WeekNumber() const { /* @@ -275,7 +287,9 @@ Note: it will work only within the Gregorian Calendar */ - if (!IsValid()) + if (!IsValid() || fYear < 1582 + || (fYear == 1582 && fMonth < 10) + || (fYear == 1582 && fMonth == 10 && fDay < 15)) return 0; int32 a; @@ -320,56 +334,25 @@ int32 BDate::DayOfWeek() const { - /* - This algorithm is taken from: - Frequently Asked Questions about Calendars - Version 2.8 Claus T?ndering 15 December 2005 - - Note: it will work only within the Gregorian Calendar - */ - - if (!IsValid()) - return -1; - - int32 a = (14 - fMonth) / 12; - int32 y = fYear - a; - int32 m = fMonth + 12 * a - 2; - int32 d = (fDay + y + (y / 4) - (y / 100) + (y / 400) + ((31 * m) / 12)) % 7; - - return d; + // http://en.wikipedia.org/wiki/Julian_day#Calculation + return (DateToJulianDay() % 7) + 1; } int32 BDate::DayOfYear() const { - /* - Note: this function might fail for 1582... - - http://en.wikipedia.org/wiki/Gregorian_calendar: - The last day of the Julian calendar was Thursday October 4, 1582 - and this was followed by the first day of the Gregorian calendar, - Friday October 15, 1582 (the cycle of weekdays was not affected). - */ - - if (!IsValid()) - return -1; - - const int kFirstDayOfMonth[2][12] = { - { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }, - { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 } - }; - - if (IsLeapYear(fYear)) - return kFirstDayOfMonth[1][fMonth -1] + fDay; - - return kFirstDayOfMonth[0][fMonth -1] + fDay; + return DateToJulianDay() - _DateToJulianDay(fYear, 1, 1) + 1; } bool BDate::IsLeapYear(int32 year) const { + if (year < 1582) { + if (year < 0) year++; + return (year % 4) == 0; + } return year % 400 == 0 || year % 4 == 0 && year % 100 != 0; } @@ -387,13 +370,7 @@ int32 BDate::DaysInMonth() const { - if (fMonth == 2 && IsLeapYear(fYear)) - return 29; - - const int32 daysInMonth[12] = - {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - - return daysInMonth[fMonth -1]; + return _DaysInMonth(fYear, fMonth); } @@ -465,9 +442,155 @@ } -// #pragma mark - +int32 +BDate::DateToJulianDay() const +{ + return _DateToJulianDay(fYear, fMonth, fDay); +} +BDate +BDate::JulianDayToDate(int32 julianDay) +{ + BDate date; + const int32 kGregorianCalendarStart = 2299161; + if (julianDay >= kGregorianCalendarStart) { + // http://en.wikipedia.org/wiki/Julian_day#Gregorian_calendar_from_Julian_day_number + int32 j = julianDay + 32044; + int32 dg = j % 146097; + int32 c = (dg / 36524 + 1) * 3 / 4; + int32 dc = dg - c * 36524; + int32 db = dc % 1461; + int32 a = (db / 365 + 1) * 3 / 4; + int32 da = db - a * 365; + int32 m = (da * 5 + 308) / 153 - 2; + date.fYear = ((j / 146097) * 400 + c * 100 + (dc / 1461) * 4 + a) - 4800 + + (m + 2) / 12; + date.fMonth = (m + 2) % 12 + 1; + date.fDay = int32((da - (m + 4) * 153 / 5 + 122) + 1.5); + } else { + // http://en.wikipedia.org/wiki/Julian_day#Calculation + julianDay += 32082; + int32 d = (4 * julianDay + 3) / 1461; + int32 e = julianDay - (1461 * d) / 4; + int32 m = ((5 * e) + 2) / 153; + date.fDay = e - (153 * m + 2) / 5 + 1; + date.fMonth = m + 3 - 12 * (m / 10); + int32 year = d - 4800 + (m / 10); + if (year <= 0) + year--; + date.fYear = year; + } + return date; +} + + +bool +BDate::operator!=(const BDate& date) const +{ + return DateToJulianDay() != date.DateToJulianDay(); +} + + +bool +BDate::operator==(const BDate& date) const +{ + return DateToJulianDay() == date.DateToJulianDay(); +} + + +bool +BDate::operator<(const BDate& date) const +{ + return DateToJulianDay() < date.DateToJulianDay(); +} + + +bool +BDate::operator<=(const BDate& date) const +{ + return DateToJulianDay() <= date.DateToJulianDay(); +} + + +bool +BDate::operator>(const BDate& date) const +{ + return DateToJulianDay() > date.DateToJulianDay(); +} + + +bool +BDate::operator>=(const BDate& date) const +{ + return DateToJulianDay() >= date.DateToJulianDay(); +} + + +bool +BDate::_SetDate(int32 year, int32 month, int32 day) +{ + fDay = -1; + fYear = -1; + fMonth = -1; + + bool valid = IsValid(year, month, day); + if (valid) { + fDay = day; + fYear = year; + fMonth = month; + } + + return valid; +} + + +int32 +BDate::_DaysInMonth(int32 year, int32 month) const +{ + if (month == 2 && IsLeapYear(year)) + return 29; + + const int32 daysInMonth[12] = + {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + + return daysInMonth[month -1]; +} + + +int32 +BDate::_DateToJulianDay(int32 _year, int32 month, int32 day) const +{ + int32 year = _year; + if (year < 0) year++; + + int32 a = (14 - month) / 12; + int32 y = year + 4800 - a; + int32 m = month + (12 * a) - 3; + + // http://en.wikipedia.org/wiki/Julian_day#Calculation + if (year > 1582 + || (year == 1582 && month > 10) + || (year == 1582 && month == 10 && day >= 15)) { + return day + (((153 * m) + 2) / 5) + (365 * y) + (y / 4) - + (y / 100) + (y / 400) - 32045; + } else if (year < 1582 + || (year == 1582 && month < 10) + || (year == 1582 && month == 10 && day <= 4)) { + return day + (((153 * m) + 2) / 5) + (365 * y) + (y / 4) - 32083; + } + + // http://en.wikipedia.org/wiki/Gregorian_calendar: + // The last day of the Julian calendar was Thursday October 4, 1582 + // and this was followed by the first day of the Gregorian calendar, + // Friday October 15, 1582 (the cycle of weekdays was not affected). + return -1; +} + + +// #pragma mark - BDateTime + + BDateTime::BDateTime(const BDate &date, const BTime &time) : fDate(date), fTime(time) From sbenedetto at mail.berlios.de Mon Sep 1 15:13:03 2008 From: sbenedetto at mail.berlios.de (sbenedetto at BerliOS) Date: Mon, 1 Sep 2008 15:13:03 +0200 Subject: [Haiku-commits] r27265 - haiku/trunk/src/system/kernel/posix Message-ID: <200809011313.m81DD3dw017374@sheep.berlios.de> Author: sbenedetto Date: 2008-09-01 15:13:03 +0200 (Mon, 01 Sep 2008) New Revision: 27265 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27265&view=rev Modified: haiku/trunk/src/system/kernel/posix/xsi_message_queue.cpp Log: * Start implementing _kern_msgctl() syscall Modified: haiku/trunk/src/system/kernel/posix/xsi_message_queue.cpp =================================================================== --- haiku/trunk/src/system/kernel/posix/xsi_message_queue.cpp 2008-09-01 13:11:29 UTC (rev 27264) +++ haiku/trunk/src/system/kernel/posix/xsi_message_queue.cpp 2008-09-01 13:13:03 UTC (rev 27265) @@ -78,6 +78,9 @@ typedef DoublyLinkedList MessageQueue; +// Arbitrary limit +#define MAX_BYTES_PER_QUEUE 2048 + class XsiMessageQueue { public: XsiMessageQueue(int flags) @@ -85,13 +88,28 @@ mutex_init(&fLock, "XsiMessageQueue private mutex"); SetIpcKey((key_t)-1); SetPermissions(flags); + // Initialize all fields to zero + memset((void *)&fMessageQueue, 0, sizeof(struct msqid_ds)); + fMessageQueue.msg_ctime = (time_t)real_time_clock(); + fMessageQueue.msg_qbytes = MAX_BYTES_PER_QUEUE; } ~XsiMessageQueue() { mutex_destroy(&fLock); + UnsetID(); + // TODO: free up all messages } + void DoIpcSet(struct msqid_ds *result) + { + fMessageQueue.msg_perm.uid = result->msg_perm.uid; + fMessageQueue.msg_perm.gid = result->msg_perm.gid; + fMessageQueue.msg_perm.mode = (fMessageQueue.msg_perm.mode & ~0x01ff) + | (result->msg_perm.mode & 0x01ff); + fMessageQueue.msg_ctime = (time_t)real_time_clock(); + } + bool HasPermission() const { if ((fMessageQueue.msg_perm.mode & S_IWOTH) != 0) @@ -110,11 +128,37 @@ return false; } + bool HasReadPermission() const + { + // TODO: fix this + return HasPermission(); + } + int ID() const { return fID; } + key_t IpcKey() const + { + return fMessageQueue.msg_perm.key; + } + + mutex &Lock() + { + return fLock; + } + + msglen_t MaxBytes() const + { + return fMessageQueue.msg_qbytes; + } + + struct msqid_ds &GetMessageQueue() + { + return fMessageQueue; + } + // Implemented after sMessageQueueHashTable is declared void SetID(); @@ -130,6 +174,9 @@ fMessageQueue.msg_perm.mode = (flags & 0x01ff); } + // Implemented after sMessageQueueHashTable is declared + void UnsetID(); + HashTableLink* Link() { return &fLink; @@ -261,7 +308,13 @@ fID = sNextAvailableID++; } +void +XsiMessageQueue::UnsetID() +{ + sNextAvailableID = fID; +} + // #pragma mark - Kernel exported API @@ -286,8 +339,101 @@ int _user_xsi_msgctl(int messageQueueID, int command, struct msqid_ds *buffer) { - // TODO - return B_ERROR; + TRACE(("xsi_msgctl: messageQueueID = %d, command = %d\n", messageQueueID, command)); + MutexLocker ipcHashLocker(sIpcLock); + MutexLocker messageQueueHashLocker(sXsiMessageQueueLock); + XsiMessageQueue *messageQueue = sMessageQueueHashTable.Lookup(messageQueueID); + if (messageQueue == NULL) { + TRACE_ERROR(("xsi_msgctl: message queue id %d not valid\n", messageQueueID)); + return EINVAL; + } + if (!IS_USER_ADDRESS(buffer)) { + TRACE_ERROR(("xsi_msgctl: buffer address is not valid\n")); + return B_BAD_ADDRESS; + } + + // Lock the message queue itself and release both the ipc hash table lock + // and the message queue hash table lock _only_ if the command it's not + // IPC_RMID, this prevents undesidered situation from happening while + // (hopefully) improving the concurrency. + MutexLocker messageQueueLocker; + if (command != IPC_RMID) { + messageQueueLocker.SetTo(&messageQueue->Lock(), false); + messageQueueHashLocker.Unlock(); + ipcHashLocker.Unlock(); + } + + switch (command) { + case IPC_STAT: { + if (!messageQueue->HasReadPermission()) { + TRACE_ERROR(("xsi_msgctl: calling process has not read " + "permission on message queue %d, key %d\n", messageQueueID, + (int)messageQueue->IpcKey())); + return EACCES; + } + struct msqid_ds msg = messageQueue->GetMessageQueue(); + if (user_memcpy(buffer, &msg, sizeof(struct msqid_ds)) < B_OK) { + TRACE_ERROR(("xsi_msgctl: user_memcpy failed\n")); + return B_BAD_ADDRESS; + } + break; + } + + case IPC_SET: { + if (!messageQueue->HasPermission()) { + TRACE_ERROR(("xsi_msgctl: calling process has not permission " + "on message queue %d, key %d\n", messageQueueID, + (int)messageQueue->IpcKey())); + return EPERM; + } + struct msqid_ds msg; + if (user_memcpy(&msg, buffer, sizeof(struct msqid_ds)) < B_OK) { + TRACE_ERROR(("xsi_msgctl: user_memcpy failed\n")); + return B_BAD_ADDRESS; + } + if (msg.msg_qbytes > messageQueue->MaxBytes() && getuid() != 0) { + TRACE_ERROR(("xsi_msgctl: user does not have permission to " + "increase the maximum number of bytes allowed on queue\n")); + return EPERM; + } + messageQueue->DoIpcSet(&msg); + break; + } + + case IPC_RMID: { + // If this was the command, we are still holding the message + // queue hash table lock along with the ipc one, but not the + // message queue lock itself. This prevents other process + // to try and acquire a destroyed mutex + if (!messageQueue->HasPermission()) { + TRACE_ERROR(("xsi_msgctl: calling process has not permission " + "on message queue %d, key %d\n", messageQueueID, + (int)messageQueue->IpcKey())); + return EPERM; + } + key_t key = messageQueue->IpcKey(); + Ipc *ipcKey = NULL; + if (key != -1) { + ipcKey = sIpcHashTable.Lookup(key); + sIpcHashTable.Remove(ipcKey); + } + sMessageQueueHashTable.Remove(messageQueue); + // Wake up of any threads waiting on this + // queue happens in destructor + if (key != -1) + delete ipcKey; + atomic_add(&sXsiMessageQueueCount, -1); + + delete messageQueue; + break; + } + + default: + TRACE_ERROR(("xsi_semctl: command %d not valid\n", command)); + return EINVAL; + } + + return B_OK; } From julun at mail.berlios.de Mon Sep 1 15:16:14 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Mon, 1 Sep 2008 15:16:14 +0200 Subject: [Haiku-commits] r27266 - haiku/trunk/src/kits/shared Message-ID: <200809011316.m81DGEtX017729@sheep.berlios.de> Author: julun Date: 2008-09-01 15:16:14 +0200 (Mon, 01 Sep 2008) New Revision: 27266 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27266&view=rev Modified: haiku/trunk/src/kits/shared/DateTime.cpp Log: * Month and Day should be used from the passed date Modified: haiku/trunk/src/kits/shared/DateTime.cpp =================================================================== --- haiku/trunk/src/kits/shared/DateTime.cpp 2008-09-01 13:13:03 UTC (rev 27265) +++ haiku/trunk/src/kits/shared/DateTime.cpp 2008-09-01 13:16:14 UTC (rev 27266) @@ -191,7 +191,7 @@ bool BDate::SetDate(const BDate& date) { - return _SetDate(date.fYear, fMonth, fDay); + return _SetDate(date.fYear, date.fMonth, date.fDay); } From alex at zappotek.com Mon Sep 1 16:41:40 2008 From: alex at zappotek.com (Alexandre Deckner) Date: Mon, 01 Sep 2008 16:41:40 +0200 Subject: [Haiku-commits] r27258 - haiku/trunk/src/apps/deskbar In-Reply-To: <1FBB57E6-3687-4DDB-96E2-B0BB09BB5DD7@gmail.com> References: <200808311840.m7VIeSgT022438@sheep.berlios.de> <48BAF0B9.7030800@zappotek.com> <48BBCCFA.8040603@zappotek.com> <1FBB57E6-3687-4DDB-96E2-B0BB09BB5DD7@gmail.com> Message-ID: <48BBFF24.3050901@zappotek.com> Michael Pfeiffer wrote: > Hope I didn't step on your shoes. I have added an extra smile in the > line with the word "ugly" on purpose :) Now that I am reading it a > second time, I have to apologize, I am sorry, I should not have > written it in the first place. > The rest of the mail was meant to be a constructive critique, though. > No no, don't worry! really :) I only considered the constructive part. I admit the ugly part affected me a bit, but i thought it didn't appear in my reply :) but hey, maybe it really is (ugly), i mean that's how it works with open source, your code is always ephemeral and will be rewritten someday by someone that has a better solution. And if i didn't like to write code i wouldn't be there anyway. In general and for further exchanges, you really don't need to handle me with kid gloves (just found that expr in the dictionnary). I'm really totally open to any advice given, even if it means i have to rewrite everything, you don't even need to put tons of smileys :), i won't take any offense, you'll just have to defend your case a bit off course! And to further clarify, when i say "please do it", it is only because i honestly believe it would be more efficient time wise (for both of us) because you seemed to have the solution already in mind. Best regards, Alex From jackburton at mail.berlios.de Mon Sep 1 16:43:28 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Mon, 1 Sep 2008 16:43:28 +0200 Subject: [Haiku-commits] r27267 - haiku/trunk/src/servers/app Message-ID: <200809011443.m81EhScB027172@sheep.berlios.de> Author: jackburton Date: 2008-09-01 16:43:25 +0200 (Mon, 01 Sep 2008) New Revision: 27267 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27267&view=rev Modified: haiku/trunk/src/servers/app/ServerPicture.cpp Log: Apply the same logic of r24682 to the drawing of BPictures inside BPictures. Fixes part of bug #1389 (drawing pictures at an offset). Thanks to Karsten for his observations! Modified: haiku/trunk/src/servers/app/ServerPicture.cpp =================================================================== --- haiku/trunk/src/servers/app/ServerPicture.cpp 2008-09-01 13:16:14 UTC (rev 27266) +++ haiku/trunk/src/servers/app/ServerPicture.cpp 2008-09-01 14:43:25 UTC (rev 27267) @@ -449,8 +449,10 @@ { ServerPicture *picture = view->Window()->ServerWindow()->App()->FindPicture(token); if (picture != NULL) { - view->CurrentState()->SetOrigin(where); + view->SetDrawingOrigin(where); + view->PushState(); picture->Play(view); + view->PopState(); } } From alex at zappotek.com Mon Sep 1 17:23:07 2008 From: alex at zappotek.com (Alexandre Deckner) Date: Mon, 01 Sep 2008 17:23:07 +0200 Subject: [Haiku-commits] r27258 - haiku/trunk/src/apps/deskbar In-Reply-To: <48BBFF24.3050901@zappotek.com> References: <200808311840.m7VIeSgT022438@sheep.berlios.de> <48BAF0B9.7030800@zappotek.com> <48BBCCFA.8040603@zappotek.com> <1FBB57E6-3687-4DDB-96E2-B0BB09BB5DD7@gmail.com> <48BBFF24.3050901@zappotek.com> Message-ID: <48BC08DB.7070304@zappotek.com> Alexandre Deckner wrote: > Michael Pfeiffer wrote: > >> Hope I didn't step on your shoes. I have added an extra smile in the >> line with the word "ugly" on purpose :) Now that I am reading it a >> second time, I have to apologize, I am sorry, I should not have >> written it in the first place. >> The rest of the mail was meant to be a constructive critique, though. >> >> > No no, don't worry! really :) I only considered the constructive part. I > admit the ugly part affected me a bit, but i thought it didn't appear in > my reply :) but hey, maybe it really is (ugly), i mean that's how it > works with open source, your code is always ephemeral and will be > rewritten someday by someone that has a better solution. And if i didn't > like to write code i wouldn't be there anyway. > > In general and for further exchanges, you really don't need to handle me > with kid gloves (just found that expr in the dictionnary). I'm really > totally open to any advice given, even if it means i have to rewrite > everything, you don't even need to put tons of smileys :), i won't take > any offense, you'll just have to defend your case a bit off course! > And to further clarify, when i say "please do it", it is only because i > honestly believe it would be more efficient time wise (for both of us) > because you seemed to have the solution already in mind. Oh, and i forgot to add, please mock me, joke on me! I'm coding for Haiku for the pleasure, and i also like this project because of the great people you find here. If we put too much pressure on us we'll never get anywhere, i don't know for you other devs, but i think i tend to under-commit because i'm to affraid of breaking what is, after all, a pre alpha code base. Of course i always test and proofread a lot (really a lot) for each of my (even minor) commit, but think i should really relax. Alpha will be out when it's done, let's just breathe. As a not really related note, another thing that tends to block me is the alpha fever that took the dev ml. It's like working in a 50m2 office with 200 people wandering around, i mean it is the main channel of communication for devs as a group, it is a working place, and a simple programming question can get hijacked quickly. As we approach alpha and there is still a ton of work to do, the list gets noisier and noisier. What we need for a good alpha is on the contrary a few months of calm, just like in a tennis match, the public gets silent when the players need focusing. A call to calm and reason and a reminder of the ml rules would do the job, but i'm no authority in there, i don't think it's my role. Maybe a joint declaration from the haiku team at large... dunno Now that was really off topic for a commit ml! Ban me ;-P Regards, Alex From michael.w.pfeiffer at gmail.com Mon Sep 1 17:55:44 2008 From: michael.w.pfeiffer at gmail.com (Michael Pfeiffer) Date: Mon, 1 Sep 2008 17:55:44 +0200 Subject: [Haiku-commits] r27262 - haiku/trunk/src/apps/aboutsystem In-Reply-To: <200809010904.m8194ARK022625@sheep.berlios.de> References: <200809010904.m8194ARK022625@sheep.berlios.de> Message-ID: Am 01.09.2008 um 11:04 schrieb stippi at BerliOS: > Author: stippi > Date: 2008-09-01 11:04:09 +0200 (Mon, 01 Sep 2008) > New Revision: 27262 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27262&view=rev > > Modified: > haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp > Log: > First attempt at a more balanced Credits section: > * Removed the outdated Team list in favor of a "Most influential > developers" > list with the top contributors of the past and the present in order > of > SVN commit numbers. It could be argued that Travis should be part > of this > list but he is already mentioned later with a special note. I used > this > wording to indicate that it could also mention no longer active, > but still > "most influential" developers. "Lead developers" or "Core > developers" would > not have this aspect. The positions of people could slightly change in "Most influential developers" if you take the changes in the CVS repository into account too: 3274 axeld 1386 bonefish 880 beveloper 691 shatty 615 rudolfc 607 korli 558 tylerdauwalder 555 darkwyrm 455 mwilber 390 jackburton 373 phoudoin 253 laplace 230 adioanca 194 wkornew 125 dreid 112 mmu_man 104 ejakowatz 101 mahlzeit 99 nwhitehorn 95 michaelphipps 93 sikosis 89 shadow303 76 danielre 63 haydentech 50 stippi 50 nielx 47 mflerackers 42 jrand 31 lillo 14 mccall 12 zooey 12 brunoga 11 jerl1 10 matzon 5 stmansfield 4 notion 4 gendusoa 2 assimil8or Note I have used a Perl script called cvs2cl.pl (http://www.red-bean.com/cvs2cl/ ) to count the number of commits, so they should be comparable to the svn numbers. To reproduce the result use the following line on the generated Changeog file grep -e "^[0-9]" ChangeLog | cut -c 19- | sort | uniq -c | sort -r - Michael From sbenedetto at mail.berlios.de Mon Sep 1 18:16:03 2008 From: sbenedetto at mail.berlios.de (sbenedetto at BerliOS) Date: Mon, 1 Sep 2008 18:16:03 +0200 Subject: [Haiku-commits] r27268 - haiku/trunk/src/system/kernel/posix Message-ID: <200809011616.m81GG3N6001985@sheep.berlios.de> Author: sbenedetto Date: 2008-09-01 18:16:03 +0200 (Mon, 01 Sep 2008) New Revision: 27268 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27268&view=rev Modified: haiku/trunk/src/system/kernel/posix/xsi_semaphore.cpp Log: * Fix a potential race condition when deleting a semaphore set: previously only the ipc hash table lock along with the semaphore set hash table lock were hold, thinking (wrongly) that the semaphore set lock itself was not needed. What could happen was that another process on semop could have gained the lock of the set itself, and then release the semaphore set hash table lock. This would make it think that the set was still valid, while it could have actually been deleted right after it release the semaphore set hash table lock. Same would have happened for any other processes waiting on the semaphore set mutex queue. By calling the lock on the mutex when deleting the set, it *should be* safe to assume that there is no one else waiting on its queue, since the list of waiters is handled in a FIFO way. As far as I can see from the mutex_destroy code, it looks safe to hold the lock when calling this function. Please confirm. Modified: haiku/trunk/src/system/kernel/posix/xsi_semaphore.cpp =================================================================== --- haiku/trunk/src/system/kernel/posix/xsi_semaphore.cpp 2008-09-01 14:43:25 UTC (rev 27267) +++ haiku/trunk/src/system/kernel/posix/xsi_semaphore.cpp 2008-09-01 16:16:03 UTC (rev 27268) @@ -846,7 +846,11 @@ setLocker.SetTo(&semaphoreSet->Lock(), false); setHashLocker.Unlock(); ipcHashLocker.Unlock(); - } + } else + // We are about to delete the set along with its mutex, so + // we can't use the MutexLocker class, as the mutex itself + // won't exist on function exit + mutex_lock(&semaphoreSet->Lock()); int result = 0; XsiSemaphore *semaphore = semaphoreSet->Semaphore(semaphoreNumber); @@ -1005,8 +1009,9 @@ case IPC_RMID: { // If this was the command, we are still holding // the semaphore set hash table lock along with the - // ipc hash table lock, but not the semaphore set - // itself lock as it would be useless in this case + // ipc hash table lock and the semaphore set lock + // itself, this way we are sure there is not + // one waiting in the queue of the mutex. if (!semaphoreSet->HasPermission()) { TRACE_ERROR(("xsi_semctl: calling process has not " "permission on semaphore %d, key %d\n", From bga at bug-br.org.br Mon Sep 1 18:29:02 2008 From: bga at bug-br.org.br (Bruno Albuquerque) Date: Mon, 01 Sep 2008 13:29:02 -0300 Subject: [Haiku-commits] r27262 - haiku/trunk/src/apps/aboutsystem In-Reply-To: References: <200809010904.m8194ARK022625@sheep.berlios.de> Message-ID: <48BC184E.9080304@bug-br.org.br> Michael Pfeiffer wrote: > The positions of people could slightly change in "Most influential > developers" if you take the changes in the CVS repository into account > too: It can change in other ways too. MDR was developed in part by me and Nathan Whitehorn (with contributions from Axel, Stephan, AGMS and others) but I did not commit it to the Haiku tree, so that this does not count as me contributing anything neither by your way or Stephan's way. Also commits of huge components outside the Haiku tree have been made by some developers and will be counted in both cases but one can argue if this is valid. My point is,there is probably no single way to do it that would take into account all possible variables so it is better if we simply stick to whatever we have now (stippi's version is fair enough in my opinion). -Bruno From superstippi at gmx.de Mon Sep 1 18:41:38 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Mon, 01 Sep 2008 18:41:38 +0200 Subject: [Haiku-commits] r27262 - haiku/trunk/src/apps/aboutsystem In-Reply-To: References: <200809010904.m8194ARK022625@sheep.berlios.de> Message-ID: <20080901184138.26098.5@stippis2.1220273270.fake> Michael Pfeiffer wrote: > > Am 01.09.2008 um 11:04 schrieb stippi at BerliOS: > > > Author: stippi > > Date: 2008-09-01 11:04:09 +0200 (Mon, 01 Sep 2008) New Revision: 27262 > > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27262&view=rev > > > > Modified: > > haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp > > Log: > > First attempt at a more balanced Credits section: > > * Removed the outdated Team list in favor of a "Most influential > > developers" > > list with the top contributors of the past and the present in order > > of > > SVN commit numbers. It could be argued that Travis should be part > > of this > > list but he is already mentioned later with a special note. I used > > this > > wording to indicate that it could also mention no longer active, > > but still > > "most influential" developers. "Lead developers" or "Core > > developers" would > > not have this aspect. > > The positions of people could slightly change in "Most influential > developers" if you take the changes in the CVS repository into account > too: > > 3274 axeld > 1386 bonefish > 880 beveloper > 691 shatty > 615 rudolfc > 607 korli > 558 tylerdauwalder > 555 darkwyrm > 455 mwilber > 390 jackburton > 373 phoudoin > 253 laplace > 230 adioanca > 194 wkornew > 125 dreid > 112 mmu_man > 104 ejakowatz > 101 mahlzeit > 99 nwhitehorn > 95 michaelphipps > 93 sikosis > 89 shadow303 > 76 danielre > 63 haydentech > 50 stippi > 50 nielx > 47 mflerackers > 42 jrand > 31 lillo > 14 mccall > 12 zooey > 12 brunoga > 11 jerl1 > 10 matzon > 5 stmansfield > 4 notion > 4 gendusoa > 2 assimil8or > > Note I have used a Perl script called cvs2cl.pl > (http://www.red-bean.com/cvs2cl/ ) to count the number of commits, so > they should be comparable to the svn numbers. > > To reproduce the result use the following line on the generated Changeog > file > grep -e "^[0-9]" ChangeLog | cut -c 19- | sort | uniq -c | sort -r Nice. Thanks a lot! How did you produce the Changelog file? I am asking to know what revisions it includes. Do you know if the SVN revision number actually includes the previous CVS commits? I thought the repository was imported with some history, not started from scratch (if you go to http://dev.haiku-os.org/changeset/7, you will see it has the authors starting from 7 years ago). If so, couldn't the script be run on the SVN repo? Best regards, -Stephan From michael.w.pfeiffer at gmail.com Mon Sep 1 18:41:14 2008 From: michael.w.pfeiffer at gmail.com (Michael Pfeiffer) Date: Mon, 1 Sep 2008 18:41:14 +0200 Subject: [Haiku-commits] r27262 - haiku/trunk/src/apps/aboutsystem In-Reply-To: <48BC184E.9080304@bug-br.org.br> References: <200809010904.m8194ARK022625@sheep.berlios.de> <48BC184E.9080304@bug-br.org.br> Message-ID: Am 01.09.2008 um 18:29 schrieb Bruno Albuquerque: > Michael Pfeiffer wrote: > >> The positions of people could slightly change in "Most influential >> developers" if you take the changes in the CVS repository into >> account >> too: > > It can change in other ways too. MDR was developed in part by me and > Nathan Whitehorn (with contributions from Axel, Stephan, AGMS and > others) but I did not commit it to the Haiku tree, so that this does > not > count as me contributing anything neither by your way or Stephan's > way. > > Also commits of huge components outside the Haiku tree have been > made by > some developers and will be counted in both cases but one can argue > if > this is valid. > > My point is,there is probably no single way to do it that would take > into account all possible variables so it is better if we simply stick > to whatever we have now (stippi's version is fair enough in my > opinion). I agree with you that the measurement has flaws, but the consequence should not be to stick to what we have, but to at least try to improve it as best as we can. EOM from my part to this thread, Michael From alex at zappotek.com Mon Sep 1 19:14:06 2008 From: alex at zappotek.com (Alexandre Deckner) Date: Mon, 01 Sep 2008 19:14:06 +0200 Subject: [Haiku-commits] r27262 - haiku/trunk/src/apps/aboutsystem In-Reply-To: References: <200809010904.m8194ARK022625@sheep.berlios.de> Message-ID: <48BC22DE.8030002@zappotek.com> Michael Pfeiffer wrote: > Am 01.09.2008 um 11:04 schrieb stippi at BerliOS: > > >> Author: stippi >> Date: 2008-09-01 11:04:09 +0200 (Mon, 01 Sep 2008) >> New Revision: 27262 >> ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27262&view=rev >> >> Modified: >> haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp >> Log: >> First attempt at a more balanced Credits section: >> * Removed the outdated Team list in favor of a "Most influential >> developers" >> list with the top contributors of the past and the present in order >> of >> SVN commit numbers. It could be argued that Travis should be part >> of this >> list but he is already mentioned later with a special note. I used >> this >> wording to indicate that it could also mention no longer active, >> but still >> "most influential" developers. "Lead developers" or "Core >> developers" would >> not have this aspect. >> > > The positions of people could slightly change in "Most influential > developers" if you take the changes in the CVS repository into account > too: > > Yep true, but we really shouldn't emphasize too much on the commit count though, we are not racing for the max number of commits, it is an interesting info but we all know it has nothing to do with quality or difficulty of the work done, that's why i liked the way it was randomised a bit, we're not in competition after all. We could put special kudo icons to make some people stand out, but that would be based on the recognition and "love", not on keystrokes. That would bring a little more humanity. Honestly, having my name here is cool and i was really pleased when it popped in, but i know that people that care already know what i've done and that's what is important to me in the end. A random user will probably not care at all anyway. Maybe we could just have two or three levels like "old active devs" and "recent active devs" and just randomize a bit in each level. If we want to rethink a little bit more the list, there are tons of ways to represent it and here is my humble proposition. I think that the important info is to represent the current active team. When you're an outsider, you like to know who is in the office at the moment. I think if there's a meaningfull line to be drawn, it is between the occasional contributors and the current active team, off course a special mention to people that were in the team at some point could be put in an (pretty honorific imo) "historical section" as they deserve a particular recognition but are more a part of the foundation and history of the project. Something along those lines: Haiku Team (currently active team). |- active senior dev, rookie dev, webmasters, testers, doc, PR, forum support, you name it. Haiku founding fathers (old devs, admin team etc). special thanks, honorific mentions etc... Haiku occasional contributions (low activity). Don't know if it makes sense, anyway thanks stippi for working on it, your version is pretty good. Best regards, Alex ps: took me an hour to write, sorry if i ever ignored some previous replies From michael.w.pfeiffer at gmail.com Mon Sep 1 19:17:20 2008 From: michael.w.pfeiffer at gmail.com (Michael Pfeiffer) Date: Mon, 1 Sep 2008 19:17:20 +0200 Subject: [Haiku-commits] r27262 - haiku/trunk/src/apps/aboutsystem In-Reply-To: <20080901184138.26098.5@stippis2.1220273270.fake> References: <200809010904.m8194ARK022625@sheep.berlios.de> <20080901184138.26098.5@stippis2.1220273270.fake> Message-ID: Am 01.09.2008 um 18:41 schrieb Stephan Assmus: > Nice. Thanks a lot! How did you produce the Changelog file? Sorry now I have to break my EOM for this thread :) I checked out the module "current" from open-beos CVS repo from Sourceforge and then used the perl script I mentioned in the other mail. > I am asking to > know what revisions it includes. Do you know if the SVN revision > number > actually includes the previous CVS commits? I thought the repository > was > imported with some history, not started from scratch (if you go to > http://dev.haiku-os.org/changeset/7, you will see it has the authors > starting from 7 years ago). Now I am completely confused. The first date in the CVS repository is 9 Jul 2002. Which is a long commit from ejakowatz with the entire source tree (Message: "It is accomplished ..."). At first I thought my memory must fool me, but know I think there was a repo before this CVS repo. And yes the changes in "current" are also visible in the SVN history. So you must ignore my numbers as these should already be part of the SVN numbers. So the question remains, what has happened to the other repo? Anyway, I will now stop with this. > If so, couldn't the script be run on the SVN > repo? I don't think so, I think it needs a CVS working directory. Anyway, that's void now. - Michael From laplace at mail.berlios.de Mon Sep 1 19:50:08 2008 From: laplace at mail.berlios.de (laplace at mail.berlios.de) Date: Mon, 1 Sep 2008 19:50:08 +0200 Subject: [Haiku-commits] r27269 - haiku/trunk/src/apps/deskbar Message-ID: <200809011750.m81Ho8r0000586@sheep.berlios.de> Author: laplace Date: 2008-09-01 19:50:06 +0200 (Mon, 01 Sep 2008) New Revision: 27269 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27269&view=rev Modified: haiku/trunk/src/apps/deskbar/TimeView.cpp haiku/trunk/src/apps/deskbar/TimeView.h Log: Added menu item "Show Calendar ..." to time pop up menu. Modified: haiku/trunk/src/apps/deskbar/TimeView.cpp =================================================================== --- haiku/trunk/src/apps/deskbar/TimeView.cpp 2008-09-01 16:16:03 UTC (rev 27268) +++ haiku/trunk/src/apps/deskbar/TimeView.cpp 2008-09-01 17:50:06 UTC (rev 27269) @@ -66,7 +66,8 @@ kMsgShowClock, kMsgChangeClock, kMsgHide, - kMsgLongClick + kMsgLongClick, + kMsgShowCalendar }; @@ -238,49 +239,63 @@ case kMsgLongClick: { BPoint where; - message->FindPoint("where", &where); - - //TODO: do nothing if the calendar is already shown + message->FindPoint("where", &where); + ShowCalendar(where); + break; + } + + case kMsgShowCalendar: + { + BRect bounds(Bounds()); + BPoint center(bounds.LeftTop()); + center += BPoint(bounds.Width() / 2, bounds.Height() / 2); + ShowCalendar(center); + break; + } + + default: + BView::MessageReceived(message); + } +} + +void +TTimeView::ShowCalendar(BPoint where) +{ + //TODO: do nothing if the calendar is already shown + #ifdef _SHOW_CALENDAR_MENU_ITEM - BPopUpMenu *menu = new BPopUpMenu("", false, false); - menu->SetFont(be_plain_font); + BPopUpMenu *menu = new BPopUpMenu("", false, false); + menu->SetFont(be_plain_font); - menu->AddItem(new CalendarMenuItem()); - menu->ResizeToPreferred(); - - BPoint point = where; - BScreen screen; - where.y = Bounds().bottom + 4; + menu->AddItem(new CalendarMenuItem()); + menu->ResizeToPreferred(); + + BPoint point = where; + BScreen screen; + where.y = Bounds().bottom + 4; - // make sure the menu is visible and doesn't hide the date - ConvertToScreen(&where); - if (where.y + menu->Bounds().Height() > screen.Frame().bottom) - where.y -= menu->Bounds().Height() + 2 * Bounds().Height(); + // make sure the menu is visible and doesn't hide the date + ConvertToScreen(&where); + if (where.y + menu->Bounds().Height() > screen.Frame().bottom) + where.y -= menu->Bounds().Height() + 2 * Bounds().Height(); - ConvertToScreen(&point); - menu->Go(where, true, true, BRect(point.x - 4, point.y - 4, - point.x + 4, point.y + 4), true); - + ConvertToScreen(&point); + menu->Go(where, true, true, BRect(point.x - 4, point.y - 4, + point.x + 4, point.y + 4), true); + #elif _SHOW_CALENDAR_MENU_WINDOW - where.y = Bounds().bottom + 4.0; - ConvertToScreen(&where); + where.y = Bounds().bottom + 4.0; + ConvertToScreen(&where); - if (where.y >= BScreen().Frame().bottom) - where.y -= (Bounds().Height() + 4.0); + if (where.y >= BScreen().Frame().bottom) + where.y -= (Bounds().Height() + 4.0); - CalendarMenuWindow* window = new CalendarMenuWindow(where, fEuroDate); - window->Show(); -#endif - - break; - } - - default: - BView::MessageReceived(message); - } + CalendarMenuWindow* window = new CalendarMenuWindow(where, fEuroDate); + window->Show(); +#endif } @@ -530,6 +545,11 @@ item = new BMenuItem("Hide Time", new BMessage('time')); menu->AddItem(item); +#if defined(_SHOW_CALENDAR_MENU_ITEM) || defined(_SHOW_CALENDAR_MENU_WINDOW) + item = new BMenuItem("Show Calendar" B_UTF8_ELLIPSIS, new BMessage(kMsgShowCalendar)); + menu->AddItem(item); +#endif + menu->SetTargetForItems(this); // Changed to accept screen coord system point; // not constrained to this view now Modified: haiku/trunk/src/apps/deskbar/TimeView.h =================================================================== --- haiku/trunk/src/apps/deskbar/TimeView.h 2008-09-01 16:16:03 UTC (rev 27268) +++ haiku/trunk/src/apps/deskbar/TimeView.h 2008-09-01 17:50:06 UTC (rev 27269) @@ -81,6 +81,7 @@ void AllowFullDate(bool); bool ShowingEuroDate() {return fEuroDate; } void ShowEuroDate(bool); + void ShowCalendar(BPoint where); bool Orientation() const; void SetOrientation(bool o); From korli at mail.berlios.de Mon Sep 1 20:37:13 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Mon, 1 Sep 2008 20:37:13 +0200 Subject: [Haiku-commits] r27270 - haiku/trunk/headers/os/interface Message-ID: <200809011837.m81IbDr6004397@sheep.berlios.de> Author: korli Date: 2008-09-01 20:37:13 +0200 (Mon, 01 Sep 2008) New Revision: 27270 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27270&view=rev Modified: haiku/trunk/headers/os/interface/InterfaceDefs.h Log: space cleanup Modified: haiku/trunk/headers/os/interface/InterfaceDefs.h =================================================================== --- haiku/trunk/headers/os/interface/InterfaceDefs.h 2008-09-01 17:50:06 UTC (rev 27269) +++ haiku/trunk/headers/os/interface/InterfaceDefs.h 2008-09-01 18:37:13 UTC (rev 27270) @@ -197,8 +197,8 @@ enum alignment { B_ALIGN_LEFT, - B_ALIGN_RIGHT, - B_ALIGN_CENTER, + B_ALIGN_RIGHT, + B_ALIGN_CENTER, B_ALIGN_HORIZONTAL_CENTER = B_ALIGN_CENTER, From anevilyak at gmail.com Mon Sep 1 20:37:13 2008 From: anevilyak at gmail.com (Rene Gollent) Date: Mon, 1 Sep 2008 13:37:13 -0500 Subject: [Haiku-commits] r27264 - in haiku/trunk: headers/private/shared src/kits/shared In-Reply-To: <200809011311.m81DBUXk017275@sheep.berlios.de> References: <200809011311.m81DBUXk017275@sheep.berlios.de> Message-ID: On Mon, Sep 1, 2008 at 8:11 AM, julun at BerliOS wrote: > + // http://en.wikipedia.org/wiki/Gregorian_calendar: > + // The last day of the Julian calendar was Thursday October 4, 1582 > + // and this was followed by the first day of the Gregorian calendar, > + // Friday October 15, 1582 (the cycle of weekdays was not affected). Just curiosity, was that supposed to be "Friday, October 5", or am I missing something? :) Regards, Rene From host.haiku at gmx.de Mon Sep 1 20:50:06 2008 From: host.haiku at gmx.de (julun) Date: Mon, 01 Sep 2008 20:50:06 +0200 Subject: [Haiku-commits] r27264 - in haiku/trunk: headers/private/shared src/kits/shared In-Reply-To: References: <200809011311.m81DBUXk017275@sheep.berlios.de> Message-ID: <48BC395E.1020007@gmx.de> Hi Rene, Rene Gollent schrieb: > On Mon, Sep 1, 2008 at 8:11 AM, julun at BerliOS wrote: > >> + // http://en.wikipedia.org/wiki/Gregorian_calendar: >> + // The last day of the Julian calendar was Thursday October 4, 1582 >> + // and this was followed by the first day of the Gregorian calendar, >> + // Friday October 15, 1582 (the cycle of weekdays was not affected). > > Just curiosity, was that supposed to be "Friday, October 5", or am I > missing something? :) no that's totally correct. They skipped some 'days', so when people where going to bed on 4 of October, the woke up the next day on 15 of October. Funny :) If someone is interested: http://en.wikipedia.org/wiki/Julian_day http://en.wikipedia.org/wiki/Julian_calendar http://en.wikipedia.org/wiki/Gregorian_calendar http://www.tondering.dk/claus/cal/node1.html While the last one is the most interesting. Regards, Karsten From anevilyak at gmail.com Mon Sep 1 20:51:47 2008 From: anevilyak at gmail.com (Rene Gollent) Date: Mon, 1 Sep 2008 13:51:47 -0500 Subject: [Haiku-commits] r27264 - in haiku/trunk: headers/private/shared src/kits/shared In-Reply-To: <48BC395E.1020007@gmx.de> References: <200809011311.m81DBUXk017275@sheep.berlios.de> <48BC395E.1020007@gmx.de> Message-ID: On Mon, Sep 1, 2008 at 1:50 PM, julun wrote: > no that's totally correct. They skipped some 'days', so when people > where going to bed on 4 of October, the woke up the next day on 15 of > October. Funny :) In that case, what happens if you ask to construct a date object in the range of that gap? Regards, Rene From host.haiku at gmx.de Mon Sep 1 21:16:10 2008 From: host.haiku at gmx.de (julun) Date: Mon, 01 Sep 2008 21:16:10 +0200 Subject: [Haiku-commits] r27264 - in haiku/trunk: headers/private/shared src/kits/shared In-Reply-To: References: <200809011311.m81DBUXk017275@sheep.berlios.de> <48BC395E.1020007@gmx.de> Message-ID: <48BC3F7A.2090100@gmx.de> Hi, Rene Gollent schrieb: > On Mon, Sep 1, 2008 at 1:50 PM, julun wrote: >> no that's totally correct. They skipped some 'days', so when people >> where going to bed on 4 of October, the woke up the next day on 15 of >> October. Funny :) > > In that case, what happens if you ask to construct a date object in > the range of that gap? The date is invalid, of course. Using this class would always force you to check if your date is valid, same would count for February, 31, 2008. :) If this class makes it into the official API, it clearly needs to be stated in the documentation. If someone is willing to point me to 'How to write Haiku docs' I'm going to document it. Karsten From anevilyak at gmail.com Mon Sep 1 21:23:13 2008 From: anevilyak at gmail.com (Rene Gollent) Date: Mon, 1 Sep 2008 14:23:13 -0500 Subject: [Haiku-commits] r27264 - in haiku/trunk: headers/private/shared src/kits/shared In-Reply-To: <48BC3F7A.2090100@gmx.de> References: <200809011311.m81DBUXk017275@sheep.berlios.de> <48BC395E.1020007@gmx.de> <48BC3F7A.2090100@gmx.de> Message-ID: On Mon, Sep 1, 2008 at 2:16 PM, julun wrote: > If this class makes it into the official API, it clearly needs to be > stated in the documentation. If someone is willing to point me to 'How > to write Haiku docs' I'm going to document it. Sounds like a nice addition to the support kit to me :) Regards, Rene From anevilyak at mail.berlios.de Mon Sep 1 21:33:50 2008 From: anevilyak at mail.berlios.de (anevilyak at BerliOS) Date: Mon, 1 Sep 2008 21:33:50 +0200 Subject: [Haiku-commits] r27271 - haiku/trunk/src/kits/interface Message-ID: <200809011933.m81JXoSm008925@sheep.berlios.de> Author: anevilyak Date: 2008-09-01 21:33:50 +0200 (Mon, 01 Sep 2008) New Revision: 27271 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27271&view=rev Modified: haiku/trunk/src/kits/interface/MenuBar.cpp Log: I hate to add another special case, but with the way the BMenu* classes are designed, I see little in the way of alternatives. If we're a BMenuField's menu bar, then we should invoke the menu item regardless of where in the bar we click. This problem was visible in ticket #1877, where basically you could click only on the portion with text, because that was the size of the menu item, where the rest of the contained menu bar was considered dead space. Thus we now check if we're an instance of BMenuField's special menubar class, and if so we unconditionally select the item instead of a hit test. Fixes the aforementioned bug. If someone has a better approach, I'm all ears. Modified: haiku/trunk/src/kits/interface/MenuBar.cpp =================================================================== --- haiku/trunk/src/kits/interface/MenuBar.cpp 2008-09-01 18:37:13 UTC (rev 27270) +++ haiku/trunk/src/kits/interface/MenuBar.cpp 2008-09-01 19:33:50 UTC (rev 27271) @@ -21,6 +21,8 @@ #include #include +#include "BMCPrivate.h" + using BPrivate::gDefaultTokens; @@ -470,7 +472,11 @@ if (Window() == NULL || !window->Lock()) break; - BMenuItem *menuItem = _HitTestItems(where, B_ORIGIN); + BMenuItem* menuItem = NULL; + if (dynamic_cast<_BMCMenuBar_*>(this)) + menuItem = ItemAt(0); + else + menuItem = _HitTestItems(where, B_ORIGIN); if (_OverSubmenu(fSelected, ConvertToScreen(where))) { // call _Track() from the selected sub-menu when the mouse cursor // is over its window From korli at mail.berlios.de Mon Sep 1 21:37:23 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Mon, 1 Sep 2008 21:37:23 +0200 Subject: [Haiku-commits] r27272 - in haiku/trunk: headers/posix src/system/libroot/posix/glibc/arch/m68k src/system/libroot/posix/glibc/arch/x86 Message-ID: <200809011937.m81JbNNG009241@sheep.berlios.de> Author: korli Date: 2008-09-01 21:37:23 +0200 (Mon, 01 Sep 2008) New Revision: 27272 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27272&view=rev Added: haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_fpclassifyl.c haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_fpclassifyl.c Modified: haiku/trunk/headers/posix/math.h haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/Jamfile haiku/trunk/src/system/libroot/posix/glibc/arch/x86/Jamfile Log: added fpclassifyl Modified: haiku/trunk/headers/posix/math.h =================================================================== --- haiku/trunk/headers/posix/math.h 2008-09-01 19:33:50 UTC (rev 27271) +++ haiku/trunk/headers/posix/math.h 2008-09-01 19:37:23 UTC (rev 27272) @@ -104,7 +104,7 @@ extern float log1pf(float x); extern float logbf(float x); extern float logf(float x); -extern long lroundf(float x); +extern long lroundf(float x); extern float modff(float x, float *y); extern float powf(float x, float y); extern float roundf(float x); @@ -129,9 +129,10 @@ extern double frexp(double x, int *_exponent); extern double gamma(double x); extern double ldexp(double x, int exponent); +extern double lgamma(double x); extern double log(double x); extern double log10(double x); -extern long lround(double x); +extern long lround(double x); extern double modf(double x, double *y); extern double pow(double x, double y); extern double round(double x); @@ -143,12 +144,10 @@ extern double trunc(double x); /* long double math functions */ +extern long double lgammal(long double x); extern long double roundl(long double x); extern long lroundl(long double x); -/* TODO: add and fix those! */ -extern /*long*/ double lgamma(/*long*/ double x); - /* some BSD non-ANSI or POSIX math functions */ extern double acosh(double x); extern double asinh(double x); Modified: haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/Jamfile =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/Jamfile 2008-09-01 19:33:50 UTC (rev 27271) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/Jamfile 2008-09-01 19:37:23 UTC (rev 27272) @@ -141,6 +141,7 @@ e_sqrt.c e_sqrtf.c # e_sqrtl.c # s_fdim.c s_fdimf.c # s_fdiml.S # s_fabs.S s_fabsf.S # s_fabsl.S + s_fpclassifyl.c # s_isnan.c s_isnanf.S s_rint.c s_rintf.c # s_rintl.c # t_sqrt.c Added: haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_fpclassifyl.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_fpclassifyl.c 2008-09-01 19:33:50 UTC (rev 27271) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_fpclassifyl.c 2008-09-01 19:37:23 UTC (rev 27272) @@ -0,0 +1,44 @@ +/* Return classification value corresponding to argument. m68k version. + Copyright (C) 1997, 2001, 2002 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper , 1997. + Fixed for m68k by Andreas Schwab . + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include + +#include "math_private.h" + + +int +__fpclassifyl (long double x) +{ + u_int32_t ex, hx, lx; + int retval = FP_NORMAL; + + GET_LDOUBLE_WORDS (ex, hx, lx, x); + ex &= 0x7fff; + if ((ex | hx | lx) == 0) + retval = FP_ZERO; + else if (ex == 0 && (hx & 0x80000000) == 0) + retval = FP_SUBNORMAL; + else if (ex == 0x7fff) + retval = ((hx & 0x7fffffff) | lx) != 0 ? FP_NAN : FP_INFINITE; + + return retval; +} +libm_hidden_def (__fpclassifyl) Modified: haiku/trunk/src/system/libroot/posix/glibc/arch/x86/Jamfile =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/x86/Jamfile 2008-09-01 19:33:50 UTC (rev 27271) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/x86/Jamfile 2008-09-01 19:37:23 UTC (rev 27272) @@ -144,6 +144,7 @@ s_fabs.S s_fabsf.S s_fabsl.S s_finite.S s_finitef.S s_finitel.S s_floor.S s_floorf.S s_floorl.S + s_fpclassifyl.c s_frexp.S s_frexpf.S s_frexpl.S s_ilogb.S s_ilogbf.S s_isinfl.c Added: haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_fpclassifyl.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_fpclassifyl.c 2008-09-01 19:33:50 UTC (rev 27271) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_fpclassifyl.c 2008-09-01 19:37:23 UTC (rev 27272) @@ -0,0 +1,43 @@ +/* Return classification value corresponding to argument. + Copyright (C) 1997, 2000, 2002 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper , 1997. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include + +#include "math_private.h" + + +int +__fpclassifyl (long double x) +{ + u_int32_t ex, hx, lx; + int retval = FP_NORMAL; + + GET_LDOUBLE_WORDS (ex, hx, lx, x); + ex &= 0x7fff; + if ((ex | lx | hx) == 0) + retval = FP_ZERO; + else if (ex == 0 && (hx & 0x80000000) == 0) + retval = FP_SUBNORMAL; + else if (ex == 0x7fff) + retval = ((hx & 0x7fffffff) | lx) != 0 ? FP_NAN : FP_INFINITE; + + return retval; +} +libm_hidden_def (__fpclassifyl) From marcusoverhagen at mail.berlios.de Mon Sep 1 21:44:28 2008 From: marcusoverhagen at mail.berlios.de (marcusoverhagen at BerliOS) Date: Mon, 1 Sep 2008 21:44:28 +0200 Subject: [Haiku-commits] r27273 - haiku/trunk/build/config_headers Message-ID: <200809011944.m81JiS6Q010323@sheep.berlios.de> Author: marcusoverhagen Date: 2008-09-01 21:44:27 +0200 (Mon, 01 Sep 2008) New Revision: 27273 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27273&view=rev Modified: haiku/trunk/build/config_headers/tracing_config.h Log: Preparing support for ATA and ATAPI tracing Modified: haiku/trunk/build/config_headers/tracing_config.h =================================================================== --- haiku/trunk/build/config_headers/tracing_config.h 2008-09-01 19:37:23 UTC (rev 27272) +++ haiku/trunk/build/config_headers/tracing_config.h 2008-09-01 19:44:27 UTC (rev 27273) @@ -19,6 +19,8 @@ // macros specifying the tracing level for individual components (0 is disabled) #define AHCI_PORT_TRACING 0 +#define ATA_TRACING 0 +#define ATAPI_TRACING 0 #define BFS_TRACING 0 #define BLOCK_CACHE_BLOCK_TRACING 0 #define BLOCK_CACHE_TRANSACTION_TRACING 0 From korli at mail.berlios.de Mon Sep 1 21:54:56 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Mon, 1 Sep 2008 21:54:56 +0200 Subject: [Haiku-commits] r27274 - in haiku/trunk/src/system/libroot/posix/glibc/arch: generic x86 Message-ID: <200809011954.m81JsuTf011409@sheep.berlios.de> Author: korli Date: 2008-09-01 21:54:55 +0200 (Mon, 01 Sep 2008) New Revision: 27274 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27274&view=rev Added: haiku/trunk/src/system/libroot/posix/glibc/arch/generic/e_gammal_r.c haiku/trunk/src/system/libroot/posix/glibc/arch/generic/e_lgammal_r.c Modified: haiku/trunk/src/system/libroot/posix/glibc/arch/x86/Jamfile Log: added gammal_r and lgammal_r private functions Added: haiku/trunk/src/system/libroot/posix/glibc/arch/generic/e_gammal_r.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/generic/e_gammal_r.c 2008-09-01 19:44:27 UTC (rev 27273) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/generic/e_gammal_r.c 2008-09-01 19:54:55 UTC (rev 27274) @@ -0,0 +1,62 @@ +/* Implementation of gamma function according to ISO C. + Copyright (C) 1997, 1999, 2001, 2003, 2004 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper , 1997. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include + + +long double +__ieee754_gammal_r (long double x, int *signgamp) +{ + /* We don't have a real gamma implementation now. We'll use lgamma + and the exp function. But due to the required boundary + conditions we must check some values separately. */ + u_int32_t es, hx, lx; + + GET_LDOUBLE_WORDS (es, hx, lx, x); + + if (((es & 0x7fff) | hx | lx) == 0) + { + /* Return value for x == 0 is Inf with divide by zero exception. */ + *signgamp = 0; + return 1.0 / x; + } + if (es == 0xffffffff && ((hx & 0x7fffffff) | lx) == 0) + { + /* x == -Inf. According to ISO this is NaN. */ + *signgamp = 0; + return x - x; + } + if ((es & 0x7fff) == 0x7fff && ((hx & 0x7fffffff) | lx) != 0) + { + /* NaN, return it. */ + *signgamp = 0; + return x; + } + if ((es & 0x8000) != 0 && x < 0xffffffff && __rintl (x) == x) + { + /* Return value for integer x < 0 is NaN with invalid exception. */ + *signgamp = 0; + return (x - x) / (x - x); + } + + /* XXX FIXME. */ + return __ieee754_expl (__ieee754_lgammal_r (x, signgamp)); +} Added: haiku/trunk/src/system/libroot/posix/glibc/arch/generic/e_lgammal_r.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/generic/e_lgammal_r.c 2008-09-01 19:44:27 UTC (rev 27273) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/generic/e_lgammal_r.c 2008-09-01 19:54:55 UTC (rev 27274) @@ -0,0 +1,446 @@ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* Long double expansions are + Copyright (C) 2001 Stephen L. Moshier + and are incorporated herein by permission of the author. The author + reserves the right to distribute this material elsewhere under different + copying permissions. These modifications are distributed here under + the following terms: + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* __ieee754_lgammal_r(x, signgamp) + * Reentrant version of the logarithm of the Gamma function + * with user provide pointer for the sign of Gamma(x). + * + * Method: + * 1. Argument Reduction for 0 < x <= 8 + * Since gamma(1+s)=s*gamma(s), for x in [0,8], we may + * reduce x to a number in [1.5,2.5] by + * lgamma(1+s) = log(s) + lgamma(s) + * for example, + * lgamma(7.3) = log(6.3) + lgamma(6.3) + * = log(6.3*5.3) + lgamma(5.3) + * = log(6.3*5.3*4.3*3.3*2.3) + lgamma(2.3) + * 2. Polynomial approximation of lgamma around its + * minimun ymin=1.461632144968362245 to maintain monotonicity. + * On [ymin-0.23, ymin+0.27] (i.e., [1.23164,1.73163]), use + * Let z = x-ymin; + * lgamma(x) = -1.214862905358496078218 + z^2*poly(z) + * 2. Rational approximation in the primary interval [2,3] + * We use the following approximation: + * s = x-2.0; + * lgamma(x) = 0.5*s + s*P(s)/Q(s) + * Our algorithms are based on the following observation + * + * zeta(2)-1 2 zeta(3)-1 3 + * lgamma(2+s) = s*(1-Euler) + --------- * s - --------- * s + ... + * 2 3 + * + * where Euler = 0.5771... is the Euler constant, which is very + * close to 0.5. + * + * 3. For x>=8, we have + * lgamma(x)~(x-0.5)log(x)-x+0.5*log(2pi)+1/(12x)-1/(360x**3)+.... + * (better formula: + * lgamma(x)~(x-0.5)*(log(x)-1)-.5*(log(2pi)-1) + ...) + * Let z = 1/x, then we approximation + * f(z) = lgamma(x) - (x-0.5)(log(x)-1) + * by + * 3 5 11 + * w = w0 + w1*z + w2*z + w3*z + ... + w6*z + * + * 4. For negative x, since (G is gamma function) + * -x*G(-x)*G(x) = pi/sin(pi*x), + * we have + * G(x) = pi/(sin(pi*x)*(-x)*G(-x)) + * since G(-x) is positive, sign(G(x)) = sign(sin(pi*x)) for x<0 + * Hence, for x<0, signgam = sign(sin(pi*x)) and + * lgamma(x) = log(|Gamma(x)|) + * = log(pi/(|x*sin(pi*x)|)) - lgamma(-x); + * Note: one should avoid compute pi*(-x) directly in the + * computation of sin(pi*(-x)). + * + * 5. Special Cases + * lgamma(2+s) ~ s*(1-Euler) for tiny s + * lgamma(1)=lgamma(2)=0 + * lgamma(x) ~ -log(x) for tiny x + * lgamma(0) = lgamma(inf) = inf + * lgamma(-integer) = +-inf + * + */ + +#include "math.h" +#include "math_private.h" + +#ifdef __STDC__ +static const long double +#else +static long double +#endif + half = 0.5L, + one = 1.0L, + pi = 3.14159265358979323846264L, + two63 = 9.223372036854775808e18L, + + /* lgam(1+x) = 0.5 x + x a(x)/b(x) + -0.268402099609375 <= x <= 0 + peak relative error 6.6e-22 */ + a0 = -6.343246574721079391729402781192128239938E2L, + a1 = 1.856560238672465796768677717168371401378E3L, + a2 = 2.404733102163746263689288466865843408429E3L, + a3 = 8.804188795790383497379532868917517596322E2L, + a4 = 1.135361354097447729740103745999661157426E2L, + a5 = 3.766956539107615557608581581190400021285E0L, + + b0 = 8.214973713960928795704317259806842490498E3L, + b1 = 1.026343508841367384879065363925870888012E4L, + b2 = 4.553337477045763320522762343132210919277E3L, + b3 = 8.506975785032585797446253359230031874803E2L, + b4 = 6.042447899703295436820744186992189445813E1L, + /* b5 = 1.000000000000000000000000000000000000000E0 */ + + + tc = 1.4616321449683623412626595423257213284682E0L, + tf = -1.2148629053584961146050602565082954242826E-1,/* double precision */ +/* tt = (tail of tf), i.e. tf + tt has extended precision. */ + tt = 3.3649914684731379602768989080467587736363E-18L, + /* lgam ( 1.4616321449683623412626595423257213284682E0 ) = +-1.2148629053584960809551455717769158215135617312999903886372437313313530E-1 */ + + /* lgam (x + tc) = tf + tt + x g(x)/h(x) + - 0.230003726999612341262659542325721328468 <= x + <= 0.2699962730003876587373404576742786715318 + peak relative error 2.1e-21 */ + g0 = 3.645529916721223331888305293534095553827E-18L, + g1 = 5.126654642791082497002594216163574795690E3L, + g2 = 8.828603575854624811911631336122070070327E3L, + g3 = 5.464186426932117031234820886525701595203E3L, + g4 = 1.455427403530884193180776558102868592293E3L, + g5 = 1.541735456969245924860307497029155838446E2L, + g6 = 4.335498275274822298341872707453445815118E0L, + + h0 = 1.059584930106085509696730443974495979641E4L, + h1 = 2.147921653490043010629481226937850618860E4L, + h2 = 1.643014770044524804175197151958100656728E4L, + h3 = 5.869021995186925517228323497501767586078E3L, + h4 = 9.764244777714344488787381271643502742293E2L, + h5 = 6.442485441570592541741092969581997002349E1L, + /* h6 = 1.000000000000000000000000000000000000000E0 */ + + + /* lgam (x+1) = -0.5 x + x u(x)/v(x) + -0.100006103515625 <= x <= 0.231639862060546875 + peak relative error 1.3e-21 */ + u0 = -8.886217500092090678492242071879342025627E1L, + u1 = 6.840109978129177639438792958320783599310E2L, + u2 = 2.042626104514127267855588786511809932433E3L, + u3 = 1.911723903442667422201651063009856064275E3L, + u4 = 7.447065275665887457628865263491667767695E2L, + u5 = 1.132256494121790736268471016493103952637E2L, + u6 = 4.484398885516614191003094714505960972894E0L, + + v0 = 1.150830924194461522996462401210374632929E3L, + v1 = 3.399692260848747447377972081399737098610E3L, + v2 = 3.786631705644460255229513563657226008015E3L, + v3 = 1.966450123004478374557778781564114347876E3L, + v4 = 4.741359068914069299837355438370682773122E2L, + v5 = 4.508989649747184050907206782117647852364E1L, + /* v6 = 1.000000000000000000000000000000000000000E0 */ + + + /* lgam (x+2) = .5 x + x s(x)/r(x) + 0 <= x <= 1 + peak relative error 7.2e-22 */ + s0 = 1.454726263410661942989109455292824853344E6L, + s1 = -3.901428390086348447890408306153378922752E6L, + s2 = -6.573568698209374121847873064292963089438E6L, + s3 = -3.319055881485044417245964508099095984643E6L, + s4 = -7.094891568758439227560184618114707107977E5L, + s5 = -6.263426646464505837422314539808112478303E4L, + s6 = -1.684926520999477529949915657519454051529E3L, + + r0 = -1.883978160734303518163008696712983134698E7L, + r1 = -2.815206082812062064902202753264922306830E7L, + r2 = -1.600245495251915899081846093343626358398E7L, + r3 = -4.310526301881305003489257052083370058799E6L, + r4 = -5.563807682263923279438235987186184968542E5L, + r5 = -3.027734654434169996032905158145259713083E4L, + r6 = -4.501995652861105629217250715790764371267E2L, + /* r6 = 1.000000000000000000000000000000000000000E0 */ + + +/* lgam(x) = ( x - 0.5 ) * log(x) - x + LS2PI + 1/x w(1/x^2) + x >= 8 + Peak relative error 1.51e-21 + w0 = LS2PI - 0.5 */ + w0 = 4.189385332046727417803e-1L, + w1 = 8.333333333333331447505E-2L, + w2 = -2.777777777750349603440E-3L, + w3 = 7.936507795855070755671E-4L, + w4 = -5.952345851765688514613E-4L, + w5 = 8.412723297322498080632E-4L, + w6 = -1.880801938119376907179E-3L, + w7 = 4.885026142432270781165E-3L; + +#ifdef __STDC__ +static const long double zero = 0.0L; +#else +static long double zero = 0.0L; +#endif + +#ifdef __STDC__ +static long double +sin_pi (long double x) +#else +static long double +sin_pi (x) + long double x; +#endif +{ + long double y, z; + int n, ix; + u_int32_t se, i0, i1; + + GET_LDOUBLE_WORDS (se, i0, i1, x); + ix = se & 0x7fff; + ix = (ix << 16) | (i0 >> 16); + if (ix < 0x3ffd8000) /* 0.25 */ + return __sinl (pi * x); + y = -x; /* x is assume negative */ + + /* + * argument reduction, make sure inexact flag not raised if input + * is an integer + */ + z = __floorl (y); + if (z != y) + { /* inexact anyway */ + y *= 0.5; + y = 2.0*(y - __floorl(y)); /* y = |x| mod 2.0 */ + n = (int) (y*4.0); + } + else + { + if (ix >= 0x403f8000) /* 2^64 */ + { + y = zero; n = 0; /* y must be even */ + } + else + { + if (ix < 0x403e8000) /* 2^63 */ + z = y + two63; /* exact */ + GET_LDOUBLE_WORDS (se, i0, i1, z); + n = i1 & 1; + y = n; + n <<= 2; + } + } + + switch (n) + { + case 0: + y = __sinl (pi * y); + break; + case 1: + case 2: + y = __cosl (pi * (half - y)); + break; + case 3: + case 4: + y = __sinl (pi * (one - y)); + break; + case 5: + case 6: + y = -__cosl (pi * (y - 1.5)); + break; + default: + y = __sinl (pi * (y - 2.0)); + break; + } + return -y; +} + + +#ifdef __STDC__ +long double +__ieee754_lgammal_r (long double x, int *signgamp) +#else +long double +__ieee754_lgammal_r (x, signgamp) + long double x; + int *signgamp; +#endif +{ + long double t, y, z, nadj, p, p1, p2, q, r, w; + int i, ix; + u_int32_t se, i0, i1; + + *signgamp = 1; + GET_LDOUBLE_WORDS (se, i0, i1, x); + ix = se & 0x7fff; + + if ((ix | i0 | i1) == 0) + return one / fabsl (x); + + ix = (ix << 16) | (i0 >> 16); + + /* purge off +-inf, NaN, +-0, and negative arguments */ + if (ix >= 0x7fff0000) + return x * x; + + if (ix < 0x3fc08000) /* 2^-63 */ + { /* |x|<2**-63, return -log(|x|) */ + if (se & 0x8000) + { + *signgamp = -1; + return -__ieee754_logl (-x); + } + else + return -__ieee754_logl (x); + } + if (se & 0x8000) + { + t = sin_pi (x); + if (t == zero) + return one / fabsl (t); /* -integer */ + nadj = __ieee754_logl (pi / fabsl (t * x)); + if (t < zero) + *signgamp = -1; + x = -x; + } + + /* purge off 1 and 2 */ + if ((((ix - 0x3fff8000) | i0 | i1) == 0) + || (((ix - 0x40008000) | i0 | i1) == 0)) + r = 0; + else if (ix < 0x40008000) /* 2.0 */ + { + /* x < 2.0 */ + if (ix <= 0x3ffee666) /* 8.99993896484375e-1 */ + { + /* lgamma(x) = lgamma(x+1) - log(x) */ + r = -__ieee754_logl (x); + if (ix >= 0x3ffebb4a) /* 7.31597900390625e-1 */ + { + y = x - one; + i = 0; + } + else if (ix >= 0x3ffced33)/* 2.31639862060546875e-1 */ + { + y = x - (tc - one); + i = 1; + } + else + { + /* x < 0.23 */ + y = x; + i = 2; + } + } + else + { + r = zero; + if (ix >= 0x3fffdda6) /* 1.73162841796875 */ + { + /* [1.7316,2] */ + y = x - 2.0; + i = 0; + } + else if (ix >= 0x3fff9da6)/* 1.23162841796875 */ + { + /* [1.23,1.73] */ + y = x - tc; + i = 1; + } + else + { + /* [0.9, 1.23] */ + y = x - one; + i = 2; + } + } + switch (i) + { + case 0: + p1 = a0 + y * (a1 + y * (a2 + y * (a3 + y * (a4 + y * a5)))); + p2 = b0 + y * (b1 + y * (b2 + y * (b3 + y * (b4 + y)))); + r += half * y + y * p1/p2; + break; + case 1: + p1 = g0 + y * (g1 + y * (g2 + y * (g3 + y * (g4 + y * (g5 + y * g6))))); + p2 = h0 + y * (h1 + y * (h2 + y * (h3 + y * (h4 + y * (h5 + y))))); + p = tt + y * p1/p2; + r += (tf + p); + break; + case 2: + p1 = y * (u0 + y * (u1 + y * (u2 + y * (u3 + y * (u4 + y * (u5 + y * u6)))))); + p2 = v0 + y * (v1 + y * (v2 + y * (v3 + y * (v4 + y * (v5 + y))))); + r += (-half * y + p1 / p2); + } + } + else if (ix < 0x40028000) /* 8.0 */ + { + /* x < 8.0 */ + i = (int) x; + t = zero; + y = x - (double) i; + p = y * + (s0 + y * (s1 + y * (s2 + y * (s3 + y * (s4 + y * (s5 + y * s6)))))); + q = r0 + y * (r1 + y * (r2 + y * (r3 + y * (r4 + y * (r5 + y * (r6 + y)))))); + r = half * y + p / q; + z = one; /* lgamma(1+s) = log(s) + lgamma(s) */ + switch (i) + { + case 7: + z *= (y + 6.0); /* FALLTHRU */ + case 6: + z *= (y + 5.0); /* FALLTHRU */ + case 5: + z *= (y + 4.0); /* FALLTHRU */ + case 4: + z *= (y + 3.0); /* FALLTHRU */ + case 3: + z *= (y + 2.0); /* FALLTHRU */ + r += __ieee754_logl (z); + break; + } + } + else if (ix < 0x40418000) /* 2^66 */ + { + /* 8.0 <= x < 2**66 */ + t = __ieee754_logl (x); + z = one / x; + y = z * z; + w = w0 + z * (w1 + + y * (w2 + y * (w3 + y * (w4 + y * (w5 + y * (w6 + y * w7)))))); + r = (x - half) * (t - one) + w; + } + else + /* 2**66 <= x <= inf */ + r = x * (__ieee754_logl (x) - one); + if (se & 0x8000) + r = nadj - r; + return r; +} Modified: haiku/trunk/src/system/libroot/posix/glibc/arch/x86/Jamfile =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/x86/Jamfile 2008-09-01 19:44:27 UTC (rev 27273) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/x86/Jamfile 2008-09-01 19:54:55 UTC (rev 27274) @@ -26,11 +26,11 @@ mul.c mul_n.c e_cosh.c e_coshf.c # e_coshl.c e_sinh.c e_sinhf.c # e_sinhl.c - e_gamma_r.c e_gammaf_r.c + e_gamma_r.c e_gammaf_r.c e_gammal_r.c e_j0.c e_j0f.c e_j1.c e_j1f.c e_jn.c e_jnf.c - e_lgamma_r.c e_lgammaf_r.c + e_lgamma_r.c e_lgammaf_r.c e_lgammal_r.c k_cos.c k_cosf.c k_sin.c k_sinf.c k_tan.c k_tanf.c @@ -90,7 +90,7 @@ w_scalb.c w_scalbf.c # w_scalbl.c w_sinh.c w_sinhf.c # w_sinhl.c w_sqrt.c w_sqrtf.c # w_sqrtl.c - w_tgamma.c w_tgammaf.c # w_tgammal.c + w_tgamma.c w_tgammaf.c w_tgammal.c ; MergeObject posix_gnu_arch_$(TARGET_ARCH)_other.o : From korli at mail.berlios.de Mon Sep 1 22:05:35 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Mon, 1 Sep 2008 22:05:35 +0200 Subject: [Haiku-commits] r27275 - haiku/trunk/src/system/libroot/posix/glibc/libio Message-ID: <200809012005.m81K5ZVw012282@sheep.berlios.de> Author: korli Date: 2008-09-01 22:05:35 +0200 (Mon, 01 Sep 2008) New Revision: 27275 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27275&view=rev Modified: haiku/trunk/src/system/libroot/posix/glibc/libio/Jamfile Log: added getwchar and iofgetws Modified: haiku/trunk/src/system/libroot/posix/glibc/libio/Jamfile =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/libio/Jamfile 2008-09-01 19:54:55 UTC (rev 27274) +++ haiku/trunk/src/system/libroot/posix/glibc/libio/Jamfile 2008-09-01 20:05:35 UTC (rev 27275) @@ -98,6 +98,8 @@ # fwscanf.c getwc.c getwc_u.c + getwchar.c + iofgetws.c iofputws.c iofputws_u.c iogetwline.c From anevilyak at mail.berlios.de Mon Sep 1 22:12:14 2008 From: anevilyak at mail.berlios.de (anevilyak at BerliOS) Date: Mon, 1 Sep 2008 22:12:14 +0200 Subject: [Haiku-commits] r27276 - haiku/trunk/headers/os/interface Message-ID: <200809012012.m81KCEJK012760@sheep.berlios.de> Author: anevilyak Date: 2008-09-01 22:12:13 +0200 (Mon, 01 Sep 2008) New Revision: 27276 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27276&view=rev Modified: haiku/trunk/headers/os/interface/CardLayout.h Log: Just noticed this file was using CR/LF newlines... Modified: haiku/trunk/headers/os/interface/CardLayout.h =================================================================== --- haiku/trunk/headers/os/interface/CardLayout.h 2008-09-01 20:05:35 UTC (rev 27275) +++ haiku/trunk/headers/os/interface/CardLayout.h 2008-09-01 20:12:13 UTC (rev 27276) @@ -1,47 +1,47 @@ -/* - * Copyright 2006, Haiku Inc. - * Distributed under the terms of the MIT License. - */ -#ifndef _CARD_LAYOUT_H -#define _CARD_LAYOUT_H - -#include - - -class BCardLayout : public BLayout { -public: - BCardLayout(); - virtual ~BCardLayout(); - - BLayoutItem* VisibleItem() const; - int32 VisibleIndex() const; - void SetVisibleItem(int32 index); - void SetVisibleItem(BLayoutItem* item); - - virtual BSize MinSize(); - virtual BSize MaxSize(); - virtual BSize PreferredSize(); - virtual BAlignment Alignment(); - - virtual bool HasHeightForWidth(); - virtual void GetHeightForWidth(float width, float* min, - float* max, float* preferred); - - virtual void InvalidateLayout(); - virtual void LayoutView(); - -protected: - virtual void ItemAdded(BLayoutItem* item); - virtual void ItemRemoved(BLayoutItem* item); - -private: - BSize fMin; - BSize fMax; - BSize fPreferred; - BLayoutItem* fVisibleItem; - bool fMinMaxValid; - - void _ValidateMinMax(); -}; - -#endif // _CARD_LAYOUT_H +/* + * Copyright 2006, Haiku Inc. + * Distributed under the terms of the MIT License. + */ +#ifndef _CARD_LAYOUT_H +#define _CARD_LAYOUT_H + +#include + + +class BCardLayout : public BLayout { +public: + BCardLayout(); + virtual ~BCardLayout(); + + BLayoutItem* VisibleItem() const; + int32 VisibleIndex() const; + void SetVisibleItem(int32 index); + void SetVisibleItem(BLayoutItem* item); + + virtual BSize MinSize(); + virtual BSize MaxSize(); + virtual BSize PreferredSize(); + virtual BAlignment Alignment(); + + virtual bool HasHeightForWidth(); + virtual void GetHeightForWidth(float width, float* min, + float* max, float* preferred); + + virtual void InvalidateLayout(); + virtual void LayoutView(); + +protected: + virtual void ItemAdded(BLayoutItem* item); + virtual void ItemRemoved(BLayoutItem* item); + +private: + BSize fMin; + BSize fMax; + BSize fPreferred; + BLayoutItem* fVisibleItem; + bool fMinMaxValid; + + void _ValidateMinMax(); +}; + +#endif // _CARD_LAYOUT_H Property changes on: haiku/trunk/headers/os/interface/CardLayout.h ___________________________________________________________________ Name: svn:eol-style + native From korli at mail.berlios.de Mon Sep 1 22:18:50 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Mon, 1 Sep 2008 22:18:50 +0200 Subject: [Haiku-commits] r27277 - haiku/trunk/src/system/libroot/posix/glibc/wctype Message-ID: <200809012018.m81KIoGP014593@sheep.berlios.de> Author: korli Date: 2008-09-01 22:18:49 +0200 (Mon, 01 Sep 2008) New Revision: 27277 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27277&view=rev Added: haiku/trunk/src/system/libroot/posix/glibc/wctype/towctrans.c Modified: haiku/trunk/src/system/libroot/posix/glibc/wctype/Jamfile Log: added towctrans Modified: haiku/trunk/src/system/libroot/posix/glibc/wctype/Jamfile =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/wctype/Jamfile 2008-09-01 20:12:13 UTC (rev 27276) +++ haiku/trunk/src/system/libroot/posix/glibc/wctype/Jamfile 2008-09-01 20:18:49 UTC (rev 27277) @@ -12,6 +12,7 @@ MergeObject posix_gnu_wctype.o : iswctype.c + towctrans.c wcfuncs.c wctrans.c wctype.c Added: haiku/trunk/src/system/libroot/posix/glibc/wctype/towctrans.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/wctype/towctrans.c 2008-09-01 20:12:13 UTC (rev 27276) +++ haiku/trunk/src/system/libroot/posix/glibc/wctype/towctrans.c 2008-09-01 20:18:49 UTC (rev 27277) @@ -0,0 +1,36 @@ +/* Map wide character using given mapping. + Copyright (C) 1996, 1997, 2000, 2004 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include + +/* Define the lookup function. */ +#include "wchar-lookup.h" + +wint_t +__towctrans (wint_t wc, wctrans_t desc) +{ + /* If the user passes in an invalid DESC valid (the one returned from + `wctrans' in case of an error) simply return the value. */ + if (desc == (wctrans_t) 0) + return wc; + + return wctrans_table_lookup ((const char *) desc, wc); +} +libc_hidden_def (__towctrans) +weak_alias (__towctrans, towctrans) From korli at mail.berlios.de Mon Sep 1 22:26:40 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Mon, 1 Sep 2008 22:26:40 +0200 Subject: [Haiku-commits] r27278 - haiku/trunk/src/system/libroot/posix/glibc/stdlib Message-ID: <200809012026.m81KQewp015276@sheep.berlios.de> Author: korli Date: 2008-09-01 22:26:40 +0200 (Mon, 01 Sep 2008) New Revision: 27278 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27278&view=rev Modified: haiku/trunk/src/system/libroot/posix/glibc/stdlib/Jamfile Log: added random_r.c Modified: haiku/trunk/src/system/libroot/posix/glibc/stdlib/Jamfile =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/stdlib/Jamfile 2008-09-01 20:18:49 UTC (rev 27277) +++ haiku/trunk/src/system/libroot/posix/glibc/stdlib/Jamfile 2008-09-01 20:26:40 UTC (rev 27278) @@ -27,6 +27,7 @@ mrand48_r.c nrand48.c nrand48_r.c + random_r.c seed48.c seed48_r.c srand48.c From stippi at mail.berlios.de Mon Sep 1 22:27:34 2008 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Mon, 1 Sep 2008 22:27:34 +0200 Subject: [Haiku-commits] r27279 - haiku/trunk/src/apps/aboutsystem Message-ID: <200809012027.m81KRYmM015371@sheep.berlios.de> Author: stippi Date: 2008-09-01 22:27:33 +0200 (Mon, 01 Sep 2008) New Revision: 27279 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27279&view=rev Modified: haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp Log: Sorry, but another fix was needed. The previous list of most influential developers was based on the oloh results, but these go only 3 years back. The SVN revision history is much more complete and contains also the CVS history apart from a screw up at revision 10. However, I was able to obtain a much more correct list now and so some resorting was due. According to these stats, Michael Lotz would not appear in the list - however, I feel he should be in there, since he was the first to run Haiku with app_server, the first to run a browser on it, wrote the USB stack and so on. The other possiblity would be to make the cut at 7 entries, which coincidentally would mean everyone in the list has contributed more than 1000 commits. Modified: haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp =================================================================== --- haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp 2008-09-01 20:26:40 UTC (rev 27278) +++ haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp 2008-09-01 20:27:33 UTC (rev 27279) @@ -394,13 +394,13 @@ fCreditsView->Insert( "Axel D?rfler\n" "Ingo Weinhold\n" + "J?r?me Duval\n" "Stephan A?mus\n" - "J?r?me Duval\n" + "Marcus Overhagen\n" "Stefano Ceccherini\n" + "Rudolf Cornelissen\n" "Fran?ois Revol\n" - "Marcus Overhagen\n" "Michael Lotz\n" - "Rudolf Cornelissen\n" "\n"); From stippi at mail.berlios.de Mon Sep 1 22:42:33 2008 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Mon, 1 Sep 2008 22:42:33 +0200 Subject: [Haiku-commits] r27280 - haiku/trunk/src/apps/aboutsystem Message-ID: <200809012042.m81KgXYF019835@sheep.berlios.de> Author: stippi Date: 2008-09-01 22:42:32 +0200 (Mon, 01 Sep 2008) New Revision: 27280 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27280&view=rev Modified: haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp Log: Removed Jorge again by his own request. I completely forgot why Jorge was not in the list and thought it was an oversight. Sorry. Modified: haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp =================================================================== --- haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp 2008-09-01 20:27:33 UTC (rev 27279) +++ haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp 2008-09-01 20:42:32 UTC (rev 27280) @@ -411,7 +411,6 @@ fCreditsView->Insert( "Phil Greenway\n" "Gavin James\n" - "Jorge G. Mare\n" "Urias McCullough\n" "Niels Sascha Reedijk\n" "Jonathan Yoder\n" From marcusoverhagen at mail.berlios.de Mon Sep 1 23:25:45 2008 From: marcusoverhagen at mail.berlios.de (marcusoverhagen at BerliOS) Date: Mon, 1 Sep 2008 23:25:45 +0200 Subject: [Haiku-commits] r27281 - haiku/trunk/src/add-ons/kernel/bus_managers/ata Message-ID: <200809012125.m81LPjHf000639@sheep.berlios.de> Author: marcusoverhagen Date: 2008-09-01 23:25:44 +0200 (Mon, 01 Sep 2008) New Revision: 27281 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27281&view=rev Added: haiku/trunk/src/add-ons/kernel/bus_managers/ata/ata_tracing.cpp haiku/trunk/src/add-ons/kernel/bus_managers/ata/ata_tracing.h Modified: haiku/trunk/src/add-ons/kernel/bus_managers/ata/Jamfile Log: ATA kernel tracing functions. Modified: haiku/trunk/src/add-ons/kernel/bus_managers/ata/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/ata/Jamfile 2008-09-01 20:42:32 UTC (rev 27280) +++ haiku/trunk/src/add-ons/kernel/bus_managers/ata/Jamfile 2008-09-01 21:25:44 UTC (rev 27281) @@ -5,6 +5,7 @@ KernelAddon ide : ata.c + ata_tracing.cpp ata_request.c atapi.c channels.c Added: haiku/trunk/src/add-ons/kernel/bus_managers/ata/ata_tracing.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/ata/ata_tracing.cpp 2008-09-01 20:42:32 UTC (rev 27280) +++ haiku/trunk/src/add-ons/kernel/bus_managers/ata/ata_tracing.cpp 2008-09-01 21:25:44 UTC (rev 27281) @@ -0,0 +1,61 @@ +#include +#include + +#include "ata_tracing.h" +#include "ide_internal.h" + +#if ATA_TRACING + +class ATATraceEntry : public AbstractTraceEntry { + public: + ATATraceEntry(int bus, int device, const char *info) + : fBus(bus) + , fDevice(device) + { + strlcpy(fInfo, info, sizeof(fInfo)); + Initialized(); + } + + void AddDump(TraceOutput& out, const char* name) + { + out.Print("ata"); + out.Print(" - %s - ", name); + out.Print("bus %d", fBus); + out.Print("device %d", fDevice); + out.Print("%s", fInfo); + } + + int fBus; + int fDevice; + char fInfo[200]; +}; + + +extern "C" void +__ata_trace_device(ide_device_info *dev, const char *fmt, ...) +{ + char info[200]; + va_list ap; + + va_start(ap, fmt); + vsnprintf(info, sizeof(info), fmt, ap); + va_end(ap); + + new(std::nothrow) ATATraceEntry(dev->bus->path_id, dev->is_device1, info); +} + + +extern "C" void +__ata_trace_bus_device(ide_bus_info *bus, int dev, const char *fmt, ...) +{ + char info[200]; + va_list ap; + + va_start(ap, fmt); + vsnprintf(info, sizeof(info), fmt, ap); + va_end(ap); + + new(std::nothrow) ATATraceEntry(bus->path_id, dev, info); +} + +#endif Added: haiku/trunk/src/add-ons/kernel/bus_managers/ata/ata_tracing.h =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/ata/ata_tracing.h 2008-09-01 20:42:32 UTC (rev 27280) +++ haiku/trunk/src/add-ons/kernel/bus_managers/ata/ata_tracing.h 2008-09-01 21:25:44 UTC (rev 27281) @@ -0,0 +1,32 @@ +/* + * Copyright 2008, Marcus Overhagen. All rights reserved. + * Distributed under the terms of the MIT License. + */ + +#include "tracing_config.h" + +#if ATA_TRACING + + struct ide_bus_info; + struct ide_device_info; + +#ifdef __cplusplus + extern "C" { +#endif + + void __ata_trace_device(struct ide_device_info *dev, const char *fmt, ...); + void __ata_trace_bus_device(struct ide_bus_info *bus, int dev, const char *fmt, ...); + +#ifdef __cplusplus + } +#endif + + #define T(dev, args...) __ata_trace_device(dev, args) + #define T2(bus, dev, args...) __ata_trace_bus_device(bus, dev, args) + +#else + + #define T(x...) + #define T2(x...) + +#endif From marcusoverhagen at mail.berlios.de Mon Sep 1 23:26:47 2008 From: marcusoverhagen at mail.berlios.de (marcusoverhagen at BerliOS) Date: Mon, 1 Sep 2008 23:26:47 +0200 Subject: [Haiku-commits] r27282 - haiku/trunk/src/add-ons/kernel/bus_managers/ata Message-ID: <200809012126.m81LQlLL001307@sheep.berlios.de> Author: marcusoverhagen Date: 2008-09-01 23:26:46 +0200 (Mon, 01 Sep 2008) New Revision: 27282 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27282&view=rev Modified: haiku/trunk/src/add-ons/kernel/bus_managers/ata/ata.c Log: Use kernel tracing feature. Doesn't seem to work, don't know why. Modified: haiku/trunk/src/add-ons/kernel/bus_managers/ata/ata.c =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/ata/ata.c 2008-09-01 21:25:44 UTC (rev 27281) +++ haiku/trunk/src/add-ons/kernel/bus_managers/ata/ata.c 2008-09-01 21:26:46 UTC (rev 27282) @@ -14,6 +14,7 @@ #include "ide_sim.h" #include "ide_cmds.h" +#include "ata_tracing.h" #define TRACE dprintf #define FLOW dprintf @@ -30,6 +31,8 @@ { ide_task_file tf; + T2(bus, device, "ata_select_device"); + // FLOW("ata_select_device device %d\n", device); tf.chs.head = 0; @@ -42,14 +45,18 @@ // for debugging only bus->controller->read_command_block_regs(bus->channel_cookie, &tf, ide_mask_device_head); - if (tf.chs.device != device) + if (tf.chs.device != device) { + T2(bus, device, "ata_select_device failed, device not selected. head 0x%x, mode 0x%x, device %d", tf.chs.head, tf.chs.mode, tf.chs.device); TRACE("ata_select_device result: device %d not selected! head 0x%x, mode 0x%x, device %d\n", device, tf.chs.head, tf.chs.mode, tf.chs.device); + } } void ata_select(ide_device_info *device) { + T(device, "ata_select"); + ASSERT(device->is_device1 == device->tf.chs.device); ata_select_device(device->bus, device->is_device1); } @@ -63,7 +70,10 @@ ata_is_device_present(ide_bus_info *bus, int device) { ide_task_file tf; + bool present; + T2(bus, device, "ata_is_device_present ?"); + ata_select_device(bus, device); tf.lba.sector_count = 0xaa; @@ -76,7 +86,11 @@ bus->controller->read_command_block_regs(bus->channel_cookie, &tf, ide_mask_sector_count | ide_mask_LBA_low); - return tf.lba.sector_count == 0xaa && tf.lba.lba_0_7 == 0x55; + present = tf.lba.sector_count == 0xaa && tf.lba.lba_0_7 == 0x55; + + T2(bus, device, "ata_is_device_present present=%d", present); + + return present; } @@ -1117,7 +1131,7 @@ return B_ERROR; } - if (ata_wait(bus, ide_status_drq, ide_status_bsy, 0, isAtapi ? 3000000 : 500000) != B_OK) { + if (ata_wait(bus, ide_status_drq, ide_status_bsy, 0, isAtapi ? 20000000 : 500000) != B_OK) { TRACE("ata_identify_device: wait failed\n"); return B_ERROR; } From ingo_weinhold at gmx.de Mon Sep 1 23:37:06 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Mon, 01 Sep 2008 23:37:06 +0200 Subject: [Haiku-commits] r27262 - haiku/trunk/src/apps/aboutsystem In-Reply-To: References: <200809010904.m8194ARK022625@sheep.berlios.de> <20080901184138.26098.5@stippis2.1220273270.fake> Message-ID: <20080901233706.551.2@knochen-vm.localdomain> On 2008-09-01 at 19:17:20 [+0200], Michael Pfeiffer wrote: > > Am 01.09.2008 um 18:41 schrieb Stephan Assmus: > > > Nice. Thanks a lot! How did you produce the Changelog file? > > Sorry now I have to break my EOM for this thread :) > > I checked out the module "current" from open-beos CVS repo from > Sourceforge and then > used the perl script I mentioned in the other mail. > > > I am asking to > > know what revisions it includes. Do you know if the SVN revision > > number > > actually includes the previous CVS commits? I thought the repository > > was > > imported with some history, not started from scratch (if you go to > > http://dev.haiku-os.org/changeset/7, you will see it has the authors > > starting from 7 years ago). > > Now I am completely confused. The first date in the CVS repository is > 9 Jul 2002. Which is a long commit from ejakowatz with the entire > source tree (Message: "It is accomplished ..."). At first I thought my > memory must fool me, but know I think there was a repo before this CVS > repo. And yes the changes in "current" are also visible in the SVN > history. So you must ignore my numbers as these should already be part > of the SVN numbers. > > So the question remains, what has happened to the other repo? Anyway, > I will now stop with this. It was actually the same repository. Every team had their own top-level module. Erik was the one who merged them into a single module (with the slightly suboptimal name "current"). IIRC the SourceForge admins had been asked to hard-delete the obsolete modules, so all history of those is really gone, I'm afraid. CU, Ingo From ingo_weinhold at gmx.de Tue Sep 2 00:18:07 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Tue, 02 Sep 2008 00:18:07 +0200 Subject: [Haiku-commits] r27281 - haiku/trunk/src/add-ons/kernel/bus_managers/ata In-Reply-To: <200809012125.m81LPjHf000639@sheep.berlios.de> References: <200809012125.m81LPjHf000639@sheep.berlios.de> Message-ID: <20080902001807.1741.9@knochen-vm.localdomain> On 2008-09-01 at 23:25:45 [+0200], marcusoverhagen at BerliOS wrote: [...] > Added: haiku/trunk/src/add-ons/kernel/bus_managers/ata/ata_tracing.cpp > =================================================================== > --- haiku/trunk/src/add-ons/kernel/bus_managers/ata/ata_tracing.cpp > 2008-09-01 20:42:32 UTC (rev 27280) > +++ haiku/trunk/src/add-ons/kernel/bus_managers/ata/ata_tracing.cpp > 2008-09-01 21:25:44 UTC (rev 27281) > @@ -0,0 +1,61 @@ > +#include > +#include > + > +#include "ata_tracing.h" > +#include "ide_internal.h" > + > +#if ATA_TRACING > + > +class ATATraceEntry : public AbstractTraceEntry { > + public: > + ATATraceEntry(int bus, int device, const char *info) > + : fBus(bus) > + , fDevice(device) > + { > + strlcpy(fInfo, info, sizeof(fInfo)); > + Initialized(); > + } > + > + void AddDump(TraceOutput& out, const char* name) > + { > + out.Print("ata"); > + out.Print(" - %s - ", name); > + out.Print("bus %d", fBus); > + out.Print("device %d", fDevice); > + out.Print("%s", fInfo); You don't have any spacing between the last three outputs. Besides, it is really possible to print all that in a single out.Print() call. > + } > + > + int fBus; > + int fDevice; > + char fInfo[200]; To save tracing buffer sapce, it is advisable to allocate space for variable-length strings dynamically via: char* alloc_tracing_buffer_strcpy(const char* source, size_t maxSize, bool user); CU, Ingo From ingo_weinhold at gmx.de Tue Sep 2 00:20:06 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Tue, 02 Sep 2008 00:20:06 +0200 Subject: [Haiku-commits] r27282 - haiku/trunk/src/add-ons/kernel/bus_managers/ata In-Reply-To: <200809012126.m81LQlLL001307@sheep.berlios.de> References: <200809012126.m81LQlLL001307@sheep.berlios.de> Message-ID: <20080902002006.1814.10@knochen-vm.localdomain> On 2008-09-01 at 23:26:47 [+0200], marcusoverhagen at BerliOS wrote: > Author: marcusoverhagen > Date: 2008-09-01 23:26:46 +0200 (Mon, 01 Sep 2008) > New Revision: 27282 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27282&view=rev > > Modified: > haiku/trunk/src/add-ons/kernel/bus_managers/ata/ata.c > Log: > Use kernel tracing feature. Doesn't seem to work, don't know why. From ingo_weinhold at gmx.de Tue Sep 2 00:41:53 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Tue, 02 Sep 2008 00:41:53 +0200 Subject: [Haiku-commits] r27268 - haiku/trunk/src/system/kernel/posix In-Reply-To: <200809011616.m81GG3N6001985@sheep.berlios.de> References: <200809011616.m81GG3N6001985@sheep.berlios.de> Message-ID: <20080902004153.1928.11@knochen-vm.localdomain> On 2008-09-01 at 18:16:03 [+0200], sbenedetto at BerliOS wrote: > Author: sbenedetto > Date: 2008-09-01 18:16:03 +0200 (Mon, 01 Sep 2008) > New Revision: 27268 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27268&view=rev > > Modified: > haiku/trunk/src/system/kernel/posix/xsi_semaphore.cpp > Log: > * Fix a potential race condition when deleting a semaphore set: previously > only > the ipc hash table lock along with the semaphore set hash table lock were > hold, thinking (wrongly) that the semaphore set lock itself was not > needed. > What could happen was that another process on semop could have gained the > lock > of the set itself, and then release the semaphore set hash table lock. > This would make it think that the set was still valid, while it could have > actually been deleted right after it release the semaphore set hash table > lock. > Same would have happened for any other processes waiting on the semaphore > set > mutex queue. By calling the lock on the mutex when deleting the set, it > *should be* safe to assume that there is no one else waiting on its queue, > since the list of waiters is handled in a FIFO way. > > As far as I can see from the mutex_destroy code, it looks safe to hold the > lock > when calling this function. Please confirm. It is. Unless I miss something, it doesn't solve the problem, though. In semop() the semaphore set is unlocked while waiting for a semaphore. A IPC_RMID after unlocking would cause the semaphore->Wait() to access free()d memory. Personally I'm a huge fan of ref-counting in such cases. > Modified: haiku/trunk/src/system/kernel/posix/xsi_semaphore.cpp > =================================================================== > --- haiku/trunk/src/system/kernel/posix/xsi_semaphore.cpp 2008-09-01 > 14:43:25 UTC (rev 27267) > +++ haiku/trunk/src/system/kernel/posix/xsi_semaphore.cpp 2008-09-01 > 16:16:03 UTC (rev 27268) > @@ -846,7 +846,11 @@ > setLocker.SetTo(&semaphoreSet->Lock(), false); > setHashLocker.Unlock(); > ipcHashLocker.Unlock(); > - } > + } else > + // We are about to delete the set along with its mutex, so > + // we can't use the MutexLocker class, as the mutex itself > + // won't exist on function exit > + mutex_lock(&semaphoreSet->Lock()); There's an AutoLocker::Detach() method, which uninits the auto locker but let's the caller keep the lock (if it was locked in the first place that is). CU, Ingo From aldeck at mail.berlios.de Tue Sep 2 04:20:14 2008 From: aldeck at mail.berlios.de (aldeck at BerliOS) Date: Tue, 2 Sep 2008 04:20:14 +0200 Subject: [Haiku-commits] r27283 - haiku/trunk/src/apps/deskbar Message-ID: <200809020220.m822KEnm027946@sheep.berlios.de> Author: aldeck Date: 2008-09-02 04:20:12 +0200 (Tue, 02 Sep 2008) New Revision: 27283 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27283&view=rev Removed: haiku/trunk/src/apps/deskbar/LongClickTracker.cpp haiku/trunk/src/apps/deskbar/LongClickTracker.h Modified: haiku/trunk/src/apps/deskbar/Jamfile haiku/trunk/src/apps/deskbar/TimeView.cpp haiku/trunk/src/apps/deskbar/TimeView.h Log: - Well, i told ya it was better with a BMessageRunner ;-P Modified: haiku/trunk/src/apps/deskbar/Jamfile =================================================================== --- haiku/trunk/src/apps/deskbar/Jamfile 2008-09-01 21:26:46 UTC (rev 27282) +++ haiku/trunk/src/apps/deskbar/Jamfile 2008-09-02 02:20:12 UTC (rev 27283) @@ -34,7 +34,6 @@ CalendarMenuItem.cpp DeskBarUtils.cpp ExpandoMenuBar.cpp - LongClickTracker.cpp ShowHideMenuItem.cpp StatusView.cpp StatusViewShelf.cpp Deleted: haiku/trunk/src/apps/deskbar/LongClickTracker.cpp Deleted: haiku/trunk/src/apps/deskbar/LongClickTracker.h Modified: haiku/trunk/src/apps/deskbar/TimeView.cpp =================================================================== --- haiku/trunk/src/apps/deskbar/TimeView.cpp 2008-09-01 21:26:46 UTC (rev 27282) +++ haiku/trunk/src/apps/deskbar/TimeView.cpp 2008-09-02 02:20:12 UTC (rev 27283) @@ -45,6 +45,7 @@ #include #include +#include #include #include #include @@ -85,7 +86,7 @@ fMaxWidth(maxWidth), fHeight(height), fOrientation(true), - fLongClickTracker(this, kMsgLongClick) + fLongClickMessageRunner(NULL) { fShowingDate = false; fTime = fLastTime = time(NULL); @@ -157,8 +158,6 @@ ResizeToPreferred(); CalculateTextPlacement(); - - fLongClickTracker.Start(); } @@ -376,6 +375,17 @@ if (buttons == B_SECONDARY_MOUSE_BUTTON) { ShowClockOptions(ConvertToScreen(point)); return; + } else if (buttons == B_PRIMARY_MOUSE_BUTTON) { + BMessage * longClickMessage = new BMessage(kMsgLongClick); + longClickMessage->AddPoint("where", point); + + bigtime_t longClickThreshold; + get_click_speed(&longClickThreshold); + // use the doubleClickSpeed as a threshold + + delete fLongClickMessageRunner; + fLongClickMessageRunner = new BMessageRunner(BMessenger(this), + longClickMessage, longClickThreshold, 1); } // flip to/from showing date or time @@ -392,6 +402,14 @@ void +TTimeView::MouseUp(BPoint point) +{ + delete fLongClickMessageRunner; + fLongClickMessageRunner = NULL; +} + + +void TTimeView::Pulse() { time_t curTime = time(NULL); Modified: haiku/trunk/src/apps/deskbar/TimeView.h =================================================================== --- haiku/trunk/src/apps/deskbar/TimeView.h 2008-09-01 21:26:46 UTC (rev 27282) +++ haiku/trunk/src/apps/deskbar/TimeView.h 2008-09-02 02:20:12 UTC (rev 27283) @@ -36,13 +36,13 @@ #include #include -#include "LongClickTracker.h" const uint32 kMsgShowSeconds = 'ShSc'; const uint32 kMsgMilTime = 'MilT'; const uint32 kMsgFullDate = 'FDat'; const uint32 kMsgEuroDate = 'EDat'; +class BMessageRunner; #ifdef AS_REPLICANT class _EXPORT TTimeView; @@ -67,6 +67,7 @@ void FrameMoved(BPoint); void MessageReceived(BMessage*); void MouseDown(BPoint where); + void MouseUp(BPoint where); void Pulse(); bool ShowingSeconds() { return fShowSeconds; } @@ -125,7 +126,7 @@ BPoint fTimeLocation; BPoint fDateLocation; - LongClickTracker fLongClickTracker; + BMessageRunner* fLongClickMessageRunner; }; From marcusoverhagen at arcor.de Tue Sep 2 09:35:53 2008 From: marcusoverhagen at arcor.de (Marcus Overhagen) Date: Tue, 2 Sep 2008 09:35:53 +0200 (CEST) Subject: [Haiku-commits] r27282 - haiku/trunk/src/add-ons/kernel/bus_managers/ata In-Reply-To: <20080902002006.1814.10@knochen-vm.localdomain> References: <20080902002006.1814.10@knochen-vm.localdomain> <200809012126.m81LQlLL001307@sheep.berlios.de> Message-ID: <32567841.1220340953394.JavaMail.ngmail@webmail17.arcor-online.net> Ingo Weinhold schrieb: > > Use kernel tracing feature. Doesn't seem to work, don't know why. > > From a look at the patches, it looks OK. I suppose you haven't just > forgotten to actually enable it? :-P I'm pretty sure I enabled it, because I had to fix some errors before the code between the #ifdef would compile. The output looks like this: http://pastebin.com/m96b8f28 / http://nopaste.org/p/aziDmES2d Lots of empty lines. I don't know whats wrong. if you have any idea, feel free to fix it. Thanks, Marcus Jetzt komfortabel bei Arcor-Digital TV einsteigen: Mehr Happy Ends, mehr Herzschmerz, mehr Fernsehen! Erleben Sie 50 digitale TV Programme und optional 60 Pay TV Sender, einen elektronischen Programmf?hrer mit Movie Star Bewertungen von TV Movie. Au?erdem, aktuelle Filmhits und spannende Dokus in der Arcor-Videothek. Infos unter www.arcor.de/tv From superstippi at gmx.de Tue Sep 2 10:19:17 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Tue, 02 Sep 2008 10:19:17 +0200 Subject: [Haiku-commits] r27283 - haiku/trunk/src/apps/deskbar In-Reply-To: <200809020220.m822KEnm027946@sheep.berlios.de> References: <200809020220.m822KEnm027946@sheep.berlios.de> Message-ID: <20080902081917.257230@gmx.net> Hi Alex, > Log: > - Well, i told ya it was better with a BMessageRunner ;-P [...] > @@ -376,6 +375,17 @@ > if (buttons == B_SECONDARY_MOUSE_BUTTON) { > ShowClockOptions(ConvertToScreen(point)); > return; > + } else if (buttons == B_PRIMARY_MOUSE_BUTTON) { > + BMessage * longClickMessage = new BMessage(kMsgLongClick); > + longClickMessage->AddPoint("where", point); > + > + bigtime_t longClickThreshold; > + get_click_speed(&longClickThreshold); > + // use the doubleClickSpeed as a threshold > + > + delete fLongClickMessageRunner; > + fLongClickMessageRunner = new BMessageRunner(BMessenger(this), > + longClickMessage, longClickThreshold, 1); > } > > // flip to/from showing date or time This is a common source for memory leaks. The BMessageRunner constructor takes a "const BMessage*" to indicate that the message will be copied. So correct would be: + BMessage longClickMessage(kMsgLongClick); + longClickMessage.AddPoint("where", point); + + bigtime_t longClickThreshold; + get_click_speed(&longClickThreshold); + // use the doubleClickSpeed as a threshold + + delete fLongClickMessageRunner; + fLongClickMessageRunner = new BMessageRunner(BMessenger(this), + &longClickMessage, longClickThreshold, 1); Unfortunately, the Be API is not consistent in this regard. For example, all BControls take over the ownership of passed BMessage objects. I think (IIRC) everything in the App Kit, though, makes copies. When we are at R2 times, a big cleanup is due to resolve these sources of misunderstanding. I don't know why Be didn't use "const BMessage&" throughout where copies are made. Best regards, -Stephan From emitrax at gmail.com Tue Sep 2 10:28:14 2008 From: emitrax at gmail.com (Salvatore Benedetto) Date: Tue, 2 Sep 2008 10:28:14 +0200 Subject: [Haiku-commits] r27268 - haiku/trunk/src/system/kernel/posix In-Reply-To: <20080902004153.1928.11@knochen-vm.localdomain> References: <200809011616.m81GG3N6001985@sheep.berlios.de> <20080902004153.1928.11@knochen-vm.localdomain> Message-ID: 2008/9/2 Ingo Weinhold : > > On 2008-09-01 at 18:16:03 [+0200], sbenedetto at BerliOS > wrote: >> Author: sbenedetto >> Date: 2008-09-01 18:16:03 +0200 (Mon, 01 Sep 2008) >> New Revision: 27268 >> ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27268&view=rev >> >> Modified: >> haiku/trunk/src/system/kernel/posix/xsi_semaphore.cpp >> Log: >> * Fix a potential race condition when deleting a semaphore set: previously >> only >> the ipc hash table lock along with the semaphore set hash table lock were >> hold, thinking (wrongly) that the semaphore set lock itself was not >> needed. >> What could happen was that another process on semop could have gained the >> lock >> of the set itself, and then release the semaphore set hash table lock. >> This would make it think that the set was still valid, while it could have >> actually been deleted right after it release the semaphore set hash table >> lock. >> Same would have happened for any other processes waiting on the semaphore >> set >> mutex queue. By calling the lock on the mutex when deleting the set, it >> *should be* safe to assume that there is no one else waiting on its queue, >> since the list of waiters is handled in a FIFO way. >> >> As far as I can see from the mutex_destroy code, it looks safe to hold the >> lock >> when calling this function. Please confirm. > > It is. Unless I miss something, it doesn't solve the problem, though. In > semop() the semaphore set is unlocked while waiting for a semaphore. A > IPC_RMID after unlocking would cause the semaphore->Wait() to access free()d > memory. I just woke up so I shouldn't be answering :-) In semop(), the set must be unlock before going to sleep otherwise it would not work, thus so far so good. Once waked up, the process would first lock the set hash table, which is always fine, and issue a lookup. If the set is still there, there was not IPC_RMID and there cannot be meanwhile as we are holding the set lock. If, on the other hand, the set was deleted, we safely return without accessing the set lock. Now that I think of though, the only thing that could happen is calling the Unlock in the destructor of the MutexLocker object on function exit, which means accessing a non-existing lock. Is this what you meant? > > Personally I'm a huge fan of ref-counting in such cases. If I don't manage to fix the problem with the existing design, I'll redo it with ref-counting. Thanks for reviewing, -- Salvatore Benedetto (a.k.a. emitrax) Student of Computer Engineer University of Pisa www.haiku-os.it From stefano.ceccherini at gmail.com Tue Sep 2 10:35:06 2008 From: stefano.ceccherini at gmail.com (Stefano Ceccherini) Date: Tue, 2 Sep 2008 10:35:06 +0200 Subject: [Haiku-commits] r27264 - in haiku/trunk: headers/private/shared src/kits/shared In-Reply-To: References: <200809011311.m81DBUXk017275@sheep.berlios.de> <48BC395E.1020007@gmx.de> <48BC3F7A.2090100@gmx.de> Message-ID: <894b9700809020135p420ebc71q6207d7f238a1bcee@mail.gmail.com> 2008/9/1 Rene Gollent : > On Mon, Sep 1, 2008 at 2:16 PM, julun wrote: >> If this class makes it into the official API, it clearly needs to be >> stated in the documentation. If someone is willing to point me to 'How >> to write Haiku docs' I'm going to document it. > > Sounds like a nice addition to the support kit to me :) > Indeed. From teammaui at web.de Tue Sep 2 10:38:46 2008 From: teammaui at web.de (Ralf Schuelke) Date: Tue, 02 Sep 2008 10:38:46 +0200 Subject: [Haiku-commits] r27264 - in haiku/trunk: headers/private/shared src/kits/shared In-Reply-To: <894b9700809020135p420ebc71q6207d7f238a1bcee@mail.gmail.com> References: <200809011311.m81DBUXk017275@sheep.berlios.de> <48BC395E.1020007@gmx.de> <48BC3F7A.2090100@gmx.de> <894b9700809020135p420ebc71q6207d7f238a1bcee@mail.gmail.com> Message-ID: <20080902103846.6942.2@2006.Belkin> On 2008-09-02 at 10:35:06 [+0200], Stefano Ceccherini wrote: > 2008/9/1 Rene Gollent : > > On Mon, Sep 1, 2008 at 2:16 PM, julun wrote: > >> If this class makes it into the official API, it clearly needs to be > >> stated in the documentation. If someone is willing to point me to 'How > >> to write Haiku docs' I'm going to document it. > > > > Sounds like a nice addition to the support kit to me :) > > > > Indeed. +1 -- Ralf Sch?lke aka Stargater From marcusoverhagen at arcor.de Tue Sep 2 11:31:53 2008 From: marcusoverhagen at arcor.de (Marcus Overhagen) Date: Tue, 2 Sep 2008 11:31:53 +0200 (CEST) Subject: [Haiku-commits] r27281 - haiku/trunk/src/add-ons/kernel/bus_managers/ata In-Reply-To: <20080902001807.1741.9@knochen-vm.localdomain> References: <20080902001807.1741.9@knochen-vm.localdomain> <200809012125.m81LPjHf000639@sheep.berlios.de> Message-ID: <10849682.1220347913607.JavaMail.ngmail@webmail17.arcor-online.net> Ingo Weinhold wrote: > You don't have any spacing between the last three outputs. Yes, I think you are correct. > Besides, it is really possible to print all that in a single out.Print() call. I see. printf semantics. > > + char fInfo[200]; > > To save tracing buffer sapce, it is advisable to allocate space for > variable-length strings dynamically via: > > char* alloc_tracing_buffer_strcpy(const char* source, size_t maxSize, > bool user); How is that supposed to be used and freed? And can it be used inside interrupt handler? What I really need for the ata stack is a simple string tracing function with C binding, all the C++ framework is overhead in this case. I thought I implemented it in a nice way, using var-arg macros, but I still have no idea why it fails to trace anything. regards Marcus advert: Jetzt komfortabel bei Arcor-Digital TV einsteigen: Mehr Happy Ends, mehr Herzschmerz, mehr Fernsehen! Erleben Sie 50 digitale TV Programme und optional 60 Pay TV Sender, einen elektronischen Programmf?hrer mit Movie Star Bewertungen von TV Movie. Au?erdem, aktuelle Filmhits und spannende Dokus in der Arcor-Videothek. Infos unter www.arcor.de/tv From alex at zappotek.com Tue Sep 2 12:14:23 2008 From: alex at zappotek.com (Alexandre Deckner) Date: Tue, 02 Sep 2008 12:14:23 +0200 Subject: [Haiku-commits] r27283 - haiku/trunk/src/apps/deskbar In-Reply-To: <20080902081917.257230@gmx.net> References: <200809020220.m822KEnm027946@sheep.berlios.de> <20080902081917.257230@gmx.net> Message-ID: <48BD11FF.6090903@zappotek.com> Stephan Assmus wrote: > > > This is a common source for memory leaks. The BMessageRunner constructor takes a "const BMessage*" to indicate that the message will be copied. So correct would be: > Oh, sure, i always check the doc about that, but forgot eventually, will fix that in a bit. (got to fix PairsWindow.cpp then :)) Regards, Alex From stippi at mail.berlios.de Tue Sep 2 12:56:14 2008 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Tue, 2 Sep 2008 12:56:14 +0200 Subject: [Haiku-commits] r27284 - haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests Message-ID: <200809021056.m82AuE6Q005376@sheep.berlios.de> Author: stippi Date: 2008-09-02 12:56:14 +0200 (Tue, 02 Sep 2008) New Revision: 27284 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27284&view=rev Modified: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/MenuBarTest.cpp haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/MenuBarTest.h Log: Added test for adding a BMenu instead of a BMenuItem, but everything works fine, at least in the context of the layout management. I am investigating a bug though that shows at least in WonderBrush (missing Filter menu). Modified: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/MenuBarTest.cpp =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/MenuBarTest.cpp 2008-09-02 02:20:12 UTC (rev 27283) +++ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/MenuBarTest.cpp 2008-09-02 10:56:14 UTC (rev 27284) @@ -14,6 +14,7 @@ enum { MSG_THIRD_ITEM = '3rdi', + MSG_CHILD_MENU = 'chmn', MSG_CHANGE_ITEM_TEXT = 'chit' }; @@ -29,6 +30,7 @@ fMenuBar->AddItem(fFirstItem = new BMenuItem("Menu item 1", NULL)); fMenuBar->AddItem(new BMenuItem("Menu item 2", NULL)); fThirdItem = new BMenuItem("Menu item 3", NULL); + fChildMenu = new BMenu("Child menu"); } @@ -53,6 +55,11 @@ new BMessage(MSG_THIRD_ITEM), this); group->AddChild(fThirdItemCheckBox); + // child menu + fChildMenuCheckBox = new LabeledCheckBox("Child menu", + new BMessage(MSG_CHILD_MENU), this); + group->AddChild(fChildMenuCheckBox); + // long text fLongTextCheckBox = new LabeledCheckBox("Long label text", new BMessage(MSG_CHANGE_ITEM_TEXT), this); @@ -80,6 +87,9 @@ case MSG_THIRD_ITEM: UpdateThirdItem(); break; + case MSG_CHILD_MENU: + UpdateChildMenu(); + break; case MSG_CHANGE_ITEM_TEXT: UpdateLongText(); break; @@ -107,6 +117,23 @@ } +// UpdateChildMenu +void +MenuBarTest::UpdateChildMenu() +{ + if (!fChildMenuCheckBox || !fMenuBar) + return; + + if (fChildMenuCheckBox->IsSelected() == (fChildMenu->Supermenu() != NULL)) + return; + + if (fChildMenuCheckBox->IsSelected()) + fMenuBar->AddItem(fChildMenu); + else + fMenuBar->RemoveItem(fChildMenu); +} + + // UpdateLongText void MenuBarTest::UpdateLongText() Modified: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/MenuBarTest.h =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/MenuBarTest.h 2008-09-02 02:20:12 UTC (rev 27283) +++ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/MenuBarTest.h 2008-09-02 10:56:14 UTC (rev 27284) @@ -9,6 +9,7 @@ #include "Test.h" +class BMenu; class BMenuBar; class BMenuItem; class LabeledCheckBox; @@ -27,13 +28,16 @@ private: void UpdateThirdItem(); + void UpdateChildMenu(); void UpdateLongText(); private: BMenuBar* fMenuBar; BMenuItem* fFirstItem; BMenuItem* fThirdItem; + BMenu* fChildMenu; LabeledCheckBox* fThirdItemCheckBox; + LabeledCheckBox* fChildMenuCheckBox; LabeledCheckBox* fLongTextCheckBox; }; From aldeck at mail.berlios.de Tue Sep 2 13:02:30 2008 From: aldeck at mail.berlios.de (aldeck at BerliOS) Date: Tue, 2 Sep 2008 13:02:30 +0200 Subject: [Haiku-commits] r27285 - in haiku/trunk/src/apps: deskbar pairs Message-ID: <200809021102.m82B2UYn013215@sheep.berlios.de> Author: aldeck Date: 2008-09-02 13:02:29 +0200 (Tue, 02 Sep 2008) New Revision: 27285 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27285&view=rev Modified: haiku/trunk/src/apps/deskbar/TimeView.cpp haiku/trunk/src/apps/pairs/PairsWindow.cpp Log: - Don't leak the message given to BMessageRunner, thanks stippi! Modified: haiku/trunk/src/apps/deskbar/TimeView.cpp =================================================================== --- haiku/trunk/src/apps/deskbar/TimeView.cpp 2008-09-02 10:56:14 UTC (rev 27284) +++ haiku/trunk/src/apps/deskbar/TimeView.cpp 2008-09-02 11:02:29 UTC (rev 27285) @@ -376,8 +376,8 @@ ShowClockOptions(ConvertToScreen(point)); return; } else if (buttons == B_PRIMARY_MOUSE_BUTTON) { - BMessage * longClickMessage = new BMessage(kMsgLongClick); - longClickMessage->AddPoint("where", point); + BMessage longClickMessage(kMsgLongClick); + longClickMessage.AddPoint("where", point); bigtime_t longClickThreshold; get_click_speed(&longClickThreshold); @@ -385,7 +385,7 @@ delete fLongClickMessageRunner; fLongClickMessageRunner = new BMessageRunner(BMessenger(this), - longClickMessage, longClickThreshold, 1); + &longClickMessage, longClickThreshold, 1); } // flip to/from showing date or time Modified: haiku/trunk/src/apps/pairs/PairsWindow.cpp =================================================================== --- haiku/trunk/src/apps/pairs/PairsWindow.cpp 2008-09-02 10:56:14 UTC (rev 27284) +++ haiku/trunk/src/apps/pairs/PairsWindow.cpp 2008-09-02 11:02:29 UTC (rev 27285) @@ -79,8 +79,9 @@ // message of message runner might not have arrived // yet, so it is deleted here to prevent any leaking // just in case + BMessage message(kMsgPairComparing); fPairComparing = new BMessageRunner(BMessenger(this), - new BMessage(kMsgPairComparing), 5 * 100000L, 1); + &message, 5 * 100000L, 1); fIsPairsActive = false; } From stippi at mail.berlios.de Tue Sep 2 13:06:41 2008 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Tue, 2 Sep 2008 13:06:41 +0200 Subject: [Haiku-commits] r27286 - haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests Message-ID: <200809021106.m82B6flT017867@sheep.berlios.de> Author: stippi Date: 2008-09-02 13:06:40 +0200 (Tue, 02 Sep 2008) New Revision: 27286 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27286&view=rev Added: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/TODO Log: Listed classes that need tests yet. Added: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/TODO =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/TODO 2008-09-02 11:02:29 UTC (rev 27285) +++ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/TODO 2008-09-02 11:06:40 UTC (rev 27286) @@ -0,0 +1,9 @@ +ChannelSlider +OptionPopup (covered by MenuField ?) +RadioButton +ScrollBar +ScrollView +StringView +TabView +TextControl +TextView From stippi at mail.berlios.de Tue Sep 2 13:28:33 2008 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Tue, 2 Sep 2008 13:28:33 +0200 Subject: [Haiku-commits] r27287 - haiku/trunk/headers/os/interface Message-ID: <200809021128.m82BSXV8028934@sheep.berlios.de> Author: stippi Date: 2008-09-02 13:28:32 +0200 (Tue, 02 Sep 2008) New Revision: 27287 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27287&view=rev Modified: haiku/trunk/headers/os/interface/ChannelControl.h Log: Rewrote ChannelControl.h Modified: haiku/trunk/headers/os/interface/ChannelControl.h =================================================================== --- haiku/trunk/headers/os/interface/ChannelControl.h 2008-09-02 11:06:40 UTC (rev 27286) +++ haiku/trunk/headers/os/interface/ChannelControl.h 2008-09-02 11:28:32 UTC (rev 27287) @@ -1,221 +1,171 @@ -/******************************************************************************* -/ -/ File: ChannelControl.h -/ -/ Description: BChannelControl is the base class for controls that -/ have several independent values, with minima and maxima. -/ -/ Copyright 1998-99, Be Incorporated, All Rights Reserved -/ -*******************************************************************************/ - -#if !defined(_CHANNEL_CONTROL_H) +/* + * Copyright (C) 2008 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT/X11 license. + */ +#ifndef _CHANNEL_CONTROL_H #define _CHANNEL_CONTROL_H +//! BChannelControl is the base class for controls that have several +// independent values, with minima and maxima. + #include #include -class BChannelControl : - public BControl -{ +class BChannelControl : public BControl { public: - BChannelControl( - BRect frame, - const char * name, - const char * label, - BMessage * model, - int32 channel_count = 1, - uint32 resize = B_FOLLOW_LEFT | B_FOLLOW_TOP, - uint32 flags = B_WILL_DRAW); - BChannelControl( - BMessage * from); -virtual ~BChannelControl(); -virtual status_t Archive( - BMessage * into, - bool deep = true) const; + BChannelControl(BRect frame, const char* name, + const char* label, BMessage* model, + int32 channelCount = 1, + uint32 resizeFlags + = B_FOLLOW_LEFT | B_FOLLOW_TOP, + uint32 viewFlags = B_WILL_DRAW); + BChannelControl(BMessage* archive); + virtual ~BChannelControl(); -virtual void Draw( - BRect area) = 0; -virtual void MouseDown( - BPoint where) = 0; -virtual void KeyDown( - const char * bytes, - int32 size) = 0; + virtual status_t Archive(BMessage* into, bool deep = true) const; -virtual void FrameResized( - float width, - float height); -virtual void SetFont( - const BFont * font, + virtual void Draw(BRect updateRect) = 0; + virtual void MouseDown(BPoint where) = 0; + virtual void KeyDown(const char* bytes, int32 size) = 0; + + virtual void FrameResized(float width, float height); + virtual void SetFont(const BFont* font, uint32 mask = B_FONT_ALL); -virtual void AttachedToWindow(); -virtual void DetachedFromWindow(); -virtual void ResizeToPreferred(); -virtual void GetPreferredSize( - float * width, - float * height) = 0; -virtual void MessageReceived( - BMessage * message); + virtual void AttachedToWindow(); + virtual void DetachedFromWindow(); + virtual void ResizeToPreferred(); + virtual void GetPreferredSize(float* width, + float* height) = 0; -virtual BHandler *ResolveSpecifier(BMessage *msg, - int32 index, - BMessage *specifier, - int32 form, - const char *property); -virtual status_t GetSupportedSuites(BMessage *data); + virtual void MessageReceived(BMessage* message); -virtual void SetModificationMessage( - BMessage *message); - BMessage *ModificationMessage() const; + virtual BHandler* ResolveSpecifier(BMessage* message, int32 index, + BMessage* specifier, int32 form, + const char* property); + virtual status_t GetSupportedSuites(BMessage* data); + + virtual void SetModificationMessage(BMessage* message); + BMessage* ModificationMessage() const; -virtual status_t Invoke(BMessage *msg = NULL); + virtual status_t Invoke(BMessage* withMessage = NULL); -// Perform a full-fledged channel invocation. These methods are -// just like Invoke() and InvokeNotify(), but include information -// about all of the channels in the control. -virtual status_t InvokeChannel(BMessage *msg = NULL, - int32 from_channel = 0, - int32 channel_count = -1, - const bool* in_mask = NULL); - status_t InvokeNotifyChannel(BMessage *msg = NULL, - uint32 kind = B_CONTROL_INVOKED, - int32 from_channel = 0, - int32 channel_count = -1, - const bool* in_mask = NULL); + //! These methods are similar to Invoke() Invoke() and InvokeNotify(), but + // include additional information about all of the channels in the control. + virtual status_t InvokeChannel(BMessage* message = NULL, + int32 fromChannel = 0, + int32 channelCount = -1, + const bool* _mask = NULL); + status_t InvokeNotifyChannel(BMessage* message = NULL, + uint32 kind = B_CONTROL_INVOKED, + int32 fromChannel = 0, + int32 channelCount = -1, + const bool* _mask = NULL); -virtual void SetValue( /* SetCurrentChannel() determines which channel */ - int32 value); -virtual status_t SetCurrentChannel( - int32 channel); - int32 CurrentChannel() const; + virtual void SetValue(int32 value); + // SetCurrentChannel() determines which channel + virtual status_t SetCurrentChannel(int32 index); + int32 CurrentChannel() const; -virtual int32 CountChannels() const; -virtual int32 MaxChannelCount() const = 0; -virtual status_t SetChannelCount( - int32 channel_count); - int32 ValueFor( - int32 channel) const; -virtual int32 GetValue( - int32 * out_values, - int32 from_channel, - int32 channel_count) const; - status_t SetValueFor( - int32 channel, - int32 value); -virtual status_t SetValue( - int32 from_channel, - int32 channel_count, - const int32 * in_values); - status_t SetAllValue( - int32 values); - status_t SetLimitsFor( - int32 channel, - int32 minimum, + virtual int32 CountChannels() const; + virtual int32 MaxChannelCount() const = 0; + virtual status_t SetChannelCount(int32 count); + int32 ValueFor(int32 channel) const; + virtual int32 GetValue(int32* _values, int32 fromChannel, + int32 channelCount) const; + status_t SetValueFor(int32 channel, int32 value); + virtual status_t SetValue(int32 fromChannel, int32 channelCount, + const int32* values); + status_t SetAllValue(int32 values); + status_t SetLimitsFor(int32 channel, int32 minimum, int32 maximum); - status_t GetLimitsFor( - int32 channel, - int32 * minimum, - int32 * maximum) const ; -virtual status_t SetLimitsFor( - int32 from_channel, - int32 channel_count, - const int32 * minimum, - const int32 * maximum); -virtual status_t GetLimitsFor( - int32 from_channel, - int32 channel_count, - int32 * minimum, - int32 * maximum) const; - status_t SetLimits( - int32 minimum, - int32 maximum); - status_t GetLimits( - int32 * outMinimum, - int32 * outMaximum) const; + status_t GetLimitsFor(int32 channel, int32* _minimum, + int32* _maximum) const ; + virtual status_t SetLimitsFor(int32 fromChannel, + int32 channelCount, const int32* minima, + const int32* maxima); + virtual status_t GetLimitsFor(int32 fromChannel, + int32 channelCount, int32* minima, + int32* maxima) const; + status_t SetLimits(int32 minimum, int32 maximum); + status_t GetLimits(int32* _minimum, + int32* _maximum) const; -virtual bool SupportsIndividualLimits() const = 0; -virtual status_t SetLimitLabels( - const char * min_label, - const char * max_label); - const char * MinLimitLabel() const; - const char * MaxLimitLabel() const; -virtual status_t SetLimitLabelsFor( - int32 channel, - const char * minLabel, - const char * maxLabel); -virtual status_t SetLimitLabelsFor( - int32 from_channel, - int32 channel_count, - const char * minLabel, - const char * maxLabel); - const char * MinLimitLabelFor( - int32 channel) const; - const char * MaxLimitLabelFor( - int32 channel) const; + virtual bool SupportsIndividualLimits() const = 0; + virtual status_t SetLimitLabels(const char* minLabel, + const char* maxLabel); + const char* MinLimitLabel() const; + const char* MaxLimitLabel() const; + virtual status_t SetLimitLabelsFor(int32 channel, + const char* minLabel, const char* maxLabel); + virtual status_t SetLimitLabelsFor(int32 fromChannel, + int32 channelCount, const char* minLabel, + const char* maxLabel); + const char* MinLimitLabelFor(int32 channel) const; + const char* MaxLimitLabelFor(int32 channel) const; private: + // Forbidden (and unimplemented) + BChannelControl(const BChannelControl& other); + BChannelControl& operator=(const BChannelControl& other); - BChannelControl( /* unimplemented */ - const BChannelControl &); - BChannelControl & operator=( /* unimplemented */ - const BChannelControl &); -virtual void _Reserverd_ChannelControl_0(void *, ...); -virtual void _Reserverd_ChannelControl_1(void *, ...); -virtual void _Reserverd_ChannelControl_2(void *, ...); -virtual void _Reserverd_ChannelControl_3(void *, ...); -virtual void _Reserverd_ChannelControl_4(void *, ...); -virtual void _Reserverd_ChannelControl_5(void *, ...); -virtual void _Reserverd_ChannelControl_6(void *, ...); -virtual void _Reserverd_ChannelControl_7(void *, ...); -virtual void _Reserverd_ChannelControl_8(void *, ...); -virtual void _Reserverd_ChannelControl_9(void *, ...); -virtual void _Reserverd_ChannelControl_10(void *, ...); -virtual void _Reserverd_ChannelControl_11(void *, ...); + virtual void _Reserverd_ChannelControl_0(void *, ...); + virtual void _Reserverd_ChannelControl_1(void *, ...); + virtual void _Reserverd_ChannelControl_2(void *, ...); + virtual void _Reserverd_ChannelControl_3(void *, ...); + virtual void _Reserverd_ChannelControl_4(void *, ...); + virtual void _Reserverd_ChannelControl_5(void *, ...); + virtual void _Reserverd_ChannelControl_6(void *, ...); + virtual void _Reserverd_ChannelControl_7(void *, ...); + virtual void _Reserverd_ChannelControl_8(void *, ...); + virtual void _Reserverd_ChannelControl_9(void *, ...); + virtual void _Reserverd_ChannelControl_10(void *, ...); + virtual void _Reserverd_ChannelControl_11(void *, ...); protected: + inline int32* const& MinLimitList() const; + inline int32* const& MaxLimitList() const; + inline int32* const& ValueList() const; - inline int32 * const & MinLimitList() const; - inline int32 * const & MaxLimitList() const; - inline int32 * const & ValueList() const; - private: + int32 fChannelCount; + int32 fCurrentChannel; + int32* fChannelMin; + int32* fChannelMax; + int32* fChannelValues; - int32 fChannelCount; - int32 fCurrentChannel; - int32 * fChannelMin; - int32 * fChannelMax; - int32 * fChannelValues; - - BString fMinLabel; - BString fMaxLabel; - - void * fMultiLabels; - - BMessage * fModificationMsg; - - uint32 _reserved_[15]; + BString fMinLabel; + BString fMaxLabel; - status_t StuffValues( - int32 from_channel, - int32 channel_count, - const int32 * in_values); + void* fMultiLabels; + + BMessage* fModificationMsg; + + uint32 _reserved_[15]; + + status_t StuffValues(int32 fromChannel, + int32 channelCount, const int32* values); }; -inline int32 * const & BChannelControl::MinLimitList() const + +inline int32* const& +BChannelControl::MinLimitList() const { return fChannelMin; } -inline int32 * const & BChannelControl::MaxLimitList() const + +inline int32* const& +BChannelControl::MaxLimitList() const { return fChannelMax; } -inline int32 * const & BChannelControl::ValueList() const + +inline int32* const& +BChannelControl::ValueList() const { return fChannelValues; } -#endif /* _CHANNEL_CONTROL_H */ - +#endif // _CHANNEL_CONTROL_H From teammaui at web.de Tue Sep 2 13:28:49 2008 From: teammaui at web.de (=?utf-8?Q?Ralf_Sch=C3=BClke?=) Date: Tue, 02 Sep 2008 13:28:49 +0200 Subject: [Haiku-commits] r27285 - in haiku/trunk/src/apps: deskbar pairs In-Reply-To: <200809021102.m82B2UYn013215@sheep.berlios.de> References: <200809021102.m82B2UYn013215@sheep.berlios.de> Message-ID: On Tue, 02 Sep 2008 13:02:30 +0200, aldeck at BerliOS wrote: > +++ haiku/trunk/src/apps/pairs/PairsWindow.cpp 2008-09-02 11:02:29 UTC > (rev 27285) > @@ -79,8 +79,9 @@ > // message of message runner might not have arrived > // yet, so it is deleted here to prevent any leaking > // just in case > + BMessage message(kMsgPairComparing); > fPairComparing = new BMessageRunner(BMessenger(this), > - new BMessage(kMsgPairComparing), 5 * 100000L, 1); > + &message, 5 * 100000L, 1); > fIsPairsActive = false; > } Hi, thank you :-) -- Ralf Sch?lke aka stargater From ingo_weinhold at gmx.de Tue Sep 2 13:36:38 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Tue, 02 Sep 2008 13:36:38 +0200 Subject: [Haiku-commits] r27282 - haiku/trunk/src/add-ons/kernel/bus_managers/ata In-Reply-To: <32567841.1220340953394.JavaMail.ngmail@webmail17.arcor-online. net> References: <20080902002006.1814.10@knochen-vm.localdomain> <200809012126.m81LQlLL001307@sheep.berlios.de> <32567841.1220340953394.JavaMail.ngmail@webmail17.arcor-online.net> Message-ID: <20080902133638.566.1@knochen-vm.localdomain> On 2008-09-02 at 09:35:53 [+0200], Marcus Overhagen wrote: > Ingo Weinhold schrieb: > > > > Use kernel tracing feature. Doesn't seem to work, don't know why. > > > > From a look at the patches, it looks OK. I suppose you haven't just > > forgotten to actually enable it? :-P > > I'm pretty sure I enabled it, because I had to fix some errors > before the code between the #ifdef would compile. > > The output looks like this: http://pastebin.com/m96b8f28 / > http://nopaste.org/p/aziDmES2d > Lots of empty lines. > > I don't know whats wrong. if you have any idea, feel free to fix it. Ah, I see it now: ATATraceEntry::AddDump() has the wrong signature. The second parameter is bogus. Hence the method is never called and there's no output. CU, Ingo From ingo_weinhold at gmx.de Tue Sep 2 14:01:17 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Tue, 02 Sep 2008 14:01:17 +0200 Subject: [Haiku-commits] r27281 - haiku/trunk/src/add-ons/kernel/bus_managers/ata In-Reply-To: <10849682.1220347913607.JavaMail.ngmail@webmail17.arcor-online. net> References: <20080902001807.1741.9@knochen-vm.localdomain> <200809012125.m81LPjHf000639@sheep.berlios.de> <10849682.1220347913607.JavaMail.ngmail@webmail17.arcor-online.net> Message-ID: <20080902140117.596.2@knochen-vm.localdomain> On 2008-09-02 at 11:31:53 [+0200], Marcus Overhagen wrote: > Ingo Weinhold wrote: > > > + char fInfo[200]; > > > > To save tracing buffer sapce, it is advisable to allocate space for > > variable-length strings dynamically via: > > > > char* alloc_tracing_buffer_strcpy(const char* source, size_t maxSize, > > bool user); > How is that supposed to be used and freed? The function allocates space in the global tracing buffer, enough to copy the "source" string into it, maximally "maxSize" bytes though. So the function is basically a strdup() with size limit. "user" indicates whether "source" is a buffer from userland -- if true, user_strlcpy() is used to copy the string. There's no restriction in how the returned buffer can be used. It is freed automatically after the trace entry is freed (i.e. when the global tracing buffer (a ring buffer) is full). > And can it be used inside > interrupt handler? Absolutely. > What I really need for the ata stack is a simple string tracing function > with C binding, all the C++ framework is overhead in this case. There's a ktrace_printf() function with standard printf() semantics, which you could use. The semaphore code does, too, though that was mainly laziness on my part. Creating C++ tracing entry classes has a few advantages: The tracing is faster (copying a few values vs. snprintf()), the entries take less space in the tracing buffer than formatted text, and they could be used for later analysis (like done by the "scheduler" command). If you only want to print random text, ktrace_printf() is probably the best choice. CU, Ingo From ingo_weinhold at gmx.de Tue Sep 2 14:10:10 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Tue, 02 Sep 2008 14:10:10 +0200 Subject: [Haiku-commits] r27268 - haiku/trunk/src/system/kernel/posix In-Reply-To: References: <200809011616.m81GG3N6001985@sheep.berlios.de> <20080902004153.1928.11@knochen-vm.localdomain> Message-ID: <20080902141010.632.3@knochen-vm.localdomain> On 2008-09-02 at 10:28:14 [+0200], Salvatore Benedetto wrote: > 2008/9/2 Ingo Weinhold : > > On 2008-09-01 at 18:16:03 [+0200], sbenedetto at BerliOS > > wrote: [...] > >> As far as I can see from the mutex_destroy code, it looks safe to hold > >> the > >> lock > >> when calling this function. Please confirm. > > > > It is. Unless I miss something, it doesn't solve the problem, though. In > > semop() the semaphore set is unlocked while waiting for a semaphore. A > > IPC_RMID after unlocking would cause the semaphore->Wait() to access > > free()d > > memory. > > I just woke up so I shouldn't be answering :-) > In semop(), the set must be unlock before going to sleep otherwise it > would not work, thus > so far so good. Once waked up, Nope, earlier: semop() unlocks the semaphore set. If preempted right after that point, another thread can IPC_RMID the set and free() all associated memory. When the first thread continues and enters the semaphore->Wait() it will access freed memory. CU, Ingo From emitrax at gmail.com Tue Sep 2 14:25:43 2008 From: emitrax at gmail.com (Salvatore Benedetto) Date: Tue, 2 Sep 2008 14:25:43 +0200 Subject: [Haiku-commits] r27268 - haiku/trunk/src/system/kernel/posix In-Reply-To: <20080902141010.632.3@knochen-vm.localdomain> References: <200809011616.m81GG3N6001985@sheep.berlios.de> <20080902004153.1928.11@knochen-vm.localdomain> <20080902141010.632.3@knochen-vm.localdomain> Message-ID: 2008/9/2 Ingo Weinhold : > > On 2008-09-02 at 10:28:14 [+0200], Salvatore Benedetto > wrote: >> 2008/9/2 Ingo Weinhold : >> > On 2008-09-01 at 18:16:03 [+0200], sbenedetto at BerliOS >> > wrote: > [...] >> >> As far as I can see from the mutex_destroy code, it looks safe to hold >> >> the >> >> lock >> >> when calling this function. Please confirm. >> > >> > It is. Unless I miss something, it doesn't solve the problem, though. In >> > semop() the semaphore set is unlocked while waiting for a semaphore. A >> > IPC_RMID after unlocking would cause the semaphore->Wait() to access >> > free()d >> > memory. >> >> I just woke up so I shouldn't be answering :-) >> In semop(), the set must be unlock before going to sleep otherwise it >> would not work, thus >> so far so good. Once waked up, > > Nope, earlier: semop() unlocks the semaphore set. If preempted right after > that point, another thread can IPC_RMID the set and free() all associated > memory. When the first thread continues and enters the semaphore->Wait() it > will access freed memory. Oh I see. Ok, that is a problem (and it shows my lack of experience with multithreading design). I'll think about something later tonight or tomorrow morning, meanwhile, if you have a suggestion that does not involve reference count, or at least does not require any big change in the design of the locking system, thus the code, please let me know. Regards, -- Salvatore Benedetto (a.k.a. emitrax) Student of Computer Engineer University of Pisa www.haiku-os.it From ingo_weinhold at gmx.de Tue Sep 2 15:22:56 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Tue, 02 Sep 2008 15:22:56 +0200 Subject: [Haiku-commits] r27268 - haiku/trunk/src/system/kernel/posix In-Reply-To: References: <200809011616.m81GG3N6001985@sheep.berlios.de> <20080902004153.1928.11@knochen-vm.localdomain> <20080902141010.632.3@knochen-vm.localdomain> Message-ID: <20080902152256.728.4@knochen-vm.localdomain> On 2008-09-02 at 14:25:43 [+0200], Salvatore Benedetto wrote: > 2008/9/2 Ingo Weinhold : > > > > On 2008-09-02 at 10:28:14 [+0200], Salvatore Benedetto > > wrote: > >> 2008/9/2 Ingo Weinhold : > >> > On 2008-09-01 at 18:16:03 [+0200], sbenedetto at BerliOS > >> > wrote: > > [...] > >> >> As far as I can see from the mutex_destroy code, it looks safe to hold > >> >> the > >> >> lock > >> >> when calling this function. Please confirm. > >> > > >> > It is. Unless I miss something, it doesn't solve the problem, though. > >> > In > >> > semop() the semaphore set is unlocked while waiting for a semaphore. A > >> > IPC_RMID after unlocking would cause the semaphore->Wait() to access > >> > free()d > >> > memory. > >> > >> I just woke up so I shouldn't be answering :-) > >> In semop(), the set must be unlock before going to sleep otherwise it > >> would not work, thus > >> so far so good. Once waked up, > > > > Nope, earlier: semop() unlocks the semaphore set. If preempted right after > > that point, another thread can IPC_RMID the set and free() all associated > > memory. When the first thread continues and enters the semaphore->Wait() > > it > > will access freed memory. > > Oh I see. > Ok, that is a problem (and it shows my lack of experience with > multithreading design). > I'll think about something later tonight or tomorrow morning, > meanwhile, if you have > a suggestion that does not involve reference count, or at least does > not require any > big change in the design of the locking system, thus the code, please > let me know. Actually the Wait() problem is even more general. It operates on members without any lock. Even two concurrent semop()s could screw things up. Also there's a good reason why threads block in two steps, thread_prepare_to_block() and thread_block(). The former is usually called while still holding a lock that the one unblocking the thread has to hold, too. This avoids race conditions of the kind that the thread_unblock() is called before thread_prepare_to_block(), thus not waking the thread up. As for the solution: Call Wait() with the set locked and pass it the respective MutexLocker. Unlock after thread_prepare_to_block(). Re-lock after returning from thread_block_locked() using the full procedure (hash lock, lookup, lock, hash unlock). That's a bit ugly since Wait() needs additional information to do that. Regarding re-locking. It must be ensured that it's still the same semaphore set. Someone could have IPC_RMID the set and added a new one with the same ID. I.e. the semaphore set pointers must be the same and a global counter should be introduced (incremented whenever semget() adds a set to the hash table, and the value stored in the set). CU, Ingo From emitrax at gmail.com Tue Sep 2 16:46:29 2008 From: emitrax at gmail.com (Salvatore Benedetto) Date: Tue, 2 Sep 2008 16:46:29 +0200 Subject: [Haiku-commits] r27268 - haiku/trunk/src/system/kernel/posix In-Reply-To: <20080902152256.728.4@knochen-vm.localdomain> References: <200809011616.m81GG3N6001985@sheep.berlios.de> <20080902004153.1928.11@knochen-vm.localdomain> <20080902141010.632.3@knochen-vm.localdomain> <20080902152256.728.4@knochen-vm.localdomain> Message-ID: 2008/9/2 Ingo Weinhold : > Actually the Wait() problem is even more general. It operates on members > without any lock. Even two concurrent semop()s could screw things up. Also > there's a good reason why threads block in two steps, > thread_prepare_to_block() and thread_block(). The former is usually called > while still holding a lock that the one unblocking the thread has to hold, > too. This avoids race conditions of the kind that the thread_unblock() is > called before thread_prepare_to_block(), thus not waking the thread up. > > As for the solution: Call Wait() with the set locked and pass it the > respective MutexLocker. Unlock after thread_prepare_to_block(). Re-lock after > returning from thread_block_locked() using the full procedure (hash lock, > lookup, lock, hash unlock). That's a bit ugly since Wait() needs additional > information to do that. I actually thought about that too, but with the only difference to unlock right before calling thread_block_locked, thus after disabling interrupts. This should make sure that the two operations, unlocking and blocking, happens atomically (under the assumption that I can can Unlock with interrupts disabled), because my doubts is what happens if I got preempted right after I called thread_prepare_to_block(); Unlock(); ? Wouldn't the thread sleep theorically forever if it calls thread_block_locked() after the set has been deleted? Anyway, in order not to mess even more the Wait() function I was thinking about just removing it. Regards, -- Salvatore Benedetto (a.k.a. emitrax) Student of Computer Engineer University of Pisa www.haiku-os.it From laplace at mail.berlios.de Tue Sep 2 18:40:24 2008 From: laplace at mail.berlios.de (laplace at mail.berlios.de) Date: Tue, 2 Sep 2008 18:40:24 +0200 Subject: [Haiku-commits] r27288 - haiku/trunk/src/apps/deskbar Message-ID: <200809021640.m82GeOe5005344@sheep.berlios.de> Author: laplace Date: 2008-09-02 18:40:22 +0200 (Tue, 02 Sep 2008) New Revision: 27288 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27288&view=rev Modified: haiku/trunk/src/apps/deskbar/TimeView.cpp haiku/trunk/src/apps/deskbar/TimeView.h Log: * Delete longClickMessageRunner in destructor to avoid potential memory leak. * Delete longClickMessageRunner after its message arrived, to shorten its lifetime. * Moved creation and deletion of longClickMessageRunner into methods. Modified: haiku/trunk/src/apps/deskbar/TimeView.cpp =================================================================== --- haiku/trunk/src/apps/deskbar/TimeView.cpp 2008-09-02 11:28:32 UTC (rev 27287) +++ haiku/trunk/src/apps/deskbar/TimeView.cpp 2008-09-02 16:40:22 UTC (rev 27288) @@ -114,6 +114,7 @@ TTimeView::~TTimeView() { + StopLongClickNotifier(); } @@ -237,6 +238,7 @@ case kMsgLongClick: { + StopLongClickNotifier(); BPoint where; message->FindPoint("where", &where); ShowCalendar(where); @@ -299,6 +301,31 @@ void +TTimeView::StartLongClickNotifier(BPoint where) +{ + StopLongClickNotifier(); + + BMessage longClickMessage(kMsgLongClick); + longClickMessage.AddPoint("where", where); + + bigtime_t longClickThreshold; + get_click_speed(&longClickThreshold); + // use the doubleClickSpeed as a threshold + + fLongClickMessageRunner = new BMessageRunner(BMessenger(this), + &longClickMessage, longClickThreshold, 1); +} + + +void +TTimeView::StopLongClickNotifier() +{ + delete fLongClickMessageRunner; + fLongClickMessageRunner = NULL; +} + + +void TTimeView::GetCurrentTime() { char tmp[64]; @@ -376,16 +403,7 @@ ShowClockOptions(ConvertToScreen(point)); return; } else if (buttons == B_PRIMARY_MOUSE_BUTTON) { - BMessage longClickMessage(kMsgLongClick); - longClickMessage.AddPoint("where", point); - - bigtime_t longClickThreshold; - get_click_speed(&longClickThreshold); - // use the doubleClickSpeed as a threshold - - delete fLongClickMessageRunner; - fLongClickMessageRunner = new BMessageRunner(BMessenger(this), - &longClickMessage, longClickThreshold, 1); + StartLongClickNotifier(point); } // flip to/from showing date or time @@ -404,8 +422,7 @@ void TTimeView::MouseUp(BPoint point) { - delete fLongClickMessageRunner; - fLongClickMessageRunner = NULL; + StopLongClickNotifier(); } Modified: haiku/trunk/src/apps/deskbar/TimeView.h =================================================================== --- haiku/trunk/src/apps/deskbar/TimeView.h 2008-09-02 11:28:32 UTC (rev 27287) +++ haiku/trunk/src/apps/deskbar/TimeView.h 2008-09-02 16:40:22 UTC (rev 27288) @@ -83,6 +83,8 @@ bool ShowingEuroDate() {return fEuroDate; } void ShowEuroDate(bool); void ShowCalendar(BPoint where); + void StartLongClickNotifier(BPoint where); + void StopLongClickNotifier(); bool Orientation() const; void SetOrientation(bool o); From marcusoverhagen at mail.berlios.de Tue Sep 2 22:04:27 2008 From: marcusoverhagen at mail.berlios.de (marcusoverhagen at BerliOS) Date: Tue, 2 Sep 2008 22:04:27 +0200 Subject: [Haiku-commits] r27289 - haiku/trunk/src/add-ons/kernel/bus_managers/ata Message-ID: <200809022004.m82K4RlZ004610@sheep.berlios.de> Author: marcusoverhagen Date: 2008-09-02 22:04:27 +0200 (Tue, 02 Sep 2008) New Revision: 27289 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27289&view=rev Modified: haiku/trunk/src/add-ons/kernel/bus_managers/ata/ata_tracing.cpp Log: Fix tracing and improve memory usage. Thanks to Ingo for his hints. Modified: haiku/trunk/src/add-ons/kernel/bus_managers/ata/ata_tracing.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/ata/ata_tracing.cpp 2008-09-02 16:40:22 UTC (rev 27288) +++ haiku/trunk/src/add-ons/kernel/bus_managers/ata/ata_tracing.cpp 2008-09-02 20:04:27 UTC (rev 27289) @@ -1,3 +1,7 @@ +/* + * Copyright 2008, Marcus Overhagen. All rights reserved. + * Distributed under the terms of the MIT License. + */ #include #include @@ -11,30 +15,26 @@ ATATraceEntry(int bus, int device, const char *info) : fBus(bus) , fDevice(device) + , fInfo(alloc_tracing_buffer_strcpy(info, 666, false)) { - strlcpy(fInfo, info, sizeof(fInfo)); Initialized(); } - void AddDump(TraceOutput& out, const char* name) + void AddDump(TraceOutput& out) { - out.Print("ata"); - out.Print(" - %s - ", name); - out.Print("bus %d", fBus); - out.Print("device %d", fDevice); - out.Print("%s", fInfo); + out.Print("ata %d:%d %s", fBus, fDevice, fInfo); } int fBus; int fDevice; - char fInfo[200]; + char *fInfo; }; extern "C" void __ata_trace_device(ide_device_info *dev, const char *fmt, ...) { - char info[200]; + char info[120]; va_list ap; va_start(ap, fmt); @@ -48,7 +48,7 @@ extern "C" void __ata_trace_bus_device(ide_bus_info *bus, int dev, const char *fmt, ...) { - char info[200]; + char info[120]; va_list ap; va_start(ap, fmt); From colacoder at mail.berlios.de Wed Sep 3 00:19:59 2008 From: colacoder at mail.berlios.de (colacoder at mail.berlios.de) Date: Wed, 3 Sep 2008 00:19:59 +0200 Subject: [Haiku-commits] r27290 - in haiku/trunk/src/add-ons/kernel/drivers/network: . attansic_l2 attansic_l2/dev attansic_l2/dev/ae attansic_l2/dev/mii Message-ID: <200809022219.m82MJxnp024240@sheep.berlios.de> Author: colacoder Date: 2008-09-03 00:19:45 +0200 (Wed, 03 Sep 2008) New Revision: 27290 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27290&view=rev Added: haiku/trunk/src/add-ons/kernel/drivers/network/attansic_l2/ haiku/trunk/src/add-ons/kernel/drivers/network/attansic_l2/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/attansic_l2/dev/ haiku/trunk/src/add-ons/kernel/drivers/network/attansic_l2/dev/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/attansic_l2/dev/ae/ haiku/trunk/src/add-ons/kernel/drivers/network/attansic_l2/dev/ae/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/attansic_l2/dev/ae/glue.c haiku/trunk/src/add-ons/kernel/drivers/network/attansic_l2/dev/ae/if_ae.c haiku/trunk/src/add-ons/kernel/drivers/network/attansic_l2/dev/ae/if_aereg.h haiku/trunk/src/add-ons/kernel/drivers/network/attansic_l2/dev/ae/if_aevar.h haiku/trunk/src/add-ons/kernel/drivers/network/attansic_l2/dev/mii/ haiku/trunk/src/add-ons/kernel/drivers/network/attansic_l2/dev/mii/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/attansic_l2/dev/mii/ukphy.c haiku/trunk/src/add-ons/kernel/drivers/network/attansic_l2/dev/mii/ukphy_subr.c Modified: haiku/trunk/src/add-ons/kernel/drivers/network/Jamfile Log: Attansic L2 Fast Ethernet driver for Haiku. Port of FreeBSD driver from: http://www.SpringDaemons.com/stas/if_ae-1214569185.tar.bz2 (This is the wired NIC on the Asus EEE PC!) NOTE: It is not in the image because it currently still crashes, will look into that soon. Modified: haiku/trunk/src/add-ons/kernel/drivers/network/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/Jamfile 2008-09-02 20:04:27 UTC (rev 27289) +++ haiku/trunk/src/add-ons/kernel/drivers/network/Jamfile 2008-09-02 22:19:45 UTC (rev 27290) @@ -20,6 +20,7 @@ SubInclude HAIKU_TOP src add-ons kernel drivers network nforce ; SubInclude HAIKU_TOP src add-ons kernel drivers network pcnet ; SubInclude HAIKU_TOP src add-ons kernel drivers network syskonnect ; +SubInclude HAIKU_TOP src add-ons kernel drivers network attansic_l2 ; SubIncludeGPL HAIKU_TOP src add-ons kernel drivers network bcm440x ; SubIncludeGPL HAIKU_TOP src add-ons kernel drivers network bcm570x ; Added: haiku/trunk/src/add-ons/kernel/drivers/network/attansic_l2/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/attansic_l2/Jamfile 2008-09-02 20:04:27 UTC (rev 27289) +++ haiku/trunk/src/add-ons/kernel/drivers/network/attansic_l2/Jamfile 2008-09-02 22:19:45 UTC (rev 27290) @@ -0,0 +1,3 @@ +SubDir HAIKU_TOP src add-ons kernel drivers network attansic_l2 ; + +SubInclude HAIKU_TOP src add-ons kernel drivers network attansic_l2 dev ; Added: haiku/trunk/src/add-ons/kernel/drivers/network/attansic_l2/dev/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/attansic_l2/dev/Jamfile 2008-09-02 20:04:27 UTC (rev 27289) +++ haiku/trunk/src/add-ons/kernel/drivers/network/attansic_l2/dev/Jamfile 2008-09-02 22:19:45 UTC (rev 27290) @@ -0,0 +1,5 @@ +SubDir HAIKU_TOP src add-ons kernel drivers network attansic_l2 dev ; + +SubInclude HAIKU_TOP src add-ons kernel drivers network attansic_l2 dev mii ; +SubInclude HAIKU_TOP src add-ons kernel drivers network attansic_l2 dev ae ; + Added: haiku/trunk/src/add-ons/kernel/drivers/network/attansic_l2/dev/ae/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/attansic_l2/dev/ae/Jamfile 2008-09-02 20:04:27 UTC (rev 27289) +++ haiku/trunk/src/add-ons/kernel/drivers/network/attansic_l2/dev/ae/Jamfile 2008-09-02 22:19:45 UTC (rev 27290) @@ -0,0 +1,14 @@ +SubDir HAIKU_TOP src add-ons kernel drivers network attansic_l2 dev ae ; + +UsePrivateHeaders kernel net ; + +UseHeaders [ FDirName $(SUBDIR) .. .. ] : true ; +UseHeaders [ FDirName $(HAIKU_TOP) src libs compat freebsd_network compat ] : true ; + +SubDirCcFlags [ FDefines _KERNEL=1 FBSD_DRIVER=1 ] ; + +KernelAddon attansic_l2 : + if_ae.c + glue.c + : libfreebsd_network.a attansic_l2_mii.a + ; Added: haiku/trunk/src/add-ons/kernel/drivers/network/attansic_l2/dev/ae/glue.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/attansic_l2/dev/ae/glue.c 2008-09-02 20:04:27 UTC (rev 27289) +++ haiku/trunk/src/add-ons/kernel/drivers/network/attansic_l2/dev/ae/glue.c 2008-09-02 22:19:45 UTC (rev 27290) @@ -0,0 +1,29 @@ +/* + * Copyright 2007, Hugo Santos. All Rights Reserved. + * Copyright 2007, Axel D?rfler, axeld at pinc-software.de. All Rights Reserved. + * Distributed under the terms of the MIT License. + */ + + +#include + + +HAIKU_FBSD_DRIVER_GLUE(attansic_l2, ae, pci) + +extern driver_t *DRIVER_MODULE_NAME(ukphy, miibus); + +driver_t * +__haiku_select_miibus_driver(device_t dev) +{ + driver_t *drivers[] = { + DRIVER_MODULE_NAME(ukphy, miibus), + NULL + }; + + return __haiku_probe_miibus(dev, drivers); +} + +NO_HAIKU_CHECK_DISABLE_INTERRUPTS(); +NO_HAIKU_REENABLE_INTERRUPTS(); + +HAIKU_DRIVER_REQUIREMENTS(FBSD_TASKQUEUES | FBSD_FAST_TASKQUEUE | FBSD_SWI_TASKQUEUE); Added: haiku/trunk/src/add-ons/kernel/drivers/network/attansic_l2/dev/ae/if_ae.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/attansic_l2/dev/ae/if_ae.c 2008-09-02 20:04:27 UTC (rev 27289) +++ haiku/trunk/src/add-ons/kernel/drivers/network/attansic_l2/dev/ae/if_ae.c 2008-09-02 22:19:45 UTC (rev 27290) @@ -0,0 +1,1897 @@ +/*- + * Copyright (c) 2008 Stanislav Sedov . + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Driver for Attansic Technology Corp. L2 FastEthernet adapter. + * + * This driver is heavily based on age(4) Attansic L1 driver by Pyun YongHyeon. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include + +#ifdef __HAIKU__ +#include +#endif + +#include "miibus_if.h" + +#include "if_aereg.h" +#include "if_aevar.h" + +MODULE_DEPEND(ae, pci, 1, 1, 1); +MODULE_DEPEND(ae, ether, 1, 1, 1); +MODULE_DEPEND(ae, miibus, 1, 1, 1); + +/* + * Devices supported by this driver. + */ +static struct ae_dev { + uint16_t vendorid; + uint16_t deviceid; + const char *name; +} ae_devs[] = { + { VENDORID_ATTANSIC, DEVICEID_ATTANSIC_L2, + "Attansic Technology Corp, L2 FastEthernet" }, +}; + +#define AE_DEVS_COUNT (sizeof(ae_devs) / sizeof(*ae_devs)) + +static int ae_probe(device_t dev); +static int ae_attach(device_t dev); +static void ae_pcie_init(ae_softc_t *sc); +static void ae_phy_reset(ae_softc_t *sc); +static int ae_reset(ae_softc_t *sc); +static void ae_init(void *arg); +static int ae_init_locked(ae_softc_t *sc); +static unsigned int ae_detach(device_t dev); +static int ae_miibus_readreg(device_t dev, int phy, int reg); +static int ae_miibus_writereg(device_t dev, int phy, int reg, int val); +static void ae_miibus_statchg(device_t dev); +static void ae_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmr); +static int ae_mediachange(struct ifnet *ifp); +static void ae_retrieve_address(ae_softc_t *sc); +static void ae_dmamap_cb(void *arg, bus_dma_segment_t *segs, int nsegs, int error); +static int ae_alloc_rings(ae_softc_t *sc); +static void ae_dma_free(ae_softc_t *sc); +static int ae_shutdown(device_t dev); +static int ae_suspend(device_t dev); +static int ae_resume(device_t dev); +static unsigned int ae_tx_avail_size(ae_softc_t *sc); +static int ae_encap(ae_softc_t *sc, struct mbuf **m_head); +static void ae_start(struct ifnet *ifp); +static void ae_link_task(void *arg, int pending); +static void ae_stop_rxmac(ae_softc_t *sc); +static void ae_stop_txmac(ae_softc_t *sc); +static void ae_tx_task(void *arg, int pending); +static void ae_mac_config(ae_softc_t *sc); +static int ae_intr(void *arg); +static void ae_int_task(void *arg, int pending); +static void ae_tx_intr(ae_softc_t *sc); +static int ae_rxeof(ae_softc_t *sc, ae_rxd_t *rxd); +static void ae_rx_intr(ae_softc_t *sc); +static void ae_watchdog(ae_softc_t *sc); +static void ae_tick(void *arg); +static void ae_rxfilter(ae_softc_t *sc); +static int ae_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data); +static void ae_stop(ae_softc_t *sc); +static int ae_check_eeprom_present(ae_softc_t *sc, int *vpdc); +static int ae_vpd_read_word(ae_softc_t *sc, int reg, uint32_t *word); +static int ae_get_vpd_eaddr(ae_softc_t *sc, uint32_t *eaddr); +static int ae_get_reg_eaddr(ae_softc_t *sc, uint32_t *eaddr); + +static device_method_t ae_methods[] = { + /* Device interface. */ + DEVMETHOD(device_probe, ae_probe), + DEVMETHOD(device_attach, ae_attach), + DEVMETHOD(device_detach, ae_detach), + DEVMETHOD(device_shutdown, ae_shutdown), + DEVMETHOD(device_suspend, ae_suspend), + DEVMETHOD(device_resume, ae_resume), + + /* MII interface. */ + DEVMETHOD(miibus_readreg, ae_miibus_readreg), + DEVMETHOD(miibus_writereg, ae_miibus_writereg), + DEVMETHOD(miibus_statchg, ae_miibus_statchg), + + { NULL, NULL } +}; + +static driver_t ae_driver = { + "ae", + ae_methods, + sizeof(ae_softc_t) +}; + +static devclass_t ae_devclass; + +DRIVER_MODULE(ae, pci, ae_driver, ae_devclass, 0, 0); +DRIVER_MODULE(miibus, ae, miibus_driver, miibus_devclass, 0, 0); + +static struct resource_spec ae_res_spec_mem[] = { + { SYS_RES_MEMORY, PCIR_BAR(0), RF_ACTIVE }, + { -1, 0, 0 } +}; + +static struct resource_spec ae_res_spec_irq[] = { + { SYS_RES_IRQ, 0, RF_ACTIVE | RF_SHAREABLE }, + { -1, 0, 0 } +}; + +#define AE_READ_4(sc, reg) \ + bus_read_4((sc)->mem[0], (reg)) + +#define AE_READ_2(sc, reg) \ + bus_read_2((sc)->mem[0], (reg)) + +#define AE_READ_1(sc, reg) \ + bus_read_1((sc)->mem[0], (reg)) + +#define AE_WRITE_4(sc, reg, val) \ + bus_write_4((sc)->mem[0], (reg), (val)) + +#define AE_WRITE_2(sc, reg, val) \ + bus_write_2((sc)->mem[0], (reg), (val)) + +#define AE_WRITE_1(sc, reg, val) \ + bus_write_1((sc)->mem[0], (reg), (val)) + +#define AE_CHECK_EADDR_VALID(eaddr) \ + ((eaddr[0] == 0 && eaddr[1] == 0) || \ + (eaddr[0] == 0xffffffff && eaddr[1] == 0xffff)) + +static int +ae_probe(device_t dev) +{ + uint16_t vendorid, deviceid; + int i; + + vendorid = pci_get_vendor(dev); + deviceid = pci_get_device(dev); + + for (i = 0; i < AE_DEVS_COUNT; i++) { + if (vendorid == ae_devs[i].vendorid && + deviceid == ae_devs[i].deviceid) { + device_set_desc(dev, ae_devs[i].name); + return (BUS_PROBE_DEFAULT); + } + } + + return (ENXIO); +} + +static int +ae_attach(device_t dev) +{ + ae_softc_t *sc; + struct ifnet *ifp; + int error; + uint8_t chiprev; + uint32_t pcirev; + + sc = device_get_softc(dev); /* Automatically allocated and zeroed + on attach. */ + + KASSERT(sc != NULL, ("[ae, %d]: sc is null", __LINE__)); + sc->dev = dev; + + /* Initialize per-device mutex. */ + mtx_init(&sc->mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, MTX_DEF); + + callout_init_mtx(&sc->tick_ch, &sc->mtx, 0); + TASK_INIT(&sc->int_task, 0, ae_int_task, sc); + TASK_INIT(&sc->link_task, 0, ae_link_task, sc); + + /* Enable bus mastering. */ + pci_enable_busmaster(dev); + + sc->spec_mem = ae_res_spec_mem; + sc->spec_irq = ae_res_spec_irq; + + /* Allocate memory registers. */ + error = bus_alloc_resources(dev, sc->spec_mem, sc->mem); + if (error != 0) { + device_printf(dev, "could not allocate memory resources.\n"); + goto fail; + } + + /* Retrieve PCI and chip revisions. */ + pcirev = pci_get_revid(dev); + chiprev = (AE_READ_4(sc, AE_MASTER_REG) >> AE_MASTER_REVNUM_SHIFT) & + AE_MASTER_REVNUM_MASK; + if (bootverbose || 1) { + device_printf(dev, "pci device revision: %#04x\n", pcirev); + device_printf(dev, "chip id: %#02x\n", chiprev); + } + + /* Allocate IRQ resources. */ + error = bus_alloc_resources(dev, sc->spec_irq, sc->irq); + if (error != 0) { + device_printf(dev, "could not allocate IRQ resources.\n"); + goto fail; + } + + /* Reset PHY */ + AE_LOCK(sc); + ae_phy_reset(sc); + AE_UNLOCK(sc); + + /* Reset the controller. */ + error = ae_reset(sc); + if (error != 0) + goto fail; + + /* Initialize PCIE controller. */ + ae_pcie_init(sc); + + /* Load MAC address. */ + ae_retrieve_address(sc); + + /* Set default PHY address. */ + sc->phyaddr = AE_PHYADDR_DEFAULT; + + ifp = sc->ifp = if_alloc(IFT_ETHER); + if (ifp == NULL) { + device_printf(dev, "could not allocate ifnet structure.\n"); + error = ENXIO; + } + + ifp->if_softc = sc; + if_initname(ifp, device_get_name(dev), device_get_unit(dev)); + ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; + ifp->if_ioctl = ae_ioctl; + ifp->if_start = ae_start; + ifp->if_init = ae_init; + ifp->if_capabilities = IFCAP_VLAN_MTU; + ifp->if_capenable = ifp->if_capabilities; + ifp->if_hwassist = 0; + ifp->if_snd.ifq_drv_maxlen = IFQ_MAXLEN; + IFQ_SET_MAXLEN(&ifp->if_snd, ifp->if_snd.ifq_drv_maxlen); + IFQ_SET_READY(&ifp->if_snd); + + /* Configure and attach MII bus. */ + error = mii_phy_probe(dev, &sc->miibus, ae_mediachange, + ae_mediastatus); + if (error != 0) { + device_printf(dev, "no PHY found.\n"); + goto fail; + } + + ether_ifattach(ifp, sc->eaddr); + + TASK_INIT(&sc->tx_task, 1, ae_tx_task, ifp); + sc->tq = taskqueue_create_fast("ae_taskq", M_WAITOK, + taskqueue_thread_enqueue, &sc->tq); + if (sc->tq == NULL) { + device_printf(dev, "could not create taskqueue.\n"); + ether_ifdetach(ifp); + error = ENXIO; + goto fail; + } + + taskqueue_start_threads(&sc->tq, 1, PI_NET, "%s taskq", + device_get_nameunit(sc->dev)); + + error = bus_setup_intr(dev, sc->irq[0], INTR_TYPE_NET | INTR_MPSAFE, + ae_intr, NULL, sc, &sc->intrhand); + if (error != 0) { + device_printf(dev, "could not set up interrupt handler.\n"); + taskqueue_free(sc->tq); + sc->tq = NULL; + ether_ifdetach(ifp); + goto fail; + } + +fail: + if (error != 0) + ae_detach(dev); + + return (error); +} + +static void +ae_pcie_init(ae_softc_t *sc) +{ + AE_WRITE_4(sc, AE_LTSSM_TESTMODE_REG, AE_LTSSM_TESTMODE_DEFAULT); + AE_WRITE_4(sc, AE_DLL_TX_REG, AE_DLL_TX_DEFAULT); +} + +static void +ae_phy_reset(ae_softc_t *sc) +{ + AE_WRITE_4(sc, AE_PHY_ENABLE_REG, AE_PHY_ENABLE); + DELAY(1000); /* XXX: pause(9) ? */ +} + +static int +ae_reset(ae_softc_t *sc) +{ + int i; + + /* Issue a soft reset. */ + AE_WRITE_4(sc, AE_MASTER_REG, AE_MASTER_SOFT_RESET); + bus_barrier(sc->mem[0], AE_MASTER_REG, 4, + BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE); + + for (i = 0; i < AE_RESET_TIMEOUT; i++) { + if ((AE_READ_4(sc, AE_MASTER_REG) & AE_MASTER_SOFT_RESET) == 0) + break; + DELAY(10); + } + + if (i == AE_RESET_TIMEOUT) { + device_printf(sc->dev, "reset timeout.\n"); + return (ENXIO); + } + + /* Wait for everything to enter idle state */ + for (i = 0; i < AE_IDLE_TIMEOUT; i++) { + if (AE_READ_4(sc, AE_IDLE_REG) == 0) + break; + DELAY(100); + } + + if (i == AE_IDLE_TIMEOUT) { + device_printf(sc->dev, "could not enter idle state.\n"); + return (ENXIO); + } + + return (0); +} + +static void +ae_init(void *arg) +{ + ae_softc_t *sc; + + sc = (ae_softc_t *)arg; + AE_LOCK(sc); + ae_init_locked(sc); + AE_UNLOCK(sc); +} + +static int +ae_init_locked(ae_softc_t *sc) +{ + struct ifnet *ifp; + struct mii_data *mii; + uint8_t eaddr[ETHER_ADDR_LEN]; + uint32_t val; + bus_addr_t addr; + + AE_LOCK_ASSERT(sc); + + ifp = sc->ifp; + mii = device_get_softc(sc->miibus); + + /* Stop the device. */ + ae_stop(sc); + + /* Reset the adapter. */ + ae_reset(sc); + + /* Initialize PCIE module. */ + ae_pcie_init(sc); + + /* Initialize ring buffers. */ + ae_alloc_rings(sc); + + /* Clear and disable interrupts. */ + AE_WRITE_4(sc, AE_ISR_REG, 0xffffffff); + + /* Set the MAC address. */ + bcopy(IF_LLADDR(ifp), eaddr, ETHER_ADDR_LEN); + val = eaddr[2] << 24 | eaddr[3] << 16 | eaddr[4] << 8 | eaddr[5]; + AE_WRITE_4(sc, AE_EADDR0_REG, val); + val = eaddr[0] << 8 | eaddr[1]; + AE_WRITE_4(sc, AE_EADDR1_REG, val); + + /* Set ring buffers base addresses. */ + addr = sc->dma_rxd_busaddr; + AE_WRITE_4(sc, AE_DESC_ADDR_HI_REG, BUS_ADDR_HI(addr)); + AE_WRITE_4(sc, AE_RXD_ADDR_LO_REG, BUS_ADDR_LO(addr)); + addr = sc->dma_txd_busaddr; + AE_WRITE_4(sc, AE_TXD_ADDR_LO_REG, BUS_ADDR_LO(addr)); + addr = sc->dma_txs_busaddr; + AE_WRITE_4(sc, AE_TXS_ADDR_LO_REG, BUS_ADDR_LO(addr)); + + /* Configure ring buffers sizes. */ + AE_WRITE_2(sc, AE_RXD_COUNT_REG, AE_RXD_COUNT_DEFAULT); + AE_WRITE_2(sc, AE_TXD_BUFSIZE_REG, AE_TXD_BUFSIZE_DEFAULT / 4); + AE_WRITE_2(sc, AE_TXS_COUNT_REG, AE_TXS_COUNT_DEFAULT); + + /* Configure interframe gap parameters. */ + val = ((AE_IFG_TXIPG_DEFAULT << AE_IFG_TXIPG_SHIFT) & + AE_IFG_TXIPG_MASK) | + ((AE_IFG_RXIPG_DEFAULT << AE_IFG_RXIPG_SHIFT) & + AE_IFG_RXIPG_MASK) | + ((AE_IFG_IPGR1_DEFAULT << AE_IFG_IPGR1_SHIFT) & + AE_IFG_IPGR1_MASK) | + ((AE_IFG_IPGR2_DEFAULT << AE_IFG_IPGR2_SHIFT) & + AE_IFG_IPGR2_MASK); + AE_WRITE_4(sc, AE_IFG_REG, val); + + /* Configure half-duplex operation. */ + val = ((AE_HDPX_LCOL_DEFAULT << AE_HDPX_LCOL_SHIFT) & + AE_HDPX_LCOL_MASK) | + ((AE_HDPX_RETRY_DEFAULT << AE_HDPX_RETRY_SHIFT) & + AE_HDPX_RETRY_MASK) | + ((AE_HDPX_ABEBT_DEFAULT << AE_HDPX_ABEBT_SHIFT) & + AE_HDPX_ABEBT_MASK) | + ((AE_HDPX_JAMIPG_DEFAULT << AE_HDPX_JAMIPG_SHIFT) & + AE_HDPX_JAMIPG_MASK) | AE_HDPX_EXC_EN; + AE_WRITE_4(sc, AE_HDPX_REG, val); + + /* Configure interrupt moderate timer. */ + AE_WRITE_2(sc, AE_IMT_REG, AE_IMT_DEFAULT); + val = AE_READ_4(sc, AE_MASTER_REG); + val |= AE_MASTER_IMT_EN; + AE_WRITE_4(sc, AE_MASTER_REG, val); + + /* Configure interrupt clearing timer. */ + AE_WRITE_2(sc, AE_ICT_REG, AE_ICT_DEFAULT); + + /* Configure MTU. */ + val = ifp->if_mtu + ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN + + ETHER_CRC_LEN; + AE_WRITE_2(sc, AE_MTU_REG, val); + + /* Configure cut-through threshold. */ + AE_WRITE_4(sc, AE_CUT_THRESH_REG, AE_CUT_THRESH_DEFAULT); + + /* Configure flow control. */ + AE_WRITE_2(sc, AE_FLOW_THRESH_HI_REG, (AE_RXD_COUNT_DEFAULT / 8) * 7); + AE_WRITE_2(sc, AE_FLOW_THRESH_LO_REG, (AE_RXD_COUNT_MIN / 8) > + (AE_RXD_COUNT_DEFAULT / 12) ? (AE_RXD_COUNT_MIN / 8) : + (AE_RXD_COUNT_DEFAULT / 12)); + + /* Init mailboxes. */ + sc->txd_cur = sc->rxd_cur = 0; + sc->txs_ack = sc->txd_ack = 0; + sc->rxd_cur = 0; + AE_WRITE_2(sc, AE_MB_TXD_IDX_REG, sc->txd_cur); + AE_WRITE_2(sc, AE_MB_RXD_IDX_REG, sc->rxd_cur); + + sc->tx_inproc = 0; /* Number of packets the chip processes now. */ + + /* We have free Txs available */ + sc->flags |= AE_FLAG_TXAVAIL; + + /* Enable DMA. */ + AE_WRITE_1(sc, AE_DMAREAD_REG, AE_DMAREAD_EN); + AE_WRITE_1(sc, AE_DMAWRITE_REG, AE_DMAWRITE_EN); + + /* Check if everything is OK. */ + val = AE_READ_4(sc, AE_ISR_REG); + if ((val & AE_ISR_PHY_LINKDOWN) != 0) { + printf("Initialization failed.\n"); + return (ENXIO); + } + + /* Clear interrupt status. */ + AE_WRITE_4(sc, AE_ISR_REG, 0x3fffffff); + AE_WRITE_4(sc, AE_ISR_REG, 0x0); + + /* Enable interrupts. */ + val = AE_READ_4(sc, AE_MASTER_REG); + AE_WRITE_4(sc, AE_MASTER_REG, val | AE_MASTER_MANUAL_INT); + AE_WRITE_4(sc, AE_IMR_REG, AE_IMR_DEFAULT); + + /* Configure MAC. */ + val = AE_MAC_TX_CRC_EN | AE_MAC_TX_AUTOPAD | + AE_MAC_FULL_DUPLEX | AE_MAC_CLK_PHY | + AE_MAC_TX_FLOW_EN | AE_MAC_RX_FLOW_EN | + ((AE_HALFBUF_DEFAULT << AE_HALFBUF_SHIFT) & AE_HALFBUF_MASK) | + ((AE_MAC_PREAMBLE_DEFAULT << AE_MAC_PREAMBLE_SHIFT) & + AE_MAC_PREAMBLE_MASK); + AE_WRITE_4(sc, AE_MAC_REG, val); + + /* Set up the receive filter. */ + ae_rxfilter(sc); +/* ae_rxvlan(sc); XXX: */ + + /* Enable Tx/Rx. */ + val = AE_READ_4(sc, AE_MAC_REG); + AE_WRITE_4(sc, AE_MAC_REG, val | AE_MAC_TX_EN | AE_MAC_RX_EN); + + sc->flags &= ~AE_FLAG_LINK; + + /* Switch to the current media */ + mii_mediachg(mii); + + callout_reset(&sc->tick_ch, hz, ae_tick, sc); + + ifp->if_drv_flags |= IFF_DRV_RUNNING; + ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; + +#ifdef AE_DEBUG + device_printf(sc->dev, "Initialization complete.\n"); +#endif + + return (0); +} + +static unsigned int +ae_detach(device_t dev) +{ + struct ae_softc *sc; + struct ifnet *ifp; + + sc = device_get_softc(dev); + KASSERT(sc != NULL, ("[ae: %d]: sc is null", __LINE__)); + ifp = sc->ifp; + + if (device_is_attached(dev)) { + AE_LOCK(sc); + sc->flags |= AE_FLAG_DETACH; + ae_stop(sc); + AE_UNLOCK(sc); + callout_drain(&sc->tick_ch); + taskqueue_drain(sc->tq, &sc->int_task); + taskqueue_drain(sc->tq, &sc->tx_task); + taskqueue_drain(taskqueue_swi, &sc->link_task); + ether_ifdetach(ifp); + } + + if (sc->tq != NULL) { + taskqueue_drain(sc->tq, &sc->int_task); + taskqueue_free(sc->tq); + sc->tq = NULL; + } + + if (sc->miibus != NULL) { + device_delete_child(dev, sc->miibus); + sc->miibus = NULL; + } + + bus_generic_detach(sc->dev); + ae_dma_free(sc); + + if (sc->intrhand != NULL) { + bus_teardown_intr(dev, sc->irq[0], sc->intrhand); + sc->intrhand = NULL; + } + + if (ifp != NULL) { + if_free(ifp); + sc->ifp = NULL; + } + + if (sc->spec_irq != NULL) + bus_release_resources(dev, sc->spec_irq, sc->irq); + if (sc->spec_mem != NULL) + bus_release_resources(dev, sc->spec_mem, sc->mem); + + mtx_destroy(&sc->mtx); + + return (0); +} + +static int +ae_miibus_readreg(device_t dev, int phy, int reg) +{ + ae_softc_t *sc; + uint32_t val; + int i; + + sc = device_get_softc(dev); + KASSERT(sc != NULL, ("[ae, %d]: sc is NULL", __LINE__)); + + /* Locking is done in upper layers. */ + +#ifdef notdef + device_printf(sc->dev, "MII read reg%d\n", reg); +#endif + + if (phy != sc->phyaddr) + return (0); + + val = ((reg << AE_MDIO_REGADDR_SHIFT) & AE_MDIO_REGADDR_MASK) | + AE_MDIO_START | AE_MDIO_READ | AE_MDIO_SUP_PREAMBLE | + ((AE_MDIO_CLK_25_4 << AE_MDIO_CLK_SHIFT) & AE_MDIO_CLK_MASK); + AE_WRITE_4(sc, AE_MDIO_REG, val); + + for (i = 0; i < AE_MDIO_TIMEOUT; i++) { + DELAY(2); + val = AE_READ_4(sc, AE_MDIO_REG); + if ((val & (AE_MDIO_START | AE_MDIO_BUSY)) == 0) + break; + } + + if (i == AE_MDIO_TIMEOUT) { + device_printf(sc->dev, "phy read timeout: %d\n", reg); + return (0); + } + + return ((val << AE_MDIO_DATA_SHIFT) & AE_MDIO_DATA_MASK); +} + +static int +ae_miibus_writereg(device_t dev, int phy, int reg, int val) +{ + ae_softc_t *sc; + uint32_t aereg; + int i; + + sc = device_get_softc(dev); + KASSERT(sc != NULL, ("[ae, %d]: sc is NULL", __LINE__)); + + /* Locking is done in upper layers. */ + + if (phy != sc->phyaddr) + return (0); + + aereg = ((reg << AE_MDIO_REGADDR_SHIFT) & AE_MDIO_REGADDR_MASK) | + AE_MDIO_START | AE_MDIO_SUP_PREAMBLE | + ((AE_MDIO_CLK_25_4 << AE_MDIO_CLK_SHIFT) & AE_MDIO_CLK_MASK) | + ((val << AE_MDIO_DATA_SHIFT) & AE_MDIO_DATA_MASK); + AE_WRITE_4(sc, AE_MDIO_REG, aereg); + + for (i = 0; i < AE_MDIO_TIMEOUT; i++) { + DELAY(2); + aereg = AE_READ_4(sc, AE_MDIO_REG); + if ((aereg & (AE_MDIO_START | AE_MDIO_BUSY)) == 0) + break; + } + + if (i == AE_MDIO_TIMEOUT) { + device_printf(sc->dev, "phy read timeout: %d\n", reg); + } + + return (0); +} + +/* MII bus callback when media changes */ +static void +ae_miibus_statchg(device_t dev) +{ + ae_softc_t *sc; + + sc = device_get_softc(dev); + taskqueue_enqueue(taskqueue_swi, &sc->link_task); +} + +/* Get current media status */ +static void +ae_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmr) +{ + ae_softc_t *sc; + struct mii_data *mii; + + sc = ifp->if_softc; + KASSERT(sc != NULL, ("[ae, %d]: sc is NULL", __LINE__)); + + AE_LOCK(sc); + mii = device_get_softc(sc->miibus); + mii_pollstat(mii); + ifmr->ifm_status = mii->mii_media_status; + ifmr->ifm_active = mii->mii_media_active; + AE_UNLOCK(sc); +} + +/* Switch to new media. */ +static int +ae_mediachange(struct ifnet *ifp) +{ + ae_softc_t *sc; + struct mii_data *mii; + struct mii_softc *mii_sc; + int error; + + /* XXX: check IFF_UP ?? */ + + sc = ifp->if_softc; + KASSERT(sc != NULL, ("[ae, %d]: sc is NULL", __LINE__)); + AE_LOCK(sc); + mii = device_get_softc(sc->miibus); + if (mii->mii_instance != 0) { + LIST_FOREACH(mii_sc, &mii->mii_phys, mii_list) + mii_phy_reset(mii_sc); + } + + error = mii_mediachg(mii); + AE_UNLOCK(sc); + + return (error); +} + +static int +ae_check_eeprom_present(ae_softc_t *sc, int *vpdc) +{ + int error; + uint32_t val; + + KASSERT(vpdc != NULL, ("[ae, %d]: vpdc is NULL!\n", __LINE__)); + + /* + * Not sure why, but Linux does this. + */ + val = AE_READ_4(sc, AE_SPICTL_REG); + if ((val & AE_SPICTL_VPD_EN) != 0) { + val &= ~AE_SPICTL_VPD_EN; + AE_WRITE_4(sc, AE_SPICTL_REG, val); + } + + error = pci_find_extcap(sc->dev, PCIY_VPD, vpdc); + + return (error); +} + +static int +ae_vpd_read_word(ae_softc_t *sc, int reg, uint32_t *word) +{ + uint32_t val; + int i; + + AE_WRITE_4(sc, AE_VPD_DATA_REG, 0); /* Clear register value. */ + + /* VPD registers start at offset 0x100. */ + val = 0x100 + reg * 4; + AE_WRITE_4(sc, AE_VPD_CAP_REG, (val << AE_VPD_CAP_ADDR_SHIFT) & + AE_VPD_CAP_ADDR_MASK); + + for (i = 0; i < AE_VPD_TIMEOUT; i++) { + DELAY(2000); + val = AE_READ_4(sc, AE_VPD_CAP_REG); + if ((val & AE_VPD_CAP_DONE) != 0) + break; + } + + if (i == AE_VPD_TIMEOUT) { + device_printf(sc->dev, "timeout reading VPD register %d.\n", + reg); + return (ETIMEDOUT); + } + + *word = AE_READ_4(sc, AE_VPD_DATA_REG); + + return (0); +} + +static int +ae_get_vpd_eaddr(ae_softc_t *sc, uint32_t *eaddr) +{ + uint32_t word, reg, val; + int error; + int found; + int vpdc; + int i; + + KASSERT(sc != NULL, ("[ae, %d]: sc is NULL", __LINE__)); + KASSERT(eaddr != NULL, ("[ae, %d]: eaddr is NULL", __LINE__)); + + /* Check for EEPROM. */ + error = ae_check_eeprom_present(sc, &vpdc); + if (error != 0) + return (error); + + /* + * Read the VPD configuration space. + * Each register is prefixed with signature, + * so we can check if it is valid. + */ + + for (i = 0, found = 0; i < AE_VPD_NREGS; i++) { + error = ae_vpd_read_word(sc, i, &word); + if (error != 0) + break; + + /* Check signature. */ + if ((word & AE_VPD_SIG_MASK) != AE_VPD_SIG) + break; + + /* Ok, we've found a valid block. */ + reg = word >> AE_VPD_REG_SHIFT; + + /* Move to the next word. */ + i++; + + if (reg != AE_EADDR0_REG && reg != AE_EADDR1_REG) + continue; + + error = ae_vpd_read_word(sc, i, &val); + if (error != 0) + break; + + if (reg == AE_EADDR0_REG) + eaddr[0] = val; + else + eaddr[1] = val; + + found++; + } + + if (found < 2) + return (ENOENT); + + /* Only last 2 bytes are used. */ + eaddr[1] &= 0xffff; + + if (AE_CHECK_EADDR_VALID(eaddr) != 0) { + if (bootverbose || 1) + device_printf(sc->dev, + "VPD ethernet address registers are invalid.\n"); + + return (EINVAL); + } + + return (0); +} + +static int +ae_get_reg_eaddr(ae_softc_t *sc, uint32_t *eaddr) +{ + /* + * BIOS is supposed to set this. + */ + eaddr[0] = AE_READ_4(sc, AE_EADDR0_REG); + eaddr[1] = AE_READ_4(sc, AE_EADDR1_REG); + + /* Only last 2 bytes are used. */ + eaddr[1] &= 0xffff; + + if (AE_CHECK_EADDR_VALID(eaddr) != 0) { + if (bootverbose || 1) + device_printf(sc->dev, + "Ethetnet address registers are invalid.\n"); + + return (EINVAL); + } + + return (0); +} + +static void +ae_retrieve_address(ae_softc_t *sc) +{ + uint32_t eaddr[2] = {0, 0}; + int error; + [... truncated: 1868 lines follow ...] From teammaui at web.de Wed Sep 3 00:33:18 2008 From: teammaui at web.de (=?utf-8?Q?Ralf_Sch=C3=BClke?=) Date: Wed, 03 Sep 2008 00:33:18 +0200 Subject: [Haiku-commits] r27290 - in haiku/trunk/src/add-ons/kernel/drivers/network: . attansic_l2 attansic_l2/dev attansic_l2/dev/ae attansic_l2/dev/mii In-Reply-To: <200809022219.m82MJxnp024240@sheep.berlios.de> References: <200809022219.m82MJxnp024240@sheep.berlios.de> Message-ID: On Wed, 03 Sep 2008 00:19:59 +0200, wrote: > Log: > Attansic L2 Fast Ethernet driver for Haiku. Port of FreeBSD driver from: > http://www.SpringDaemons.com/stas/if_ae-1214569185.tar.bz2 > (This is the wired NIC on the Asus EEE PC!) > NOTE: It is not in the image because it currently still crashes, will > look into that soon. > wow nice to see it. thanks -- Ralf Sch?lke aka stargater From julun at mail.berlios.de Wed Sep 3 02:26:30 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Wed, 3 Sep 2008 02:26:30 +0200 Subject: [Haiku-commits] r27291 - haiku/trunk/src/kits/interface Message-ID: <200809030026.m830QUKU028547@sheep.berlios.de> Author: julun Date: 2008-09-03 02:26:25 +0200 (Wed, 03 Sep 2008) New Revision: 27291 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27291&view=rev Modified: haiku/trunk/src/kits/interface/InterfaceDefs.cpp Log: * rewrote truncate_middle partly, it failed while trying to add an optional character this was most noticable in Deskbar when opening DataTranslations in Expand App Mode Modified: haiku/trunk/src/kits/interface/InterfaceDefs.cpp =================================================================== --- haiku/trunk/src/kits/interface/InterfaceDefs.cpp 2008-09-02 22:19:45 UTC (rev 27290) +++ haiku/trunk/src/kits/interface/InterfaceDefs.cpp 2008-09-03 00:26:25 UTC (rev 27291) @@ -108,7 +108,7 @@ case B_8_BIT_640x480: case B_8_BIT_800x600: case B_8_BIT_1024x768: - case B_8_BIT_1152x900: + case B_8_BIT_1152x900: case B_8_BIT_1280x1024: case B_8_BIT_1600x1200: colorSpace = B_CMAP8; @@ -117,16 +117,16 @@ case B_15_BIT_640x480: case B_15_BIT_800x600: case B_15_BIT_1024x768: - case B_15_BIT_1152x900: + case B_15_BIT_1152x900: case B_15_BIT_1280x1024: case B_15_BIT_1600x1200: - colorSpace = B_RGB15; - break; + colorSpace = B_RGB15; + break; case B_16_BIT_640x480: case B_16_BIT_800x600: case B_16_BIT_1024x768: - case B_16_BIT_1152x900: + case B_16_BIT_1152x900: case B_16_BIT_1280x1024: case B_16_BIT_1600x1200: colorSpace = B_RGB16; @@ -135,7 +135,7 @@ case B_32_BIT_640x480: case B_32_BIT_800x600: case B_32_BIT_1024x768: - case B_32_BIT_1152x900: + case B_32_BIT_1152x900: case B_32_BIT_1280x1024: case B_32_BIT_1600x1200: colorSpace = B_RGB32; @@ -167,12 +167,12 @@ width = 1024; height = 768; break; - case B_8_BIT_1152x900: - case B_15_BIT_1152x900: - case B_16_BIT_1152x900: - case B_32_BIT_1152x900: - width = 1152; height = 900; - break; + case B_8_BIT_1152x900: + case B_15_BIT_1152x900: + case B_16_BIT_1152x900: + case B_32_BIT_1152x900: + width = 1152; height = 900; + break; case B_8_BIT_1280x1024: case B_15_BIT_1280x1024: @@ -1322,92 +1322,54 @@ truncate_middle(const char* source, char* dest, uint32 numChars, const float* escapementArray, float width, float ellipsisWidth, float size) { - // find visual center + float mid = (width - ellipsisWidth) / 2.0; - ellipsisWidth /= size; - // test if this is as accurate as escapementArray * size - width /= size; + uint32 left = 0; + float leftWidth = 0.0; + while (left < numChars && (leftWidth + (escapementArray[left] * size)) < mid) + leftWidth += (escapementArray[left++] * size); - float halfWidth = (width - ellipsisWidth) / 2.0; - float leftWidth = 0.0, rightWidth = 0.0; - uint32 left, right; - - // coming from left... - - for (left = 0; left < numChars; left++) { - if (leftWidth + escapementArray[left] > halfWidth) - break; - - leftWidth += escapementArray[left]; - } - - if (left == numChars) { - // string is smaller than half of the maximum width + if (left == numChars) return false; - } - // check if the whole string fits in + float rightWidth = 0.0; + uint32 right = numChars; + while (right > left && (rightWidth + (escapementArray[right - 1] * size)) < mid) + rightWidth += (escapementArray[--right] * size); - float stringWidth = leftWidth; - uint32 i = left; - for (; i < numChars && stringWidth < width; i++) { - stringWidth += escapementArray[i]; - } - if (stringWidth < width) + if (left >= right) return false; - // coming from right... + float stringWidth = leftWidth + rightWidth; + for (uint32 i = left; i < right; ++i) + stringWidth += (escapementArray[i] * size); - for (right = numChars; right-- > left; ) { - if (rightWidth + escapementArray[right] > halfWidth) - break; - - rightWidth += escapementArray[right]; - } - - if (left >= right) { - // string is smaller than the maximum width + if (stringWidth <= width) return false; - } - if (left == 0 || right >= numChars - 1) { - // there is no space for the ellipsis + // if there is no space for the ellipsis + if (width < ellipsisWidth) { strcpy(dest, ""); return true; } - // see if the gap between left/right is smaller than the ellipsis - - float totalWidth = rightWidth + leftWidth; - - for (uint32 i = left; i < right; i++) { - totalWidth += escapementArray[i]; - if (totalWidth > width) - break; - } - - if (totalWidth <= width) { - // the whole string fits! - return false; - } - // The ellipsis now definitely fits, but let's // see if we can add another character - - totalWidth = ellipsisWidth + rightWidth + leftWidth; - + float gap = width - (leftWidth + ellipsisWidth + rightWidth); if (left > numChars - right) { // try right letter first - if (escapementArray[right] + totalWidth <= width) + if (escapementArray[right - 1] * size <= gap) { right--; - else if (escapementArray[left] + totalWidth <= width) + } else if (escapementArray[left + 1] * size <= gap) { left++; + } } else { // try left letter first - if (escapementArray[left] + totalWidth <= width) + if (escapementArray[left + 1] * size <= gap) { left++; - else if (escapementArray[right] + totalWidth <= width) + } else if (escapementArray[right - 1] * size <= gap) { right--; + } } // copy characters From julun at mail.berlios.de Wed Sep 3 02:33:43 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Wed, 3 Sep 2008 02:33:43 +0200 Subject: [Haiku-commits] r27292 - haiku/trunk/src/kits/shared Message-ID: <200809030033.m830XhI6028828@sheep.berlios.de> Author: julun Date: 2008-09-03 02:33:41 +0200 (Wed, 03 Sep 2008) New Revision: 27292 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27292&view=rev Modified: haiku/trunk/src/kits/shared/CalendarView.cpp Log: * use the new get function Modified: haiku/trunk/src/kits/shared/CalendarView.cpp =================================================================== --- haiku/trunk/src/kits/shared/CalendarView.cpp 2008-09-03 00:26:25 UTC (rev 27291) +++ haiku/trunk/src/kits/shared/CalendarView.cpp 2008-09-03 00:33:41 UTC (rev 27292) @@ -105,9 +105,7 @@ || archive->FindInt32("_month", &fMonth) != B_OK || archive->FindInt32("_year", &fYear) != B_OK) { BDate date = BDate::CurrentDate(B_LOCAL_TIME); - fDay = date.Day(); - fMonth = date.Month(); - fYear = date.Year(); + date.GetDate(&fYear, &fMonth, &fDay); } int32 start; @@ -712,9 +710,7 @@ BCalendarView::_InitObject() { BDate date = BDate::CurrentDate(B_LOCAL_TIME); - fDay = date.Day(); - fYear = date.Year(); - fMonth = date.Month(); + date.GetDate(&fYear, &fMonth, &fDay); _SetupDayNames(); _SetupDayNumbers(); @@ -923,7 +919,7 @@ if (fWeekStart == B_WEEK_START_MONDAY && dayOfWeek == 0) dayOfWeek = 7; date.AddDays(4 - dayOfWeek); - + for (int32 row = 0; row < 6; ++row) { fWeekNumbers[row].SetTo(""); fWeekNumbers[row] << date.WeekNumber(); From bonefish at mail.berlios.de Wed Sep 3 02:39:46 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Wed, 3 Sep 2008 02:39:46 +0200 Subject: [Haiku-commits] r27293 - haiku/trunk/src/tools/fs_shell Message-ID: <200809030039.m830dk66029432@sheep.berlios.de> Author: bonefish Date: 2008-09-03 02:39:45 +0200 (Wed, 03 Sep 2008) New Revision: 27293 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27293&view=rev Modified: haiku/trunk/src/tools/fs_shell/unistd.cpp Log: also seems to be the standard Linux place for the ioctl() prototype. Apparently some Linuxes discarded the header which POSIX demands. Modified: haiku/trunk/src/tools/fs_shell/unistd.cpp =================================================================== --- haiku/trunk/src/tools/fs_shell/unistd.cpp 2008-09-03 00:33:41 UTC (rev 27292) +++ haiku/trunk/src/tools/fs_shell/unistd.cpp 2008-09-03 00:39:45 UTC (rev 27293) @@ -31,15 +31,14 @@ # elif defined(HAIKU_HOST_PLATFORM_CYGWIN) # include # include +# elif defined(HAIKU_HOST_PLATFORM_LINUX) +# include +# include +# include # else // the (POSIX) correct place of definition for ioctl() # include # endif - -# if defined(HAIKU_HOST_PLATFORM_LINUX) -# include -# include -# endif #endif From ingo_weinhold at gmx.de Wed Sep 3 02:59:48 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Wed, 03 Sep 2008 02:59:48 +0200 Subject: [Haiku-commits] r27268 - haiku/trunk/src/system/kernel/posix In-Reply-To: References: <200809011616.m81GG3N6001985@sheep.berlios.de> <20080902004153.1928.11@knochen-vm.localdomain> <20080902141010.632.3@knochen-vm.localdomain> <20080902152256.728.4@knochen-vm.localdomain> Message-ID: <20080903025948.723.3@knochen-vm.localdomain> On 2008-09-02 at 16:46:29 [+0200], Salvatore Benedetto wrote: > 2008/9/2 Ingo Weinhold : > > Actually the Wait() problem is even more general. It operates on members > > without any lock. Even two concurrent semop()s could screw things up. Also > > there's a good reason why threads block in two steps, > > thread_prepare_to_block() and thread_block(). The former is usually called > > while still holding a lock that the one unblocking the thread has to hold, > > too. This avoids race conditions of the kind that the thread_unblock() is > > called before thread_prepare_to_block(), thus not waking the thread up. > > > > As for the solution: Call Wait() with the set locked and pass it the > > respective MutexLocker. Unlock after thread_prepare_to_block(). Re-lock > > after > > returning from thread_block_locked() using the full procedure (hash lock, > > lookup, lock, hash unlock). That's a bit ugly since Wait() needs > > additional > > information to do that. > > I actually thought about that too, but with the only difference to > unlock right before > calling thread_block_locked, thus after disabling interrupts. This > should make sure > that the two operations, unlocking and blocking, happens atomically > (under the assumption > that I can can Unlock with interrupts disabled), You can't unlock while holding the thread spinlock, since unlocking will also aquire the thread spinlock. > because my doubts is > what happens > if I got preempted right after I called thread_prepare_to_block(); > Unlock(); ? > Wouldn't the thread sleep theorically forever if it calls > thread_block_locked() after > the set has been deleted? Nope, since the destructor calls thread_unblock(). Therefore thread_block() would return immediately. This situation is exactly the reason why there are two blocking steps. After the first step the thread is already known to block, while it still has the chance to do whatever cleanup work it has to do (usually releasing a lock). > Anyway, in order not to mess even more the Wait() function I was > thinking about just > removing it. Sure, do that. CU, Ingo From julun at mail.berlios.de Wed Sep 3 04:15:30 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Wed, 3 Sep 2008 04:15:30 +0200 Subject: [Haiku-commits] r27294 - haiku/trunk/src/kits/interface Message-ID: <200809030215.m832FU6d010173@sheep.berlios.de> Author: julun Date: 2008-09-03 04:15:30 +0200 (Wed, 03 Sep 2008) New Revision: 27294 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27294&view=rev Modified: haiku/trunk/src/kits/interface/InterfaceDefs.cpp Log: * of by one, while left points behind the chars to copy right points to the first charater to start copy with Modified: haiku/trunk/src/kits/interface/InterfaceDefs.cpp =================================================================== --- haiku/trunk/src/kits/interface/InterfaceDefs.cpp 2008-09-03 00:39:45 UTC (rev 27293) +++ haiku/trunk/src/kits/interface/InterfaceDefs.cpp 2008-09-03 02:15:30 UTC (rev 27294) @@ -1360,12 +1360,12 @@ // try right letter first if (escapementArray[right - 1] * size <= gap) { right--; - } else if (escapementArray[left + 1] * size <= gap) { + } else if (escapementArray[left] * size <= gap) { left++; } } else { // try left letter first - if (escapementArray[left + 1] * size <= gap) { + if (escapementArray[left] * size <= gap) { left++; } else if (escapementArray[right - 1] * size <= gap) { right--; From emitrax at gmail.com Wed Sep 3 10:08:15 2008 From: emitrax at gmail.com (Salvatore Benedetto) Date: Wed, 3 Sep 2008 08:08:15 +0000 Subject: [Haiku-commits] r27268 - haiku/trunk/src/system/kernel/posix In-Reply-To: <20080902152256.728.4@knochen-vm.localdomain> References: <200809011616.m81GG3N6001985@sheep.berlios.de> <20080902004153.1928.11@knochen-vm.localdomain> <20080902141010.632.3@knochen-vm.localdomain> <20080902152256.728.4@knochen-vm.localdomain> Message-ID: 2008/9/2 Ingo Weinhold : > > Regarding re-locking. It must be ensured that it's still the same semaphore > set. Someone could have IPC_RMID the set and added a new one with the same > ID. I.e. the semaphore set pointers must be the same and a global counter > should be introduced (incremented whenever semget() adds a set to the hash > table, and the value stored in the set). On a second thought, I think this is not a problem, since when we return from Wait beside checking if the set is still valid, we also check for the return value of thread_block_locked(), in which case will be EIDRM, preventing us from using the set any further. So moving the unlock right after thread_prepare_to_block(), and removing the Wait() to keep thing clean, should definitely fix the problem. Regards, -- Salvatore Benedetto (a.k.a. emitrax) Student of Computer Engineer University of Pisa www.haiku-os.it From sbenedetto at mail.berlios.de Wed Sep 3 11:00:28 2008 From: sbenedetto at mail.berlios.de (sbenedetto at BerliOS) Date: Wed, 3 Sep 2008 11:00:28 +0200 Subject: [Haiku-commits] r27295 - haiku/trunk/src/system/kernel/posix Message-ID: <200809030900.m8390Swp003545@sheep.berlios.de> Author: sbenedetto Date: 2008-09-03 11:00:27 +0200 (Wed, 03 Sep 2008) New Revision: 27295 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27295&view=rev Modified: haiku/trunk/src/system/kernel/posix/xsi_message_queue.cpp Log: * Start implementing _kern_xsi_msgsnd(). Modified: haiku/trunk/src/system/kernel/posix/xsi_message_queue.cpp =================================================================== --- haiku/trunk/src/system/kernel/posix/xsi_message_queue.cpp 2008-09-03 02:15:30 UTC (rev 27294) +++ haiku/trunk/src/system/kernel/posix/xsi_message_queue.cpp 2008-09-03 09:00:27 UTC (rev 27295) @@ -52,25 +52,31 @@ struct queued_message : DoublyLinkedListLinkImpl { - queued_message(long type, char *_message, ssize_t length) + queued_message(const void *_message, ssize_t _length) : - init(false), - length(length), - type(type) + initOK(false), + length(_length) { - message = (char *)malloc(sizeof(char) * length); - if (message) - init = true; - memcpy(_message, message, length); + message = (char *)malloc(sizeof(char) * _length); + if (message == NULL) + return; + + if (user_memcpy(&type, _message, sizeof(long)) != B_OK + || user_memcpy(message, (void *)((long *)_message + sizeof(long)), + _length) != B_OK) { + free(message); + return; + } + initOK = true; } ~queued_message() { - if (init) + if (initOK) free(message); } - bool init; + bool initOK; ssize_t length; char *message; long type; @@ -84,6 +90,8 @@ class XsiMessageQueue { public: XsiMessageQueue(int flags) + : + fBytesInQueue(0) { mutex_init(&fLock, "XsiMessageQueue private mutex"); SetIpcKey((key_t)-1); @@ -139,6 +147,9 @@ return fID; } + // Implemented after sXsiMessageCountLock is declared + bool Insert(queued_message *message); + key_t IpcKey() const { return fMessageQueue.msg_perm.key; @@ -177,12 +188,18 @@ // Implemented after sMessageQueueHashTable is declared void UnsetID(); + status_t Wait(queued_message *message) + { + return B_ERROR; + } + HashTableLink* Link() { return &fLink; } private: + msglen_t fBytesInQueue; int fID; mutex fLock; MessageQueue fMessage; @@ -282,20 +299,45 @@ } }; -// Arbitrary limit -#define MAX_XSI_MESSAGE_QUEUE 2048 +// Arbitrary limits +#define MAX_XSI_MESSAGE 4096 +#define MAX_XSI_MESSAGE_QUEUE 1024 static OpenHashTable sIpcHashTable; static OpenHashTable sMessageQueueHashTable; static mutex sIpcLock; static mutex sXsiMessageQueueLock; +static mutex sXsiMessageCountLock; static vint32 sNextAvailableID = 1; +static vint32 sXsiMessageCount = 0; static vint32 sXsiMessageQueueCount = 0; // #pragma mark - + +bool +XsiMessageQueue::Insert(queued_message *message) +{ + // The only situation that would make us (potentially) wait + // is that we exceed with bytes or with the total number of messages + MutexLocker _(sXsiMessageCountLock); + if (fBytesInQueue == fMessageQueue.msg_qbytes + || fBytesInQueue + message->length > fMessageQueue.msg_qbytes + || sXsiMessageCount <= MAX_XSI_MESSAGE) + return true; + + fMessage.Add(message); + fMessageQueue.msg_qnum++; + fMessageQueue.msg_lspid = getpid(); + fMessageQueue.msg_stime = real_time_clock(); + fBytesInQueue += message->length; + sXsiMessageCount++; + return false; +} + + void XsiMessageQueue::SetID() { @@ -308,6 +350,7 @@ fID = sNextAvailableID++; } + void XsiMessageQueue::UnsetID() { @@ -331,13 +374,15 @@ mutex_init(&sIpcLock, "global POSIX message queue IPC table"); mutex_init(&sXsiMessageQueueLock, "global POSIX xsi message queue table"); + mutex_init(&sXsiMessageCountLock, "global POSIX xsi message count"); } // #pragma mark - Syscalls -int _user_xsi_msgctl(int messageQueueID, int command, struct msqid_ds *buffer) +int +_user_xsi_msgctl(int messageQueueID, int command, struct msqid_ds *buffer) { TRACE(("xsi_msgctl: messageQueueID = %d, command = %d\n", messageQueueID, command)); MutexLocker ipcHashLocker(sIpcLock); @@ -361,7 +406,11 @@ messageQueueLocker.SetTo(&messageQueue->Lock(), false); messageQueueHashLocker.Unlock(); ipcHashLocker.Unlock(); - } + } else + // Since we are going to delete the message queue object + // along with its mutex, we can't use a MutexLocker object, + // as the mutex itself won't exist on function exit + mutex_lock(&messageQueue->Lock()); switch (command) { case IPC_STAT: { @@ -437,7 +486,8 @@ } -int _user_xsi_msgget(key_t key, int flags) +int +_user_xsi_msgget(key_t key, int flags) { TRACE(("xsi_msgget: key = %d, flags = %d\n", (nt)key, flags)); XsiMessageQueue *messageQueue = NULL; @@ -515,7 +565,8 @@ } -ssize_t _user_xsi_msgrcv(int messageQueueID, void *messagePointer, +ssize_t +_user_xsi_msgrcv(int messageQueueID, void *messagePointer, size_t messageSize, long messageType, int messageFlags) { // TODO @@ -523,9 +574,60 @@ } -int _user_xsi_msgsnd(int messageQueueID, const void *messagePointer, +int +_user_xsi_msgsnd(int messageQueueID, const void *messagePointer, size_t messageSize, int messageFlags) { - // TODO - return B_ERROR; + TRACE(("xsi_msgsnd: messageQueueID = %d, messageSize = %Ld\n", + messageQueueID, messageSize)); + MutexLocker messageQueueHashLocker(sXsiMessageQueueLock); + XsiMessageQueue *messageQueue = sMessageQueueHashTable.Lookup(messageQueueID); + if (messageQueue == NULL) { + TRACE_ERROR(("xsi_msgsnd: message queue id %d not valid\n", + messageQueueID)); + return EINVAL; + } + MutexLocker messageQueueLocker(messageQueue->Lock()); + messageQueueHashLocker.Unlock(); + + if (messageSize < 0 || messageSize > MAX_BYTES_PER_QUEUE) { + TRACE_ERROR(("xsi_msgsnd: message size is out of range\n")); + return EINVAL; + } + if (!messageQueue->HasPermission()) { + TRACE_ERROR(("xsi_msgsnd: calling process has not permission " + "on message queue id %d, key %d\n", messageQueueID, + (int)messageQueue->IpcKey())); + return EACCES; + } + if (!IS_USER_ADDRESS(messagePointer)) { + TRACE_ERROR(("xsi_msgsnd: message address is not valid\n")); + return B_BAD_ADDRESS; + } + + bool notSent = true; + while (notSent) { + queued_message *message + = new(std::nothrow) queued_message(messagePointer, messageSize); + if (message == NULL || message->initOK != true) { + TRACE_ERROR(("xsi_msgsnd: failed to create new message to queue\n")); + delete message; + return ENOMEM; + } + bool goToSleep = messageQueue->Insert(message); + if (goToSleep && !(messageFlags & IPC_NOWAIT)) { + // We are going to sleep + messageQueue->Wait(message); + } else if (goToSleep) { + // We did not send the message and we can't wait + delete message; + return EAGAIN; + } else { + // Message delivered correctly + TRACE(("xsi_msgsnd: message sent correctly\n")); + notSent = false; + } + } + + return B_OK; } From mmlr at mlotz.ch Wed Sep 3 11:03:33 2008 From: mmlr at mlotz.ch (Michael Lotz) Date: Wed, 3 Sep 2008 11:03:33 +0200 Subject: [Haiku-commits] r27290 - in haiku/trunk/src/add-ons/kernel/drivers/network: . attansic_l2 attansic_l2/dev attansic_l2/dev/ae attansic_l2/dev/mii In-Reply-To: <200809022219.m82MJxnp024240@sheep.berlios.de> References: <200809022219.m82MJxnp024240@sheep.berlios.de> Message-ID: <20080903090321.M73117@mlotz.ch> On Wed, 3 Sep 2008 00:19:59 +0200, colacoder wrote > Author: colacoder > Date: 2008-09-03 00:19:45 +0200 (Wed, 03 Sep 2008) > New Revision: 27290 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27290&view=rev > > Log: > Attansic L2 Fast Ethernet driver for Haiku. Port of FreeBSD driver from: > http://www.SpringDaemons.com/stas/if_ae-1214569185.tar.bz2 > (This is the wired NIC on the Asus EEE PC!) > NOTE: It is not in the image because it currently still crashes, > will look into that soon. Ouch... I have ported exactly that driver some more than a month ago. My version doesn't crash, however sending doesn't work. It seems that there is a problem with our emulation layer as it seems other FreeBSD drivers aren't working either (there's a VIA rhine bugreport mentioning similar symptoms). I haven't commited it as Stas (who wrote the driver) mentioned in some post that the version is outdated and that a newer version would be made available. Since it isn't usable as is I decided to wait for the update first to check whether this would get it going. BTW I used the atphy instead of the ukphy and added the F2 to that one. It seemed to work better in some regard, though sending wasn't affected by that. Not sure it would actually work in the end. Regards Michael From jackburton at mail.berlios.de Wed Sep 3 12:02:02 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Wed, 3 Sep 2008 12:02:02 +0200 Subject: [Haiku-commits] r27296 - haiku/trunk/src/tests/kits/game/chart Message-ID: <200809031002.m83A229U009275@sheep.berlios.de> Author: jackburton Date: 2008-09-03 12:01:58 +0200 (Wed, 03 Sep 2008) New Revision: 27296 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27296&view=rev Modified: haiku/trunk/src/tests/kits/game/chart/ChartView.cpp Log: fixed warnings (gcc4). Style fixes. Modified: haiku/trunk/src/tests/kits/game/chart/ChartView.cpp =================================================================== --- haiku/trunk/src/tests/kits/game/chart/ChartView.cpp 2008-09-03 09:00:27 UTC (rev 27295) +++ haiku/trunk/src/tests/kits/game/chart/ChartView.cpp 2008-09-03 10:01:58 UTC (rev 27296) @@ -14,67 +14,82 @@ #include "ChartView.h" #include "ChartWindow.h" -/* Straightforward constructor */ -ChartView::ChartView(BRect rect) : -BView(rect, "", B_FOLLOW_ALL, B_WILL_DRAW) {;} +ChartView::ChartView(BRect rect) + : + BView(rect, "", B_FOLLOW_ALL, B_WILL_DRAW) +{ +} + + /* The drawing function just draw the offscreen if it exists and is used */ -void ChartView::Draw(BRect r) +void +ChartView::Draw(BRect rect) { - ChartWindow *w; - - w = dynamic_cast(Window()); - if ((w->fOffscreen != 0) && (w->fCurrentSettings.display == DISPLAY_BITMAP)) - DrawBitmap(w->fOffscreen, r, r); + ChartWindow *window = dynamic_cast(Window()); + if ((window->fOffscreen != 0) && (window->fCurrentSettings.display == DISPLAY_BITMAP)) + DrawBitmap(window->fOffscreen, rect, rect); } + /* Send a message to the window if the user click anywhere in the animation view. This is used to go out of fullscreen demo mode. */ -void ChartView::MouseDown(BPoint where) +void +ChartView::MouseDown(BPoint where) { Window()->PostMessage(BACK_DEMO_MSG); } + /* Another straightforward constructor. The default target setting for the frames/s vue-meter is 5 (as 5 * 12 = 60 frames/s) */ -InstantView::InstantView(BRect rect) : -BView(rect, "", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW) +InstantView::InstantView(BRect rect) + : + BView(rect, "", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW) { step = 5; } + /* Draw the colored bars of the vue-meter depending the current framerate of the window animation. The color coding depends of the target framerate as encoded by step. */ -void InstantView::Draw(BRect r) +void +InstantView::Draw(BRect rect) { - ChartWindow *w = dynamic_cast(Window()); - for (int32 i=0; i< w->fInstantLoadLevel; i++) { - if (i(Window()); + for (int32 i = 0; i < window->fInstantLoadLevel; i++) { + if (i < step) + SetHighColor(255, 90, 90); + else if ((i / step) & 1) + SetHighColor(90, 255, 90); + else + SetHighColor(40, 200, 40); + FillRect(BRect(3 + i * 4, 2, 5 + i * 4, 19)); } Flush(); } -/* Straightforward constructor */ -ChartColorControl::ChartColorControl(BPoint start, BMessage *message) : -BColorControl(start, B_CELLS_32x8, 8.0, "", message) + +ChartColorControl::ChartColorControl(BPoint start, BMessage *message) + : + BColorControl(start, B_CELLS_32x8, 8.0, "", message) { } + /* We overwrite SetValue to send a message to the target everytime the setting change and not only at the end. */ -void ChartColorControl::SetValue(int32 color_value) +void +ChartColorControl::SetValue(int32 colorValue) { - BLooper *looper; + BLooper *looper; - BColorControl::SetValue(color_value); + BColorControl::SetValue(colorValue); Target(&looper); if (looper) { BMessage msg(*Message()); - msg.AddInt32("be:value", color_value); + msg.AddInt32("be:value", colorValue); looper->PostMessage(&msg); } } From jackburton at mail.berlios.de Wed Sep 3 13:23:20 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Wed, 3 Sep 2008 13:23:20 +0200 Subject: [Haiku-commits] r27297 - in haiku/trunk: headers/private/storage src/kits/storage Message-ID: <200809031123.m83BNKbn014936@sheep.berlios.de> Author: jackburton Date: 2008-09-03 13:23:15 +0200 (Wed, 03 Sep 2008) New Revision: 27297 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27297&view=rev Modified: haiku/trunk/headers/private/storage/OffsetFile.h haiku/trunk/src/kits/storage/OffsetFile.cpp Log: the virtual version is const Modified: haiku/trunk/headers/private/storage/OffsetFile.h =================================================================== --- haiku/trunk/headers/private/storage/OffsetFile.h 2008-09-03 10:01:58 UTC (rev 27296) +++ haiku/trunk/headers/private/storage/OffsetFile.h 2008-09-03 11:23:15 UTC (rev 27297) @@ -49,7 +49,7 @@ off_t Position() const; status_t SetSize(off_t size); - status_t GetSize(off_t *size); + status_t GetSize(off_t *size) const; off_t Offset() const; Modified: haiku/trunk/src/kits/storage/OffsetFile.cpp =================================================================== --- haiku/trunk/src/kits/storage/OffsetFile.cpp 2008-09-03 10:01:58 UTC (rev 27296) +++ haiku/trunk/src/kits/storage/OffsetFile.cpp 2008-09-03 11:23:15 UTC (rev 27297) @@ -145,7 +145,7 @@ // GetSize status_t -OffsetFile::GetSize(off_t *size) +OffsetFile::GetSize(off_t *size) const { status_t error = (size ? B_OK : B_BAD_VALUE ); if (error == B_OK) From revol at free.fr Wed Sep 3 14:05:03 2008 From: revol at free.fr (=?windows-1252?q?Fran=E7ois?= Revol) Date: Wed, 03 Sep 2008 14:05:03 +0200 CEST Subject: [Haiku-commits] =?windows-1252?q?r27290_-_in_haiku/trunk/src/add-?= =?windows-1252?q?ons/kernel/drivers/network=3A_=2E_attansic=5Fl2_attansic?= =?windows-1252?q?=5Fl2/dev_attansic=5Fl2/dev/ae_attansic=5Fl2/dev/mii?= In-Reply-To: <200809022219.m82MJxnp024240@sheep.berlios.de> Message-ID: <3286360959-BeMail@laptop> > Log: > Attansic L2 Fast Ethernet driver for Haiku. Port of FreeBSD driver > from: > http://www.SpringDaemons.com/stas/if_ae-1214569185.tar.bz2 > (This is the wired NIC on the Asus EEE PC!) Nice. Great to see you back ! Fran?ois. From ingo_weinhold at gmx.de Wed Sep 3 14:54:32 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Wed, 03 Sep 2008 14:54:32 +0200 Subject: [Haiku-commits] r27268 - haiku/trunk/src/system/kernel/posix In-Reply-To: References: <200809011616.m81GG3N6001985@sheep.berlios.de> <20080902004153.1928.11@knochen-vm.localdomain> <20080902141010.632.3@knochen-vm.localdomain> <20080902152256.728.4@knochen-vm.localdomain> Message-ID: <20080903145432.490.1@knochen-vm.localdomain> On 2008-09-03 at 10:08:15 [+0200], Salvatore Benedetto wrote: > 2008/9/2 Ingo Weinhold : > > > > Regarding re-locking. It must be ensured that it's still the same > > semaphore > > set. Someone could have IPC_RMID the set and added a new one with the same > > ID. I.e. the semaphore set pointers must be the same and a global counter > > should be introduced (incremented whenever semget() adds a set to the hash > > table, and the value stored in the set). > > On a second thought, I think this is not a problem, since when we > return from Wait > beside checking if the set is still valid, we also check for the > return value of thread_block_locked(), > in which case will be EIDRM, preventing us from using the set any further. That's not safe to assume. A friendly unblock by another semop() could be followed directly by a removal of the semaphore set. Hence thread_block_locked() returned B_OK, but the semaphore set would be gone anyway. CU, Ingo From julun at mail.berlios.de Wed Sep 3 14:53:02 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Wed, 3 Sep 2008 14:53:02 +0200 Subject: [Haiku-commits] r27298 - haiku/trunk/src/kits/interface Message-ID: <200809031253.m83Cr29k013228@sheep.berlios.de> Author: julun Date: 2008-09-03 14:53:01 +0200 (Wed, 03 Sep 2008) New Revision: 27298 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27298&view=rev Modified: haiku/trunk/src/kits/interface/InterfaceDefs.cpp Log: * take the precision into account while trying to add an optional character Modified: haiku/trunk/src/kits/interface/InterfaceDefs.cpp =================================================================== --- haiku/trunk/src/kits/interface/InterfaceDefs.cpp 2008-09-03 11:23:15 UTC (rev 27297) +++ haiku/trunk/src/kits/interface/InterfaceDefs.cpp 2008-09-03 12:53:01 UTC (rev 27298) @@ -1233,6 +1233,16 @@ } +static bool +optional_char_fits(float escapement, float fontSize, float gap) +{ + const float size = escapement * fontSize; + if (size <= gap || fabs(size - gap) <= 0.0001) + return true; + return false; +} + + bool truncate_end(const char* source, char* dest, uint32 numChars, const float* escapementArray, float width, float ellipsisWidth, float size) @@ -1358,16 +1368,16 @@ float gap = width - (leftWidth + ellipsisWidth + rightWidth); if (left > numChars - right) { // try right letter first - if (escapementArray[right - 1] * size <= gap) { + if (optional_char_fits(escapementArray[right - 1], size, gap)) { right--; - } else if (escapementArray[left] * size <= gap) { + } else if (optional_char_fits(escapementArray[left], size, gap)) { left++; } } else { // try left letter first - if (escapementArray[left] * size <= gap) { + if (optional_char_fits(escapementArray[left], size, gap)) { left++; - } else if (escapementArray[right - 1] * size <= gap) { + } else if (optional_char_fits(escapementArray[right - 1], size, gap)) { right--; } } From emitrax at gmail.com Wed Sep 3 15:14:29 2008 From: emitrax at gmail.com (Salvatore Benedetto) Date: Wed, 3 Sep 2008 13:14:29 +0000 Subject: [Haiku-commits] r27268 - haiku/trunk/src/system/kernel/posix In-Reply-To: <20080903145432.490.1@knochen-vm.localdomain> References: <200809011616.m81GG3N6001985@sheep.berlios.de> <20080902004153.1928.11@knochen-vm.localdomain> <20080902141010.632.3@knochen-vm.localdomain> <20080902152256.728.4@knochen-vm.localdomain> <20080903145432.490.1@knochen-vm.localdomain> Message-ID: 2008/9/3 Ingo Weinhold : > > On 2008-09-03 at 10:08:15 [+0200], Salvatore Benedetto > wrote: >> 2008/9/2 Ingo Weinhold : >> > >> > Regarding re-locking. It must be ensured that it's still the same >> > semaphore >> > set. Someone could have IPC_RMID the set and added a new one with the same >> > ID. I.e. the semaphore set pointers must be the same and a global counter >> > should be introduced (incremented whenever semget() adds a set to the hash >> > table, and the value stored in the set). >> >> On a second thought, I think this is not a problem, since when we >> return from Wait >> beside checking if the set is still valid, we also check for the >> return value of thread_block_locked(), >> in which case will be EIDRM, preventing us from using the set any further. > > That's not safe to assume. A friendly unblock by another semop() could be > followed directly by a removal of the semaphore set. Hence > thread_block_locked() returned B_OK, but the semaphore set would be gone > anyway. Ok, fair enough, the check for NULL set must still take place. But how do I make sure the set is still the same? Set pointers could happen to be the same even on reuse, and I'm not sure how you want to use the global counter as it must be resetted soon or later in order to prevent an overflow. Perhaps I could change the way IDs are created by using the current time, so that we are always sure that IDs are unique, or better yet, adding a timestamp creation field to the set, and use that as identifier. Regards, -- Salvatore Benedetto (a.k.a. emitrax) Student of Computer Engineer University of Pisa www.haiku-os.it From ingo_weinhold at gmx.de Wed Sep 3 15:39:50 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Wed, 03 Sep 2008 15:39:50 +0200 Subject: [Haiku-commits] r27268 - haiku/trunk/src/system/kernel/posix In-Reply-To: References: <200809011616.m81GG3N6001985@sheep.berlios.de> <20080902004153.1928.11@knochen-vm.localdomain> <20080902141010.632.3@knochen-vm.localdomain> <20080902152256.728.4@knochen-vm.localdomain> <20080903145432.490.1@knochen-vm.localdomain> Message-ID: <20080903153950.463.3@knochen-vm.localdomain> On 2008-09-03 at 15:14:29 [+0200], Salvatore Benedetto wrote: > 2008/9/3 Ingo Weinhold : > > > > On 2008-09-03 at 10:08:15 [+0200], Salvatore Benedetto > > wrote: > >> 2008/9/2 Ingo Weinhold : > >> > > >> > Regarding re-locking. It must be ensured that it's still the same > >> > semaphore > >> > set. Someone could have IPC_RMID the set and added a new one with the > >> > same > >> > ID. I.e. the semaphore set pointers must be the same and a global > >> > counter > >> > should be introduced (incremented whenever semget() adds a set to the > >> > hash > >> > table, and the value stored in the set). > >> > >> On a second thought, I think this is not a problem, since when we > >> return from Wait > >> beside checking if the set is still valid, we also check for the > >> return value of thread_block_locked(), > >> in which case will be EIDRM, preventing us from using the set any > >> further. > > > > That's not safe to assume. A friendly unblock by another semop() could be > > followed directly by a removal of the semaphore set. Hence > > thread_block_locked() returned B_OK, but the semaphore set would be gone > > anyway. > > Ok, fair enough, the check for NULL set must still take place. > But how do I make sure the set is still the same? Set pointers could happen > to > be the same even on reuse, and I'm not sure how you want to use the > global counter > as it must be resetted soon or later in order to prevent an overflow. > > Perhaps I could change the way IDs are created by using the current > time, so that > we are always sure that IDs are unique, or better yet, adding a > timestamp creation > field to the set, and use that as identifier. That's almost the same as using a counter. With the difference that one microsecond is really quite some time on modern hardware. If you're afraid of overflows, you could use a 64 bit counter. Though I guess the chances that a 32 bit counter overflow will cause a problem in this situation are probably microscopic compared to those of being struck by lightning, surviving a plane crash, and winning the lottery on the same day. CU, Ingo From stippi at mail.berlios.de Wed Sep 3 15:40:56 2008 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Wed, 3 Sep 2008 15:40:56 +0200 Subject: [Haiku-commits] r27299 - haiku/trunk/src/apps/aboutsystem Message-ID: <200809031340.m83Deuh8018471@sheep.berlios.de> Author: stippi Date: 2008-09-03 15:40:56 +0200 (Wed, 03 Sep 2008) New Revision: 27299 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27299&view=rev Modified: haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp Log: Another attempt at improving the AboutSystem credits: * The "Most influential developers" list wasn't such a good idea after all. * Now we have "Current Maintainers" and "Past Maintainers". Some developers who still have commit access are in the Past Maintainers list, since they have not done a commit in a long time (more than a year at least) * TODO: Move more people from Contributors into Past Maintainers, I don't know many names and have not tried to match names to SVN commit log nick names. * Added Ralf Schuelke to the Contributors for his Pairs game contribution. Modified: haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp =================================================================== --- haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp 2008-09-03 12:53:01 UTC (rev 27298) +++ haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp 2008-09-03 13:40:56 UTC (rev 27299) @@ -388,63 +388,77 @@ font.SetFace(B_BOLD_FACE | B_ITALIC_FACE); fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &kHaikuOrange); - fCreditsView->Insert("Most influential developers:\n"); + fCreditsView->Insert("Current Maintainers:\n"); fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &kDarkGrey); fCreditsView->Insert( + "Ithamar R. Adema\n" + "Bruno G. Albuquerque\n" + "Stephan A?mus\n" + "Salvatore Benedetto\n" + "Stefano Ceccherini\n" + "Rudolf Cornelissen\n" + "Alexandre Deckner\n" + "Oliver Ruiz Dorantes\n" "Axel D?rfler\n" - "Ingo Weinhold\n" "J?r?me Duval\n" - "Stephan A?mus\n" + "Ren? Gollent\n" + "Karsten Heimrich\n" + "Philippe Houdoin\n" + "Maurice Kalinowski\n" + "Euan Kirkhope\n" + "Ryan Leavengood\n" + "Michael Lotz\n" + "David McPaul\n" + "Fredrik Mod?en\n" "Marcus Overhagen\n" - "Stefano Ceccherini\n" - "Rudolf Cornelissen\n" + "Michael Pfeiffer\n" "Fran?ois Revol\n" - "Michael Lotz\n" + "Andrej Spielmann\n" + "Oliver Tappe\n" + "Gerasim Troeglazov\n" + "Ingo Weinhold\n" + "Siarzhuk Zharski\n" "\n"); - fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &kHaikuOrange); - fCreditsView->Insert("Website, Marketing & Documention:\n"); + fCreditsView->Insert("Past Maintainers:\n"); fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &kDarkGrey); fCreditsView->Insert( - "Phil Greenway\n" - "Gavin James\n" - "Urias McCullough\n" + "Andrew Bachmann\n" + "Tyler Dauwalder\n" + "Daniel Furrer\n" + "Andre Alves Garzia\n" + "Erik Jaesler\n" + "Marcin Konicki\n" + "Waldemar Kornewald\n" + "Thomas Kurschel\n" + "Frans Van Nispen\n" + "Adi Oanca\n" + "Michael Phipps\n" "Niels Sascha Reedijk\n" + "David Reid\n" + "Hugo Santos\n" + "Alexander G. M. Smith\n" + "Jonas Sundstr?m\n" + "Bryan Varner\n" + "Nathan Whitehorn\n" + "Michael Wilber\n" "Jonathan Yoder\n" + "Gabe Yoder\n" "\n"); - fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &kHaikuOrange); - fCreditsView->Insert("Developers:\n"); + fCreditsView->Insert("Website, Marketing & Documention:\n"); fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &kDarkGrey); fCreditsView->Insert( - "Ithamar R. Adema\n" - "Bruno G. Albuquerque\n" - "Andrew Bachmann\n" - "Salvatore Benedetto\n" - "Alexandre Deckner\n" - "Oliver Ruiz Dorantes\n" - "Andre Alves Garzia\n" - "Ren? Gollent\n" - "Karsten Heimrich\n" - "Philippe Houdoin\n" - "Maurice Kalinowski\n" - "Euan Kirkhope\n" - "Waldemar Kornewald\n" - "Ryan Leavengood\n" - "David McPaul\n" - "Fredrik Mod?en\n" - "Michael Pfeiffer\n" - "Hugo Santos\n" - "Andrej Spielmann\n" - "Jonas Sundstr?m\n" - "Gerasim Troeglazov\n" - "Bryan Varner\n" - "Siarzhuk Zharski\n" + "Phil Greenway\n" + "Gavin James\n" + "Urias McCullough\n" + "Niels Sascha Reedijk\n" + "Jonathan Yoder\n" "\n"); fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &kHaikuOrange); @@ -456,29 +470,23 @@ "Andre Braga\n" "Bruce Cameron\n" "Greg Crain\n" - "Tyler Dauwalder\n" "David Dengg\n" "John Drinkwater\n" "Cian Duffy\n" "Christian Fasshauer\n" "Andreas F?rber\n" "Marc Flerackers\n" - "Daniel Furrer\n" "Matthijs Hollemans\n" "Mathew Hounsell\n" "Morgan Howe\n" - "Erik Jaesler\n" "Carwyn Jones\n" "Vasilis Kaoutsis\n" "James Kim\n" "Shintaro Kinugawa\n" "Jan Kl?tzke\n" - "Marcin Konicki\n" "Kurtis Kopf\n" - "Waldemar Kornewald\n" "Tom?? Ku?era\n" "Lubo? Kuli?\n" - "Thomas Kurschel\n" "Elad Lahav\n" "Anthony Lee\n" "Santiago Lema\n" @@ -498,36 +506,28 @@ "Misza\n" "MrSiggler\n" "Alan Murta\n" - "Frans Van Nispen\n" - "Adi Oanca\n" "Pahtz\n" "Michael Paine\n" - "Michael Phipps\n" "David Powell\n" "Jeremy Rand\n" "Hartmut Reh\n" - "David Reid\n" "Daniel Reinhold\n" "Samuel Rodriguez Perez\n" "Thomas Roell\n" "Rafael Romo\n" "Philippe Saint-Pierre\n" + "Ralf Sch?lke\n" "Reznikov Sergei\n" "Zousar Shaker\n" - "Alexander G. M. Smith\n" "Daniel Switkin\n" "Atsushi Takamatsu\n" - "Oliver Tappe\n" "James Urquhart\n" "Jason Vandermark\n" "Sandor Vroemisse\n" "Denis Washington\n" - "Nathan Whitehorn\n" - "Michael Wilber\n" "Ulrich Wimboeck\n" "James Woodcock\n" "Artur Wyszynski\n" - "Gabe Yoder\n" "Gerald Zajac\n" "?ukasz Zemczak\n" "JiSheng Zhang\n" @@ -535,6 +535,7 @@ "(sorry!)" "\n\n"); + fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &kHaikuOrange); fCreditsView->Insert("Special Thanks To:\n"); From superstippi at gmx.de Wed Sep 3 15:46:55 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Wed, 03 Sep 2008 15:46:55 +0200 Subject: [Haiku-commits] r27268 - haiku/trunk/src/system/kernel/posix In-Reply-To: <20080903153950.463.3@knochen-vm.localdomain> References: <200809011616.m81GG3N6001985@sheep.berlios.de> <20080902004153.1928.11@knochen-vm.localdomain> <20080902141010.632.3@knochen-vm.localdomain> <20080902152256.728.4@knochen-vm.localdomain> <20080903145432.490.1@knochen-vm.localdomain> <20080903153950.463.3@knochen-vm.localdomain> Message-ID: <20080903154655.1820.8@stippis2.1220433860.fake> Ingo Weinhold wrote: > > On 2008-09-03 at 15:14:29 [+0200], Salvatore Benedetto > wrote: > > 2008/9/3 Ingo Weinhold : > > > > > > On 2008-09-03 at 10:08:15 [+0200], Salvatore Benedetto > > > wrote: > > >> 2008/9/2 Ingo Weinhold : > > >> > > > >> > Regarding re-locking. It must be ensured that it's still the same > > >> > semaphore > > >> > set. Someone could have IPC_RMID the set and added a new one with > > >> > the same > > >> > ID. I.e. the semaphore set pointers must be the same and a global > > >> > counter > > >> > should be introduced (incremented whenever semget() adds a set to > > >> > the hash > > >> > table, and the value stored in the set). > > >> > > >> On a second thought, I think this is not a problem, since when we > > >> return from Wait > > >> beside checking if the set is still valid, we also check for the > > >> return value of thread_block_locked(), > > >> in which case will be EIDRM, preventing us from using the set any > > >> further. > > > > > > That's not safe to assume. A friendly unblock by another semop() > > > could be followed directly by a removal of the semaphore set. Hence > > > thread_block_locked() returned B_OK, but the semaphore set would be > > > gone anyway. > > > > Ok, fair enough, the check for NULL set must still take place. But how > > do I make sure the set is still the same? Set pointers could happen to > > be the same even on reuse, and I'm not sure how you want to use the > > global counter > > as it must be resetted soon or later in order to prevent an overflow. > > > > Perhaps I could change the way IDs are created by using the current > > time, so that > > we are always sure that IDs are unique, or better yet, adding a > > timestamp creation > > field to the set, and use that as identifier. > > That's almost the same as using a counter. With the difference that one > microsecond is really quite some time on modern hardware. If you're > afraid of overflows, you could use a 64 bit counter. Though I guess the > chances that a > 32 bit counter overflow will cause a problem in this situation are > probably > microscopic compared to those of being struck by lightning, surviving a > plane crash, and winning the lottery on the same day. If the counter is incremented every time a set is created, doesn't this mean that for a mix up, you would need to create and delete exactly as many sets as are possible values in the integer range of the counter, all within the time of the race condition, and finally you need to get the same pointer for the wrong set, too. Sounds like even a one byte counter should be enough to prevent a confusion - Or I am understanding only half or less of what was said... :-) Best regards, -Stephan From emitrax at gmail.com Wed Sep 3 15:52:27 2008 From: emitrax at gmail.com (Salvatore Benedetto) Date: Wed, 3 Sep 2008 13:52:27 +0000 Subject: [Haiku-commits] r27268 - haiku/trunk/src/system/kernel/posix In-Reply-To: <20080903154655.1820.8@stippis2.1220433860.fake> References: <200809011616.m81GG3N6001985@sheep.berlios.de> <20080902141010.632.3@knochen-vm.localdomain> <20080902152256.728.4@knochen-vm.localdomain> <20080903145432.490.1@knochen-vm.localdomain> <20080903153950.463.3@knochen-vm.localdomain> <20080903154655.1820.8@stippis2.1220433860.fake> Message-ID: 2008/9/3 Stephan Assmus : > >> That's almost the same as using a counter. With the difference that one >> microsecond is really quite some time on modern hardware. If you're >> afraid of overflows, you could use a 64 bit counter. Though I guess the >> chances that a >> 32 bit counter overflow will cause a problem in this situation are >> probably >> microscopic compared to those of being struck by lightning, surviving a >> plane crash, and winning the lottery on the same day. > > If the counter is incremented every time a set is created, doesn't this > mean that for a mix up, you would need to create and delete exactly as many > sets as are possible values in the integer range of the counter, all within > the time of the race condition, and finally you need to get the same > pointer for the wrong set, too. Sounds like even a one byte counter should > be enough to prevent a confusion - Or I am understanding only half or less > of what was said... :-) Yep, that's right. :-) Regards, -- Salvatore Benedetto (a.k.a. emitrax) Student of Computer Engineer University of Pisa www.haiku-os.it From ingo_weinhold at gmx.de Wed Sep 3 16:37:38 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Wed, 03 Sep 2008 16:37:38 +0200 Subject: [Haiku-commits] r27268 - haiku/trunk/src/system/kernel/posix In-Reply-To: <20080903154655.1820.8@stippis2.1220433860.fake> References: <200809011616.m81GG3N6001985@sheep.berlios.de> <20080902004153.1928.11@knochen-vm.localdomain> <20080902141010.632.3@knochen-vm.localdomain> <20080902152256.728.4@knochen-vm.localdomain> <20080903145432.490.1@knochen-vm.localdomain> <20080903153950.463.3@knochen-vm.localdomain> <20080903154655.1820.8@stippis2.1220433860.fake> Message-ID: <20080903163738.550.4@knochen-vm.localdomain> On 2008-09-03 at 15:46:55 [+0200], Stephan Assmus wrote: > > Ingo Weinhold wrote: > > > > On 2008-09-03 at 15:14:29 [+0200], Salvatore Benedetto > > wrote: > > > 2008/9/3 Ingo Weinhold : > > > > > > > > On 2008-09-03 at 10:08:15 [+0200], Salvatore Benedetto > > > > wrote: > > > >> 2008/9/2 Ingo Weinhold : > > > >> > > > > >> > Regarding re-locking. It must be ensured that it's still the same > > > >> > semaphore > > > >> > set. Someone could have IPC_RMID the set and added a new one with > > > >> > the same > > > >> > ID. I.e. the semaphore set pointers must be the same and a global > > > >> > counter > > > >> > should be introduced (incremented whenever semget() adds a set to > > > >> > the hash > > > >> > table, and the value stored in the set). > > > >> > > > >> On a second thought, I think this is not a problem, since when we > > > >> return from Wait > > > >> beside checking if the set is still valid, we also check for the > > > >> return value of thread_block_locked(), > > > >> in which case will be EIDRM, preventing us from using the set any > > > >> further. > > > > > > > > That's not safe to assume. A friendly unblock by another semop() > > > > could be followed directly by a removal of the semaphore set. Hence > > > > thread_block_locked() returned B_OK, but the semaphore set would be > > > > gone anyway. > > > > > > Ok, fair enough, the check for NULL set must still take place. But how > > > do I make sure the set is still the same? Set pointers could happen to > > > be the same even on reuse, and I'm not sure how you want to use the > > > global counter > > > as it must be resetted soon or later in order to prevent an overflow. > > > > > > Perhaps I could change the way IDs are created by using the current > > > time, so that > > > we are always sure that IDs are unique, or better yet, adding a > > > timestamp creation > > > field to the set, and use that as identifier. > > > > That's almost the same as using a counter. With the difference that one > > microsecond is really quite some time on modern hardware. If you're > > afraid of overflows, you could use a 64 bit counter. Though I guess the > > chances that a > > 32 bit counter overflow will cause a problem in this situation are > > probably > > microscopic compared to those of being struck by lightning, surviving a > > plane crash, and winning the lottery on the same day. > > If the counter is incremented every time a set is created, doesn't this > mean that for a mix up, you would need to create and delete exactly as many > sets as are possible values in the integer range of the counter, all within > the time of the race condition, and finally you need to get the same > pointer for the wrong set, too. Sounds like even a one byte counter should > be enough to prevent a confusion - Or I am understanding only half or less > of what was said... :-) Not quite. The problematic situation is this: A thread waits on a semaphore, another thread releases it, deletes it, and creates one with the same ID. That the new semaphore is created at the same memory address is not unlikely. For the counters to be equal all that's needed is that the right number of semaphores has been created after the semaphore the thread waits on and before the other thread releases the semaphore. So a malevolent citizen would have lots of time to aim for the counters to match. But the worst thing that would happen is that the first thread continued to wait on the new semaphore or succeeds to acquire it, although it would correctly have to fail. CU, Ingo From bonefish at mail.berlios.de Wed Sep 3 16:47:28 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Wed, 3 Sep 2008 16:47:28 +0200 Subject: [Haiku-commits] r27300 - in haiku/trunk: headers/private/kernel src/system/kernel Message-ID: <200809031447.m83ElSlj024603@sheep.berlios.de> Author: bonefish Date: 2008-09-03 16:47:26 +0200 (Wed, 03 Sep 2008) New Revision: 27300 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27300&view=rev Modified: haiku/trunk/headers/private/kernel/elf.h haiku/trunk/src/system/kernel/elf.cpp Log: Added elf_get_image_info_for_address() to get an image info for a kernel image. Modified: haiku/trunk/headers/private/kernel/elf.h =================================================================== --- haiku/trunk/headers/private/kernel/elf.h 2008-09-03 13:40:56 UTC (rev 27299) +++ haiku/trunk/headers/private/kernel/elf.h 2008-09-03 14:47:26 UTC (rev 27300) @@ -1,7 +1,7 @@ /* * Copyright 2005, Haiku Inc. All Rights Reserved. * Distributed under the terms of the MIT license. - * + * * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. * Distributed under the terms of the NewOS License. */ @@ -31,6 +31,7 @@ status_t elf_debug_lookup_user_symbol_address(struct team* team, addr_t address, addr_t *_baseAddress, const char **_symbolName, const char **_imageName, bool *_exactMatch); +status_t elf_get_image_info_for_address(addr_t address, image_info* info); status_t elf_init(struct kernel_args *args); #ifdef __cplusplus Modified: haiku/trunk/src/system/kernel/elf.cpp =================================================================== --- haiku/trunk/src/system/kernel/elf.cpp 2008-09-03 13:40:56 UTC (rev 27299) +++ haiku/trunk/src/system/kernel/elf.cpp 2008-09-03 14:47:26 UTC (rev 27300) @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -1820,6 +1821,33 @@ status_t +elf_get_image_info_for_address(addr_t address, image_info* info) +{ + MutexLocker _(sImageMutex); + struct elf_image_info* elfInfo = find_image_at_address(address); + if (elfInfo == NULL) + return B_ENTRY_NOT_FOUND; + + info->id = elfInfo->id; + info->type = B_SYSTEM_IMAGE; + info->sequence = 0; + info->init_order = 0; + info->init_routine = NULL; + info->term_routine = NULL; + info->device = -1; + info->node = -1; + // TODO: We could actually fill device/node in. + strlcpy(info->name, elfInfo->name, sizeof(info->name)); + info->text = (void*)elfInfo->text_region.start; + info->data = (void*)elfInfo->data_region.start; + info->text_size = elfInfo->text_region.size; + info->data_size = elfInfo->data_region.size; + + return B_OK; +} + + +status_t elf_init(kernel_args *args) { struct preloaded_image *image; From emitrax at gmail.com Wed Sep 3 16:47:25 2008 From: emitrax at gmail.com (Salvatore Benedetto) Date: Wed, 3 Sep 2008 14:47:25 +0000 Subject: [Haiku-commits] r27268 - haiku/trunk/src/system/kernel/posix In-Reply-To: <20080903163738.550.4@knochen-vm.localdomain> References: <200809011616.m81GG3N6001985@sheep.berlios.de> <20080902141010.632.3@knochen-vm.localdomain> <20080902152256.728.4@knochen-vm.localdomain> <20080903145432.490.1@knochen-vm.localdomain> <20080903153950.463.3@knochen-vm.localdomain> <20080903154655.1820.8@stippis2.1220433860.fake> <20080903163738.550.4@knochen-vm.localdomain> Message-ID: 2008/9/3 Ingo Weinhold : > > On 2008-09-03 at 15:46:55 [+0200], Stephan Assmus wrote: >> >> Ingo Weinhold wrote: >> > >> > On 2008-09-03 at 15:14:29 [+0200], Salvatore Benedetto >> > wrote: >> > > 2008/9/3 Ingo Weinhold : >> > > > >> > > > On 2008-09-03 at 10:08:15 [+0200], Salvatore Benedetto >> > > > wrote: >> > > >> 2008/9/2 Ingo Weinhold : >> > > >> > >> > > >> > Regarding re-locking. It must be ensured that it's still the same >> > > >> > semaphore >> > > >> > set. Someone could have IPC_RMID the set and added a new one with >> > > >> > the same >> > > >> > ID. I.e. the semaphore set pointers must be the same and a global >> > > >> > counter >> > > >> > should be introduced (incremented whenever semget() adds a set to >> > > >> > the hash >> > > >> > table, and the value stored in the set). >> > > >> >> > > >> On a second thought, I think this is not a problem, since when we >> > > >> return from Wait >> > > >> beside checking if the set is still valid, we also check for the >> > > >> return value of thread_block_locked(), >> > > >> in which case will be EIDRM, preventing us from using the set any >> > > >> further. >> > > > >> > > > That's not safe to assume. A friendly unblock by another semop() >> > > > could be followed directly by a removal of the semaphore set. Hence >> > > > thread_block_locked() returned B_OK, but the semaphore set would be >> > > > gone anyway. >> > > >> > > Ok, fair enough, the check for NULL set must still take place. But how >> > > do I make sure the set is still the same? Set pointers could happen to >> > > be the same even on reuse, and I'm not sure how you want to use the >> > > global counter >> > > as it must be resetted soon or later in order to prevent an overflow. >> > > >> > > Perhaps I could change the way IDs are created by using the current >> > > time, so that >> > > we are always sure that IDs are unique, or better yet, adding a >> > > timestamp creation >> > > field to the set, and use that as identifier. >> > >> > That's almost the same as using a counter. With the difference that one >> > microsecond is really quite some time on modern hardware. If you're >> > afraid of overflows, you could use a 64 bit counter. Though I guess the >> > chances that a >> > 32 bit counter overflow will cause a problem in this situation are >> > probably >> > microscopic compared to those of being struck by lightning, surviving a >> > plane crash, and winning the lottery on the same day. >> >> If the counter is incremented every time a set is created, doesn't this >> mean that for a mix up, you would need to create and delete exactly as many >> sets as are possible values in the integer range of the counter, all within >> the time of the race condition, and finally you need to get the same >> pointer for the wrong set, too. Sounds like even a one byte counter should >> be enough to prevent a confusion - Or I am understanding only half or less >> of what was said... :-) > > Not quite. The problematic situation is this: A thread waits on a semaphore, > another thread releases it, deletes it, and creates one with the same ID. > That the new semaphore is created at the same memory address is not > unlikely. For the counters to be equal all that's needed is that the right > number of semaphores has been created after the semaphore the thread waits > on and before the other thread releases the semaphore. So a malevolent > citizen would have lots of time to aim for the counters to match. But the > worst thing that would happen is that the first thread continued to wait on > the new semaphore or succeeds to acquire it, although it would correctly > have to fail. As for now there is a limit of MAX_XSI_SEMAPHORE set to 2048, which is the total number of semaphores (not sets) that one create in the system. It's a static limit of course, and in the future could be based on available memory. We could add a limit to the total number of set as well and prevent any sort of bad situation from happening. Of course the limit must be lower than the maximun value the counter can reach. Regards, -- Salvatore Benedetto (a.k.a. emitrax) Student of Computer Engineer University of Pisa www.haiku-os.it From bonefish at mail.berlios.de Wed Sep 3 16:48:48 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Wed, 3 Sep 2008 16:48:48 +0200 Subject: [Haiku-commits] r27301 - in haiku/trunk/headers/private: kernel system Message-ID: <200809031448.m83EmmjM024726@sheep.berlios.de> Author: bonefish Date: 2008-09-03 16:48:47 +0200 (Wed, 03 Sep 2008) New Revision: 27301 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27301&view=rev Modified: haiku/trunk/headers/private/kernel/thread_types.h haiku/trunk/headers/private/system/thread_defs.h Log: Moved the wait type definitions to . We're going to use them in userland, too. Modified: haiku/trunk/headers/private/kernel/thread_types.h =================================================================== --- haiku/trunk/headers/private/kernel/thread_types.h 2008-09-03 14:47:26 UTC (rev 27300) +++ haiku/trunk/headers/private/kernel/thread_types.h 2008-09-03 14:48:47 UTC (rev 27301) @@ -49,20 +49,6 @@ JOB_CONTROL_STATE_DEAD } job_control_state; -// The type of object a thread blocks on (thread::wait::type, set by -// thread_prepare_to_block()). -enum { - THREAD_BLOCK_TYPE_SEMAPHORE = 0, - THREAD_BLOCK_TYPE_CONDITION_VARIABLE = 1, - THREAD_BLOCK_TYPE_SNOOZE = 2, - THREAD_BLOCK_TYPE_SIGNAL = 3, - THREAD_BLOCK_TYPE_MUTEX = 4, - THREAD_BLOCK_TYPE_RW_LOCK = 5, - - THREAD_BLOCK_TYPE_OTHER = 9999, - THREAD_BLOCK_TYPE_USER_BASE = 10000 -}; - struct image; // defined in image.c struct realtime_sem_context; // defined in realtime_sem.cpp struct select_info; Modified: haiku/trunk/headers/private/system/thread_defs.h =================================================================== --- haiku/trunk/headers/private/system/thread_defs.h 2008-09-03 14:47:26 UTC (rev 27300) +++ haiku/trunk/headers/private/system/thread_defs.h 2008-09-03 14:48:47 UTC (rev 27301) @@ -24,6 +24,21 @@ - USER_STACK_GUARD_PAGES * B_PAGE_SIZE) // 16 MB +// The type of object a thread blocks on (thread::wait::type, set by +// thread_prepare_to_block()). +enum { + THREAD_BLOCK_TYPE_SEMAPHORE = 0, + THREAD_BLOCK_TYPE_CONDITION_VARIABLE = 1, + THREAD_BLOCK_TYPE_SNOOZE = 2, + THREAD_BLOCK_TYPE_SIGNAL = 3, + THREAD_BLOCK_TYPE_MUTEX = 4, + THREAD_BLOCK_TYPE_RW_LOCK = 5, + + THREAD_BLOCK_TYPE_OTHER = 9999, + THREAD_BLOCK_TYPE_USER_BASE = 10000 +}; + + struct thread_creation_attributes { int32 (*entry)(thread_func, void *); const char* name; From bonefish at mail.berlios.de Wed Sep 3 16:51:02 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Wed, 3 Sep 2008 16:51:02 +0200 Subject: [Haiku-commits] r27302 - in haiku/trunk: headers/private/kernel src/system/kernel/debug Message-ID: <200809031451.m83Ep2jF025034@sheep.berlios.de> Author: bonefish Date: 2008-09-03 16:51:00 +0200 (Wed, 03 Sep 2008) New Revision: 27302 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27302&view=rev Modified: haiku/trunk/headers/private/kernel/tracing.h haiku/trunk/src/system/kernel/debug/tracing.cpp Log: Added [un]lock_tracing_buffer(). This allows other components to analyze tracing buffer entries even when not in the kernel debugger. Modified: haiku/trunk/headers/private/kernel/tracing.h =================================================================== --- haiku/trunk/headers/private/kernel/tracing.h 2008-09-03 14:48:47 UTC (rev 27301) +++ haiku/trunk/headers/private/kernel/tracing.h 2008-09-03 14:51:00 UTC (rev 27302) @@ -208,6 +208,8 @@ tracing_stack_trace* capture_tracing_stack_trace(int32 maxCount, int32 skipFrames, bool userOnly); int dump_tracing(int argc, char** argv, WrapperTraceFilter* wrapperFilter); +void lock_tracing_buffer(); +void unlock_tracing_buffer(); status_t tracing_init(void); void _user_ktrace_output(const char *message); Modified: haiku/trunk/src/system/kernel/debug/tracing.cpp =================================================================== --- haiku/trunk/src/system/kernel/debug/tracing.cpp 2008-09-03 14:48:47 UTC (rev 27301) +++ haiku/trunk/src/system/kernel/debug/tracing.cpp 2008-09-03 14:51:00 UTC (rev 27302) @@ -1179,6 +1179,24 @@ } +void +lock_tracing_buffer() +{ +#if ENABLE_TRACING + acquire_spinlock(&sLock); +#endif +} + + +void +unlock_tracing_buffer() +{ +#if ENABLE_TRACING + release_spinlock(&sLock); +#endif +} + + extern "C" status_t tracing_init(void) { From bonefish at mail.berlios.de Wed Sep 3 16:53:02 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Wed, 3 Sep 2008 16:53:02 +0200 Subject: [Haiku-commits] r27303 - haiku/trunk/headers/private/kernel Message-ID: <200809031453.m83Er2YF025472@sheep.berlios.de> Author: bonefish Date: 2008-09-03 16:53:01 +0200 (Wed, 03 Sep 2008) New Revision: 27303 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27303&view=rev Modified: haiku/trunk/headers/private/kernel/condition_variable.h Log: Added ConditionVariable::ObjectType() getter. Modified: haiku/trunk/headers/private/kernel/condition_variable.h =================================================================== --- haiku/trunk/headers/private/kernel/condition_variable.h 2008-09-03 14:51:00 UTC (rev 27302) +++ haiku/trunk/headers/private/kernel/condition_variable.h 2008-09-03 14:53:01 UTC (rev 27303) @@ -65,7 +65,8 @@ // all-in one, i.e. doesn't need a // ConditionVariableEntry - const void* Object() const { return fObject; } + const void* Object() const { return fObject; } + const char* ObjectType() const { return fObjectType; } static void ListAll(); void Dump() const; From bonefish at mail.berlios.de Wed Sep 3 17:10:48 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Wed, 3 Sep 2008 17:10:48 +0200 Subject: [Haiku-commits] r27304 - in haiku/trunk: headers/private/kernel headers/private/system src/system/kernel Message-ID: <200809031510.m83FAmcr027086@sheep.berlios.de> Author: bonefish Date: 2008-09-03 17:10:44 +0200 (Wed, 03 Sep 2008) New Revision: 27304 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27304&view=rev Added: haiku/trunk/headers/private/kernel/scheduling_analysis.h haiku/trunk/headers/private/system/scheduler_defs.h Modified: haiku/trunk/headers/private/kernel/kscheduler.h haiku/trunk/headers/private/system/syscalls.h haiku/trunk/src/system/kernel/condition_variable.cpp haiku/trunk/src/system/kernel/lock.cpp haiku/trunk/src/system/kernel/scheduler.cpp haiku/trunk/src/system/kernel/sem.cpp Log: * Fixed bug in the "scheduler" command: The check when a thread was unscheduled was incorrect. * Introduced _kern_analyze_scheduling() syscall. It requires scheduler kernel tracing to be enabled. It uses the tracing entries for a given period of time to do a similar analysis the "scheduler" debugger command does (i.e. number of runs, run time, latencies, preemption times) for each thread. Additionally the analysis includes for each thread how long the thread waited on each locking primitive in total. * Added kernel tracing for the creation of semaphores and initialization of condition variables, mutexes, and rw locks. The enabling macro is SCHEDULING_ANALYSIS_TRACING. The only purpose is to provide _kern_analyze_scheduling() with more info on the locking primitives (the name in particular). Modified: haiku/trunk/headers/private/kernel/kscheduler.h =================================================================== --- haiku/trunk/headers/private/kernel/kscheduler.h 2008-09-03 14:53:01 UTC (rev 27303) +++ haiku/trunk/headers/private/kernel/kscheduler.h 2008-09-03 15:10:44 UTC (rev 27304) @@ -6,6 +6,10 @@ #define KERNEL_SCHEDULER_H +#include + + +struct scheduling_analysis; struct thread; @@ -20,6 +24,9 @@ void scheduler_init(void); void scheduler_start(void); +status_t _user_analyze_scheduling(bigtime_t from, bigtime_t until, void* buffer, + size_t size, struct scheduling_analysis* analysis); + #ifdef __cplusplus } #endif Added: haiku/trunk/headers/private/kernel/scheduling_analysis.h =================================================================== --- haiku/trunk/headers/private/kernel/scheduling_analysis.h 2008-09-03 14:53:01 UTC (rev 27303) +++ haiku/trunk/headers/private/kernel/scheduling_analysis.h 2008-09-03 15:10:44 UTC (rev 27304) @@ -0,0 +1,193 @@ +/* + * Copyright 2008, Ingo Weinhold, ingo_weinhold at gmx.de. + * Distributed under the terms of the MIT License. + */ +#ifndef _KERNEL_SCHEDULING_ANALYSIS_H +#define _KERNEL_SCHEDULING_ANALYSIS_H + +#include +#include + + +class ConditionVariable; +struct mutex; +struct rw_lock; + + +#if SCHEDULING_ANALYSIS_TRACING +namespace SchedulingAnalysisTracing { + +class WaitObjectTraceEntry : public AbstractTraceEntry { +public: + virtual uint32 Type() const = 0; + virtual void* Object() const = 0; + virtual const char* Name() const = 0; + + virtual void* ReferencedObject() const + { + return NULL; + } +}; + + +class CreateSemaphore : public WaitObjectTraceEntry { +public: + CreateSemaphore(sem_id id, const char* name) + : + fID(id), + fName(alloc_tracing_buffer_strcpy(name, 128, false)) + { + Initialized(); + } + + virtual void AddDump(TraceOutput& out) + { + out.Print("sem create \"%s\" -> %ld", fName, fID); + } + + virtual uint32 Type() const + { + return THREAD_BLOCK_TYPE_SEMAPHORE; + } + + virtual void* Object() const + { + return (void*)(addr_t)fID; + } + + virtual const char* Name() const + { + return fName; + } + +private: + sem_id fID; + const char* fName; +}; + + +class InitConditionVariable : public WaitObjectTraceEntry { +public: + InitConditionVariable(ConditionVariable* variable, const void* object, + const char* objectType) + : + fVariable(variable), + fObject(object), + fObjectType(alloc_tracing_buffer_strcpy(objectType, 128, false)) + { + Initialized(); + } + + virtual void AddDump(TraceOutput& out) + { + out.Print("cvar init variable %p: object: %p \"%s\"", fVariable, + fObject, fObjectType); + } + + virtual uint32 Type() const + { + return THREAD_BLOCK_TYPE_CONDITION_VARIABLE; + } + + virtual void* Object() const + { + return fVariable; + } + + virtual const char* Name() const + { + return fObjectType; + } + + virtual void* ReferencedObject() const + { + return (void*)fObject; + } + +private: + ConditionVariable* fVariable; + const void* fObject; + const char* fObjectType; +}; + + +class InitMutex : public WaitObjectTraceEntry { +public: + InitMutex(mutex* lock, const char* name) + : + fMutex(lock), + fName(alloc_tracing_buffer_strcpy(name, 128, false)) + { + Initialized(); + } + + virtual void AddDump(TraceOutput& out) + { + out.Print("mutex init %p: name: \"%s\"", fMutex, fName); + } + + virtual uint32 Type() const + { + return THREAD_BLOCK_TYPE_MUTEX; + } + + virtual void* Object() const + { + return fMutex; + } + + virtual const char* Name() const + { + return fName; + } + +private: + mutex* fMutex; + const char* fName; +}; + + +class InitRWLock : public WaitObjectTraceEntry { +public: + InitRWLock(rw_lock* lock, const char* name) + : + fLock(lock), + fName(alloc_tracing_buffer_strcpy(name, 128, false)) + { + Initialized(); + } + + virtual void AddDump(TraceOutput& out) + { + out.Print("rwlock init %p: name: \"%s\"", fLock, fName); + } + + virtual uint32 Type() const + { + return THREAD_BLOCK_TYPE_RW_LOCK; + } + + virtual void* Object() const + { + return fLock; + } + + virtual const char* Name() const + { + return fName; + } + +private: + rw_lock* fLock; + const char* fName; +}; + +} // namespace SchedulingAnalysisTracing + +# define T_SCHEDULING_ANALYSIS(x) \ + new(std::nothrow) SchedulingAnalysisTracing::x; +#else +# define T_SCHEDULING_ANALYSIS(x) ; +#endif // SCHEDULING_ANALYSIS_TRACING + +#endif // _KERNEL_SCHEDULING_ANALYSIS_H Added: haiku/trunk/headers/private/system/scheduler_defs.h =================================================================== --- haiku/trunk/headers/private/system/scheduler_defs.h 2008-09-03 14:53:01 UTC (rev 27303) +++ haiku/trunk/headers/private/system/scheduler_defs.h 2008-09-03 15:10:44 UTC (rev 27304) @@ -0,0 +1,64 @@ +/* + * Copyright 2008, Ingo Weinhold, ingo_weinhold at gmx.de. + * Distributed under the terms of the MIT License. + */ +#ifndef _SYSTEM_SCHEDULER_DEFS_H +#define _SYSTEM_SCHEDULER_DEFS_H + +#include + + +struct scheduling_analysis_thread_wait_object; + +struct scheduling_analysis_thread { + thread_id id; + char name[B_OS_NAME_LENGTH]; + + int64 runs; + bigtime_t total_run_time; + bigtime_t min_run_time; + bigtime_t max_run_time; + + int64 latencies; + bigtime_t total_latency; + bigtime_t min_latency; + bigtime_t max_latency; + + int64 reruns; + bigtime_t total_rerun_time; + bigtime_t min_rerun_time; + bigtime_t max_rerun_time; + + bigtime_t unspecified_wait_time; + + int64 preemptions; + + scheduling_analysis_thread_wait_object* wait_objects; +}; + + +struct scheduling_analysis_wait_object { + uint32 type; + void* object; + char name[B_OS_NAME_LENGTH]; + void* referenced_object; +}; + + +struct scheduling_analysis_thread_wait_object { + thread_id thread; + scheduling_analysis_wait_object* wait_object; + bigtime_t wait_time; + scheduling_analysis_thread_wait_object* next_in_list; +}; + + +struct scheduling_analysis { + uint32 thread_count; + scheduling_analysis_thread** threads; + uint64 wait_object_count; + uint64 thread_wait_object_count; +}; + + +#endif /* _SYSTEM_SCHEDULER_DEFS_H */ Modified: haiku/trunk/headers/private/system/syscalls.h =================================================================== --- haiku/trunk/headers/private/system/syscalls.h 2008-09-03 14:53:01 UTC (rev 27303) +++ haiku/trunk/headers/private/system/syscalls.h 2008-09-03 15:10:44 UTC (rev 27304) @@ -27,6 +27,7 @@ struct net_stat; struct pollfd; struct rlimit; +struct scheduling_analysis; struct sigaction; struct stat; struct _sem_t; @@ -394,6 +395,9 @@ /* System informations */ extern status_t _kern_get_system_info(system_info *info, size_t size); +extern status_t _kern_analyze_scheduling(bigtime_t from, bigtime_t until, + void* buffer, size_t size, + struct scheduling_analysis* analysis); /* Debug output */ extern void _kern_debug_output(const char *message); Modified: haiku/trunk/src/system/kernel/condition_variable.cpp =================================================================== --- haiku/trunk/src/system/kernel/condition_variable.cpp 2008-09-03 14:53:01 UTC (rev 27303) +++ haiku/trunk/src/system/kernel/condition_variable.cpp 2008-09-03 15:10:44 UTC (rev 27304) @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -187,6 +188,8 @@ fObject = object; fObjectType = objectType; new(&fEntries) EntryList; + + T_SCHEDULING_ANALYSIS(InitConditionVariable(this, object, objectType)); } @@ -199,6 +202,8 @@ fObjectType = objectType; new(&fEntries) EntryList; + T_SCHEDULING_ANALYSIS(InitConditionVariable(this, object, objectType)); + InterruptsLocker _; SpinLocker locker(sConditionVariablesLock); Modified: haiku/trunk/src/system/kernel/lock.cpp =================================================================== --- haiku/trunk/src/system/kernel/lock.cpp 2008-09-03 14:53:01 UTC (rev 27303) +++ haiku/trunk/src/system/kernel/lock.cpp 2008-09-03 15:10:44 UTC (rev 27304) @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -223,6 +224,8 @@ lock->writer_count = 0; lock->owner_count = 0; lock->flags = 0; + + T_SCHEDULING_ANALYSIS(InitRWLock(lock, name)); } @@ -236,6 +239,8 @@ lock->writer_count = 0; lock->owner_count = 0; lock->flags = flags & RW_LOCK_FLAG_CLONE_NAME; + + T_SCHEDULING_ANALYSIS(InitRWLock(lock, name)); } @@ -430,6 +435,8 @@ lock->count = 0; #endif lock->flags = 0; + + T_SCHEDULING_ANALYSIS(InitMutex(lock, name)); } @@ -444,6 +451,8 @@ lock->count = 0; #endif lock->flags = flags & MUTEX_FLAG_CLONE_NAME; + + T_SCHEDULING_ANALYSIS(InitMutex(lock, name)); } Modified: haiku/trunk/src/system/kernel/scheduler.cpp =================================================================== --- haiku/trunk/src/system/kernel/scheduler.cpp 2008-09-03 14:53:01 UTC (rev 27303) +++ haiku/trunk/src/system/kernel/scheduler.cpp 2008-09-03 15:10:44 UTC (rev 27304) @@ -1,4 +1,5 @@ /* + * Copyright 2008, Ingo Weinhold, ingo_weinhold at gmx.de. * Copyright 2002-2007, Axel D?rfler, axeld at pinc-software.de. * Copyright 2002, Angelo Mottola, a.mottola at libero.it. * Distributed under the terms of the MIT License. @@ -13,14 +14,19 @@ #include #include +#include +#include +#include +#include +#include #include +#include +#include +#include #include #include -#include -#include -#include -#include #include +#include #include @@ -45,6 +51,8 @@ thread_id ThreadID() const { return fID; } + virtual const char* Name() const = 0; + protected: thread_id fID; }; @@ -75,6 +83,11 @@ "next %ld)", fID, fName, fPriority, fPreviousID, fNextID); } + virtual const char* Name() const + { + return fName; + } + private: thread_id fPreviousID; thread_id fNextID; @@ -98,6 +111,11 @@ out.Print("scheduler remove %ld, priority %d", fID, fPriority); } + virtual const char* Name() const + { + return NULL; + } + private: uint8 fPriority; }; @@ -170,8 +188,16 @@ out.Print(")"); } - thread_id PreviousThreadID() const { return fPreviousID; } + virtual const char* Name() const + { + return fName; + } + thread_id PreviousThreadID() const { return fPreviousID; } + uint8 PreviousState() const { return fPreviousState; } + uint16 PreviousWaitObjectType() const { return fPreviousWaitObjectType; } + const void* PreviousWaitObject() const { return fPreviousWaitObject; } + private: thread_id fPreviousID; int32 fCPU; @@ -233,6 +259,20 @@ #if SCHEDULER_TRACING +namespace SchedulerTracing { + +enum ScheduleState { + RUNNING, + STILL_RUNNING, + PREEMPTED, + READY, + WAITING, + UNKNOWN +}; + +} + + static int cmd_scheduler(int argc, char** argv) { @@ -250,15 +290,6 @@ return 0; } - enum ScheduleState { - RUNNING, - STILL_RUNNING, - PREEMPTED, - READY, - WAITING, - UNKNOWN - }; - ScheduleState state = UNKNOWN; bigtime_t lastTime = 0; @@ -322,7 +353,7 @@ lastTime = entry->Time(); state = RUNNING; } - } else if (entry->PreviousThreadID() != threadID) { + } else if (entry->PreviousThreadID() == threadID) { // thread unscheduled bigtime_t diffTime = entry->Time() - lastTime; @@ -360,7 +391,7 @@ if (state == RUNNING || state == STILL_RUNNING) { // Thread was running and is reentered into the run queue. This - // is done by the scheduler, if the next thread remains ready. + // is done by the scheduler, if the thread remains ready. state = STILL_RUNNING; } else { // Thread was waiting and is ready now. @@ -691,3 +722,857 @@ RELEASE_THREAD_LOCK(); restore_interrupts(state); } + + +// #pragma mark - + + +#if SCHEDULER_TRACING + +namespace SchedulingAnalysis { + +using namespace SchedulerTracing; + +#if SCHEDULING_ANALYSIS_TRACING +using namespace SchedulingAnalysisTracing; +#endif + +struct ThreadWaitObject; + +struct HashObjectKey { + virtual ~HashObjectKey() + { + } + + virtual uint32 HashKey() const = 0; +}; + + +struct HashObject { + HashObject* next; + + virtual ~HashObject() + { + } + + virtual uint32 HashKey() const = 0; + virtual bool Equals(const HashObjectKey* key) const = 0; +}; + + +struct ThreadKey : HashObjectKey { + thread_id id; + + ThreadKey(thread_id id) + : + id(id) + { + } + + virtual uint32 HashKey() const + { + return id; + } +}; + + +struct Thread : HashObject, scheduling_analysis_thread { + ScheduleState state; + bigtime_t lastTime; + + ThreadWaitObject* waitObject; + + Thread(thread_id id) + : + state(UNKNOWN), + lastTime(0), + + waitObject(NULL) + { + this->id = id; + name[0] = '\0'; + + runs = 0; + total_run_time = 0; + min_run_time = 1; + max_run_time = -1; + + latencies = 0; + total_latency = 0; + min_latency = -1; + max_latency = -1; + + reruns = 0; + total_rerun_time = 0; + min_rerun_time = -1; + max_rerun_time = -1; + + unspecified_wait_time = 0; + + preemptions = 0; + + wait_objects = NULL; + } + + virtual uint32 HashKey() const + { + return id; + } + + virtual bool Equals(const HashObjectKey* _key) const + { + const ThreadKey* key = dynamic_cast(_key); + if (key == NULL) + return false; + return key->id == id; + } +}; + + +struct WaitObjectKey : HashObjectKey { + uint32 type; + void* object; + + WaitObjectKey(uint32 type, void* object) + : + type(type), + object(object) + { + } + + virtual uint32 HashKey() const + { + return type ^ (uint32)(addr_t)object; + } +}; + + +struct WaitObject : HashObject, scheduling_analysis_wait_object { + WaitObject(uint32 type, void* object) + { + this->type = type; + this->object = object; + name[0] = '\0'; + referenced_object = NULL; + } + + virtual uint32 HashKey() const + { + return type ^ (uint32)(addr_t)object; + } + + virtual bool Equals(const HashObjectKey* _key) const + { + const WaitObjectKey* key = dynamic_cast(_key); + if (key == NULL) + return false; + return key->type == type && key->object == object; + } +}; + + +struct ThreadWaitObjectKey : HashObjectKey { + thread_id thread; + uint32 type; + void* object; + + ThreadWaitObjectKey(thread_id thread, uint32 type, void* object) + : + thread(thread), + type(type), + object(object) + { + } + + virtual uint32 HashKey() const + { + return thread ^ type ^ (uint32)(addr_t)object; + } +}; + + +struct ThreadWaitObject : HashObject, scheduling_analysis_thread_wait_object { + ThreadWaitObject(thread_id thread, WaitObject* waitObject) + { + this->thread = thread; + wait_object = waitObject; + wait_time = 0; + next_in_list = NULL; + } + + virtual uint32 HashKey() const + { + return thread ^ wait_object->type ^ (uint32)(addr_t)wait_object->object; + } + + virtual bool Equals(const HashObjectKey* _key) const + { + const ThreadWaitObjectKey* key + = dynamic_cast(_key); + if (key == NULL) + return false; + return key->thread == thread && key->type == wait_object->type + && key->object == wait_object->object; + } +}; + + +class SchedulingAnalysisManager { +public: + SchedulingAnalysisManager(void* buffer, size_t size) + : + fBuffer(buffer), + fSize(size), + fHashTable(), + fHashTableSize(0) + { + fAnalysis.thread_count = 0; + fAnalysis.threads = 0; + fAnalysis.wait_object_count = 0; + fAnalysis.thread_wait_object_count = 0; + + size_t maxObjectSize = max_c(max_c(sizeof(Thread), sizeof(WaitObject)), + sizeof(ThreadWaitObject)); + fHashTableSize = size / (maxObjectSize + sizeof(HashObject*)); + fHashTable = (HashObject**)((uint8*)fBuffer + fSize) - fHashTableSize; + fNextAllocation = (uint8*)fBuffer; + fRemainingBytes = (addr_t)fHashTable - (addr_t)fBuffer; + + image_info info; + if (elf_get_image_info_for_address((addr_t)&scheduler_start, &info) + == B_OK) { + fKernelStart = (addr_t)info.text; + fKernelEnd = (addr_t)info.data + info.data_size; + } else { + fKernelStart = 0; + fKernelEnd = 0; + } + } + + const scheduling_analysis* Analysis() const + { + return &fAnalysis; + } + + void* Allocate(size_t size) + { + size = (size + 7) & ~(size_t)7; + + if (size > fRemainingBytes) + return NULL; + + void* address = fNextAllocation; + fNextAllocation += size; + fRemainingBytes -= size; + return address; + } + + void Insert(HashObject* object) + { + uint32 index = object->HashKey() % fHashTableSize; + object->next = fHashTable[index]; + fHashTable[index] = object; + } + + void Remove(HashObject* object) + { + uint32 index = object->HashKey() % fHashTableSize; + HashObject** slot = &fHashTable[index]; + while (*slot != object) + slot = &(*slot)->next; + + *slot = object->next; + } + + HashObject* Lookup(const HashObjectKey& key) const + { + uint32 index = key.HashKey() % fHashTableSize; + HashObject* object = fHashTable[index]; + while (object != NULL && !object->Equals(&key)) + object = object->next; + return object; + } + + Thread* ThreadFor(thread_id id) const + { + return dynamic_cast(Lookup(ThreadKey(id))); + } + + WaitObject* WaitObjectFor(uint32 type, void* object) const + { + return dynamic_cast(Lookup(WaitObjectKey(type, object))); + } + + ThreadWaitObject* ThreadWaitObjectFor(thread_id thread, uint32 type, + void* object) const + { + return dynamic_cast( + Lookup(ThreadWaitObjectKey(thread, type, object))); + } + + status_t AddThread(thread_id id, const char* name) + { + Thread* thread = ThreadFor(id); + if (thread == NULL) { + void* memory = Allocate(sizeof(Thread)); + if (memory == NULL) + return B_NO_MEMORY; + + thread = new(memory) Thread(id); + Insert(thread); + fAnalysis.thread_count++; + } + + if (name != NULL && thread->name[0] == '\0') + strlcpy(thread->name, name, sizeof(thread->name)); + + return B_OK; + } + + status_t AddWaitObject(uint32 type, void* object, + WaitObject** _waitObject = NULL) + { + if (WaitObjectFor(type, object) != NULL) + return B_OK; + + void* memory = Allocate(sizeof(WaitObject)); + if (memory == NULL) + return B_NO_MEMORY; + + WaitObject* waitObject = new(memory) WaitObject(type, object); + Insert(waitObject); + fAnalysis.wait_object_count++; + + // Set a dummy name for snooze() and waiting for signals, so we don't + // try to update them later on. + if (type == THREAD_BLOCK_TYPE_SNOOZE + || type == THREAD_BLOCK_TYPE_SIGNAL) { + strcpy(waitObject->name, "?"); + } + + if (_waitObject != NULL) + *_waitObject = waitObject; + + return B_OK; + } + + status_t UpdateWaitObject(uint32 type, void* object, const char* name, + void* referencedObject) + { + WaitObject* waitObject = WaitObjectFor(type, object); + if (waitObject == NULL) + return B_OK; + + if (waitObject->name[0] != '\0') { + // This is a new object at the same address. Replace the old one. + Remove(waitObject); + status_t error = AddWaitObject(type, object, &waitObject); + if (error != B_OK) + return error; + } + + if (name == NULL) + name = "?"; + + strlcpy(waitObject->name, name, sizeof(waitObject->name)); + waitObject->referenced_object = referencedObject; + + return B_OK; + } + + bool UpdateWaitObjectDontAdd(uint32 type, void* object, const char* name, + void* referencedObject) + { + WaitObject* waitObject = WaitObjectFor(type, object); + if (waitObject == NULL || waitObject->name[0] != '\0') + return false; + + if (name == NULL) + name = "?"; + + strlcpy(waitObject->name, name, sizeof(waitObject->name)); + waitObject->referenced_object = referencedObject; + + return B_OK; + } + + status_t AddThreadWaitObject(Thread* thread, uint32 type, void* object) + { + WaitObject* waitObject = WaitObjectFor(type, object); + if (waitObject == NULL) { + // The algorithm should prevent this case. + return B_ERROR; + } + + ThreadWaitObject* threadWaitObject = ThreadWaitObjectFor(thread->id, + type, object); + if (threadWaitObject == NULL + || threadWaitObject->wait_object != waitObject) { + if (threadWaitObject != NULL) + Remove(threadWaitObject); + + void* memory = Allocate(sizeof(ThreadWaitObject)); + if (memory == NULL) + return B_NO_MEMORY; + + threadWaitObject = new(memory) ThreadWaitObject(thread->id, + waitObject); + Insert(threadWaitObject); + fAnalysis.thread_wait_object_count++; + + threadWaitObject->next_in_list = thread->wait_objects; + thread->wait_objects = threadWaitObject; + } + + thread->waitObject = threadWaitObject; + + return B_OK; + } + + int32 MissingWaitObjects() const + { + // Iterate through the hash table and count the wait objects that don't + // have a name yet. + int32 count = 0; + for (uint32 i = 0; i < fHashTableSize; i++) { + HashObject* object = fHashTable[i]; + while (object != NULL) { + WaitObject* waitObject = dynamic_cast(object); + if (waitObject != NULL && waitObject->name[0] == '\0') + count++; + + object = object->next; + } + } + + return count; + } + + status_t FinishAnalysis() + { + // allocate the thread array + scheduling_analysis_thread** threads + = (scheduling_analysis_thread**)Allocate( + sizeof(Thread*) * fAnalysis.thread_count); + if (threads == NULL) + return B_NO_MEMORY; + + // Iterate through the hash table and collect all threads. Also polish + // all wait objects that haven't been update yet. + int32 index = 0; + for (uint32 i = 0; i < fHashTableSize; i++) { + HashObject* object = fHashTable[i]; + while (object != NULL) { + Thread* thread = dynamic_cast(object); + if (thread != NULL) { + threads[index++] = thread; + } else if (WaitObject* waitObject + = dynamic_cast(object)) { + _PolishWaitObject(waitObject); + } + + object = object->next; + } + } + + fAnalysis.threads = threads; +dprintf("scheduling analysis: free bytes: %lu/%lu\n", fRemainingBytes, fSize); + return B_OK; + } + [... truncated: 419 lines follow ...] From bonefish at mail.berlios.de Wed Sep 3 17:11:42 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Wed, 3 Sep 2008 17:11:42 +0200 Subject: [Haiku-commits] r27305 - haiku/trunk/build/config_headers Message-ID: <200809031511.m83FBgde027144@sheep.berlios.de> Author: bonefish Date: 2008-09-03 17:11:41 +0200 (Wed, 03 Sep 2008) New Revision: 27305 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27305&view=rev Modified: haiku/trunk/build/config_headers/tracing_config.h Log: Macro for additional scheduling analysis tracing. Modified: haiku/trunk/build/config_headers/tracing_config.h =================================================================== --- haiku/trunk/build/config_headers/tracing_config.h 2008-09-03 15:10:44 UTC (rev 27304) +++ haiku/trunk/build/config_headers/tracing_config.h 2008-09-03 15:11:41 UTC (rev 27305) @@ -35,6 +35,7 @@ #define NET_BUFFER_TRACING_STACK_TRACE 0 /* stack trace depth */ #define RUNTIME_LOADER_TRACING 0 #define SCHEDULER_TRACING 0 +#define SCHEDULING_ANALYSIS_TRACING 0 #define SIGNAL_TRACING 0 #define SWAP_TRACING 0 #define SYSCALL_TRACING 0 From bonefish at mail.berlios.de Wed Sep 3 17:15:21 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Wed, 3 Sep 2008 17:15:21 +0200 Subject: [Haiku-commits] r27306 - haiku/trunk/src/tests/system/kernel Message-ID: <200809031515.m83FFL0N027759@sheep.berlios.de> Author: bonefish Date: 2008-09-03 17:15:19 +0200 (Wed, 03 Sep 2008) New Revision: 27306 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27306&view=rev Modified: haiku/trunk/src/tests/system/kernel/Jamfile haiku/trunk/src/tests/system/kernel/time_stats.cpp Log: * Added "-s" option, which uses the new scheduling analysis feature to gather additional information on the threads that were running and what they were doing. * Added "-o " option for specifying a file to which to print the statistics to. * Some beautifications (usage, help, etc.). Modified: haiku/trunk/src/tests/system/kernel/Jamfile =================================================================== --- haiku/trunk/src/tests/system/kernel/Jamfile 2008-09-03 15:11:41 UTC (rev 27305) +++ haiku/trunk/src/tests/system/kernel/Jamfile 2008-09-03 15:15:19 UTC (rev 27306) @@ -1,6 +1,7 @@ SubDir HAIKU_TOP src tests system kernel ; UsePrivateKernelHeaders ; +UsePrivateHeaders shared ; SimpleTest advisory_locking_test : advisory_locking_test.cpp ; Modified: haiku/trunk/src/tests/system/kernel/time_stats.cpp =================================================================== --- haiku/trunk/src/tests/system/kernel/time_stats.cpp 2008-09-03 15:11:41 UTC (rev 27305) +++ haiku/trunk/src/tests/system/kernel/time_stats.cpp 2008-09-03 15:15:19 UTC (rev 27306) @@ -4,9 +4,12 @@ */ #include +#include +#include #include #include #include +#include #include #include @@ -14,10 +17,33 @@ #include +#include +#include +#include +#include + + #define MAX_THREADS 4096 +#define SCHEDULING_ANALYSIS_BUFFER_SIZE 10 * 1024 * 1024 + +extern const char* __progname; + +static const char* kUsage = + "Usage: %s [ -h ] [ -o ] [ -s ] \n" +; + + +static void +print_usage_and_exit(bool error) +{ + fprintf(error ? stderr : stdout, kUsage, __progname); + exit(error ? 1 : 0); +} + + struct UsageInfoThreadComparator { inline bool operator()(const thread_info& a, const thread_info& b) { @@ -53,29 +79,19 @@ } -int -main(int argc, const char* const* argv) +static pid_t +run_child(int argc, const char* const* argv) { - if (argc < 2) { - fprintf(stderr, "Usage:...\n"); - exit(1); - } - - // gather initial usage info - thread_info initialUsage[MAX_THREADS]; - int32 initialUsageCount = get_usage_infos(initialUsage); - // fork - bigtime_t startTime = system_time(); pid_t child = fork(); if (child < 0) { - fprintf(stderr, "fork() failed: %s\n", strerror(errno)); + fprintf(stderr, "Error: fork() failed: %s\n", strerror(errno)); exit(1); } // exec child process if (child == 0) { - execvp(argv[1], (char**)(argv + 1)); + execvp(argv[0], (char**)argv); exit(1); } @@ -83,8 +99,128 @@ int childStatus; while (wait(&childStatus) < 0); + return child; +} + + +static const char* +wait_object_to_string(scheduling_analysis_wait_object* waitObject, char* buffer) +{ + uint32 type = waitObject->type; + void* object = waitObject->object; + + switch (type) { + case THREAD_BLOCK_TYPE_SEMAPHORE: + sprintf(buffer, "sem %ld (%s)", (sem_id)(addr_t)object, + waitObject->name); + break; + case THREAD_BLOCK_TYPE_CONDITION_VARIABLE: + sprintf(buffer, "cvar %p (%s %p)", object, waitObject->name, + waitObject->referenced_object); + break; + case THREAD_BLOCK_TYPE_SNOOZE: + strcpy(buffer, "snooze"); + break; + case THREAD_BLOCK_TYPE_SIGNAL: + strcpy(buffer, "signal"); + break; + case THREAD_BLOCK_TYPE_MUTEX: + sprintf(buffer, "mutex %p (%s)", object, waitObject->name); + break; + case THREAD_BLOCK_TYPE_RW_LOCK: + sprintf(buffer, "rwlock %p (%s)", object, waitObject->name); + break; + case THREAD_BLOCK_TYPE_OTHER: + sprintf(buffer, "other %p", object); + break; + default: + sprintf(buffer, "unknown %p", object); + break; + } + + return buffer; +} + + +static void +do_scheduling_analysis(bigtime_t startTime, bigtime_t endTime) +{ + printf("\n"); + + // allocate a chunk of memory for the scheduling analysis + void* buffer = malloc(SCHEDULING_ANALYSIS_BUFFER_SIZE); + if (buffer == NULL) { + fprintf(stderr, "Error: Failed to allocate memory for the scheduling " + "analysis.\n"); + exit(1); + } + MemoryDeleter _(buffer); + + // do the scheduling analysis + scheduling_analysis analysis; + status_t error = _kern_analyze_scheduling(startTime, endTime, buffer, + SCHEDULING_ANALYSIS_BUFFER_SIZE, &analysis); + if (error != B_OK) { + fprintf(stderr, "Error: Scheduling analysis failed: %s\n", + strerror(error)); + exit(1); + } + + printf("scheduling analysis: %lu threads, %llu wait objects, " + "%llu thread wait objects\n", analysis.thread_count, + analysis.wait_object_count, analysis.thread_wait_object_count); + + for (uint32 i = 0; i < analysis.thread_count; i++) { + scheduling_analysis_thread* thread = analysis.threads[i]; + + // compute total wait time + bigtime_t waitTime = 0; + scheduling_analysis_thread_wait_object* threadWaitObject + = thread->wait_objects; + while (threadWaitObject != NULL) { + waitTime += threadWaitObject->wait_time; + threadWaitObject = threadWaitObject->next_in_list; + } + + printf("\nthread %ld \"%s\":\n", thread->id, thread->name); + printf(" run time: %lld us (%lld runs)\n", thread->total_run_time, + thread->runs); + printf(" wait time: %lld us\n", waitTime); + printf(" latencies: %lld us (%lld)\n", thread->total_latency, + thread->latencies); + printf(" preemptions: %lld us (%lld)\n", thread->total_rerun_time, + thread->reruns); + printf(" unspecified: %lld us\n", thread->unspecified_wait_time); + printf(" waited on:\n"); + threadWaitObject = thread->wait_objects; + while (threadWaitObject != NULL) { + scheduling_analysis_wait_object* waitObject + = threadWaitObject->wait_object; + char buffer[1024]; + wait_object_to_string(waitObject, buffer); + printf(" %s: %lld us\n", buffer, threadWaitObject->wait_time); + + threadWaitObject = threadWaitObject->next_in_list; + } + } +} + + +static void +do_timing_analysis(int argc, const char* const* argv, bool schedulingAnalysis, + int outFD) +{ + // gather initial usage info + thread_info initialUsage[MAX_THREADS]; + int32 initialUsageCount = get_usage_infos(initialUsage); + + // exec child process + bigtime_t startTime = system_time(); + pid_t child = run_child(argc, argv); + // get child usage info - bigtime_t runTime = system_time() - startTime; + bigtime_t endTime = system_time(); + bigtime_t runTime = endTime - startTime; team_usage_info childUsage; get_team_usage_info(B_CURRENT_TEAM, B_TEAM_USAGE_CHILDREN, &childUsage); @@ -154,6 +290,10 @@ std::sort(sortedThreads, sortedThreads + sortedThreadCount, UsageInfoTimeComparator()); + // redirect output, if requested + if (outFD >= 0) + dup2(outFD, STDOUT_FILENO); + // print results printf("\nTotal run time: %lld us\n", runTime); printf("Thread time statistics in us:\n\n"); @@ -186,5 +326,62 @@ printf("%7ld %-32s \n", info.thread, info.name); } + if (schedulingAnalysis) + do_scheduling_analysis(startTime, endTime); +} + + +int +main(int argc, const char* const* argv) +{ + const char* outputFile = NULL; + bool schedulingAnalysis = false; + + while (true) { + static struct option sLongOptions[] = { + { "help", no_argument, 0, 'h' }, + { "output", required_argument, 0, 'o' }, + { 0, 0, 0, 0 } + }; + + opterr = 0; // don't print errors + int c = getopt_long(argc, (char**)argv, "ho:s", sLongOptions, NULL); + if (c == -1) + break; + + switch (c) { + case 'h': + print_usage_and_exit(false); + break; + case 'o': + outputFile = optarg; + break; + case 's': + schedulingAnalysis = true; + break; + + default: + print_usage_and_exit(true); + break; + } + } + + if (optind >= argc) + print_usage_and_exit(true); + + // open output file, if specified + int outFD = -1; + if (outputFile != NULL) { + outFD = open(outputFile, O_WRONLY | O_CREAT | O_TRUNC, + S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP| S_IROTH | S_IWOTH); + if (outFD < 0) { + fprintf(stderr, "Error: Failed to open \"%s\": %s\n", outputFile, + strerror(errno)); + exit(1); + } + } + + do_timing_analysis(argc - optind, argv + optind, schedulingAnalysis, outFD); + return 0; } From korli at mail.berlios.de Wed Sep 3 20:59:13 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Wed, 3 Sep 2008 20:59:13 +0200 Subject: [Haiku-commits] r27307 - haiku/trunk/src/system/libroot/posix/glibc/arch/m68k Message-ID: <200809031859.m83IxDYg013836@sheep.berlios.de> Author: korli Date: 2008-09-03 20:59:12 +0200 (Wed, 03 Sep 2008) New Revision: 27307 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27307&view=rev Modified: haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/Jamfile Log: I forgot that m68k build doesn't include long double versions of functions Modified: haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/Jamfile =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/Jamfile 2008-09-03 15:15:19 UTC (rev 27306) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/Jamfile 2008-09-03 18:59:12 UTC (rev 27307) @@ -141,7 +141,7 @@ e_sqrt.c e_sqrtf.c # e_sqrtl.c # s_fdim.c s_fdimf.c # s_fdiml.S # s_fabs.S s_fabsf.S # s_fabsl.S - s_fpclassifyl.c + # s_fpclassifyl.c # s_isnan.c s_isnanf.S s_rint.c s_rintf.c # s_rintl.c # t_sqrt.c From korli at mail.berlios.de Wed Sep 3 21:12:18 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Wed, 3 Sep 2008 21:12:18 +0200 Subject: [Haiku-commits] r27308 - haiku/trunk/src/servers/input Message-ID: <200809031912.m83JCIc3014876@sheep.berlios.de> Author: korli Date: 2008-09-03 21:12:18 +0200 (Wed, 03 Sep 2008) New Revision: 27308 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27308&view=rev Modified: haiku/trunk/src/servers/input/InputServer.cpp Log: print errors when starting devices Modified: haiku/trunk/src/servers/input/InputServer.cpp =================================================================== --- haiku/trunk/src/servers/input/InputServer.cpp 2008-09-03 18:59:12 UTC (rev 27307) +++ haiku/trunk/src/servers/input/InputServer.cpp 2008-09-03 19:12:18 UTC (rev 27308) @@ -80,7 +80,10 @@ InputDeviceListItem::Start() { PRINT((" Starting: %s\n", fDevice.name)); - fServerDevice->Start(fDevice.name, fDevice.cookie); + status_t err = fServerDevice->Start(fDevice.name, fDevice.cookie); + if (err != B_OK) { + PRINTERR((" error: %s (%lx)\n", strerror(err), err)); + } fRunning = true; } From korli at mail.berlios.de Wed Sep 3 21:14:38 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Wed, 3 Sep 2008 21:14:38 +0200 Subject: [Haiku-commits] r27309 - haiku/trunk/src/add-ons/input_server/devices/mouse Message-ID: <200809031914.m83JEcb2015243@sheep.berlios.de> Author: korli Date: 2008-09-03 21:14:37 +0200 (Wed, 03 Sep 2008) New Revision: 27309 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27309&view=rev Modified: haiku/trunk/src/add-ons/input_server/devices/mouse/MouseInputDevice.cpp haiku/trunk/src/add-ons/input_server/devices/mouse/MouseInputDevice.h Log: fix debug build on Stop(), close the device, then wait for our service thread to quit Modified: haiku/trunk/src/add-ons/input_server/devices/mouse/MouseInputDevice.cpp =================================================================== --- haiku/trunk/src/add-ons/input_server/devices/mouse/MouseInputDevice.cpp 2008-09-03 19:12:18 UTC (rev 27308) +++ haiku/trunk/src/add-ons/input_server/devices/mouse/MouseInputDevice.cpp 2008-09-03 19:14:37 UTC (rev 27309) @@ -175,6 +175,9 @@ void MouseDevice::Stop() { + close(fDevice); + fDevice = -1; + fActive = false; // this will stop the thread as soon as it reads the next packet @@ -186,8 +189,6 @@ status_t dummy; wait_for_thread(fThread, &dummy); } - - close(fDevice); } @@ -251,9 +252,9 @@ _ComputeAcceleration(movements, deltaX, deltaY); LOG("%s: buttons: 0x%lx, x: %ld, y: %ld, clicks:%ld, wheel_x:%ld, wheel_y:%ld\n", - device->device_ref.name, movements.buttons, movements.xdelta, movements.ydelta, + fDeviceRef.name, movements.buttons, movements.xdelta, movements.ydelta, movements.clicks, movements.wheel_xdelta, movements.wheel_ydelta); - LOG("%s: x: %ld, y: %ld\n", device->device_ref.name, deltaX, deltaY); + LOG("%s: x: %ld, y: %ld\n", fDeviceRef.name, deltaX, deltaY); BMessage *message = NULL; Modified: haiku/trunk/src/add-ons/input_server/devices/mouse/MouseInputDevice.h =================================================================== --- haiku/trunk/src/add-ons/input_server/devices/mouse/MouseInputDevice.h 2008-09-03 19:12:18 UTC (rev 27308) +++ haiku/trunk/src/add-ons/input_server/devices/mouse/MouseInputDevice.h 2008-09-03 19:14:37 UTC (rev 27309) @@ -13,13 +13,15 @@ #include #include +#include + class MouseDevice; class MouseInputDevice : public BInputServerDevice { public: MouseInputDevice(); - ~MouseInputDevice(); + virtual ~MouseInputDevice(); virtual status_t InitCheck(); From korli at mail.berlios.de Wed Sep 3 21:18:42 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Wed, 3 Sep 2008 21:18:42 +0200 Subject: [Haiku-commits] r27310 - haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid Message-ID: <200809031918.m83JIgIb015571@sheep.berlios.de> Author: korli Date: 2008-09-03 21:18:42 +0200 (Wed, 03 Sep 2008) New Revision: 27310 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27310&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/Driver.cpp haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/MouseDevice.cpp Log: * on freeing, only remove the device when it is removed * check if the device is still opened when waiting for data Modified: haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/Driver.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/Driver.cpp 2008-09-03 19:14:37 UTC (rev 27309) +++ haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/Driver.cpp 2008-09-03 19:18:42 UTC (rev 27310) @@ -191,7 +191,8 @@ HIDDevice *device = (HIDDevice *)cookie; mutex_lock(&sDriverLock); status_t status = device->Free(); - if (gDeviceList->RemoveDevice(NULL, device) == B_OK) { + if (device->IsRemoved() + && gDeviceList->RemoveDevice(NULL, device) == B_OK) { // the device is removed already but as it was open the removed hook // has not deleted the object delete device; Modified: haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/MouseDevice.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/MouseDevice.cpp 2008-09-03 19:14:37 UTC (rev 27309) +++ haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/MouseDevice.cpp 2008-09-03 19:18:42 UTC (rev 27310) @@ -46,7 +46,7 @@ // released in the callback function status_t result = acquire_sem_etc(fTransferNotifySem, 1, B_CAN_INTERRUPT, 0); - if (result == B_INTERRUPTED) + if (result == B_INTERRUPTED && IsOpen()) continue; else if (result != B_OK) return result; From korli at mail.berlios.de Wed Sep 3 22:58:19 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Wed, 3 Sep 2008 22:58:19 +0200 Subject: [Haiku-commits] r27311 - haiku/trunk/src/servers/input Message-ID: <200809032058.m83KwJib023754@sheep.berlios.de> Author: korli Date: 2008-09-03 22:58:19 +0200 (Wed, 03 Sep 2008) New Revision: 27311 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27311&view=rev Modified: haiku/trunk/src/servers/input/InputServer.cpp Log: fix warnings white space cleanup Modified: haiku/trunk/src/servers/input/InputServer.cpp =================================================================== --- haiku/trunk/src/servers/input/InputServer.cpp 2008-09-03 19:18:42 UTC (rev 27310) +++ haiku/trunk/src/servers/input/InputServer.cpp 2008-09-03 20:58:19 UTC (rev 27311) @@ -480,8 +480,8 @@ BMessage reply; status_t status = B_OK; - PRINT(("%s what:%c%c%c%c\n", __PRETTY_FUNCTION__, message->what >> 24, - message->what >> 16, message->what >> 8, message->what)); + PRINT(("%s what:%c%c%c%c\n", __PRETTY_FUNCTION__, (char)(message->what >> 24), + (char)(message->what >> 16), (char)(message->what >> 8), (char)message->what)); switch (message->what) { case IS_SET_METHOD: @@ -973,8 +973,8 @@ InputServer::EnqueueMethodMessage(BMessage* message) { CALLED(); - PRINT(("%s what:%c%c%c%c\n", __PRETTY_FUNCTION__, message->what >> 24, - message->what >> 16, message->what >> 8, message->what)); + PRINT(("%s what:%c%c%c%c\n", __PRETTY_FUNCTION__, (char)(message->what >> 24), + (char)(message->what >> 16), (char)(message->what >> 8), (char)message->what)); #ifdef DEBUG if (message->what == 'IMEV') { @@ -1327,7 +1327,7 @@ CALLED(); fEventLooperPort = create_port(100, "input server events"); if (fEventLooperPort < 0) { - PRINTERR(("InputServer: create_port error: (0x%x) %s\n", + PRINTERR(("InputServer: create_port error: (0x%lx) %s\n", fEventLooperPort, strerror(fEventLooperPort))); return fEventLooperPort; } @@ -1460,8 +1460,8 @@ int32 x, y; float absX, absY; - if (event->FindInt32("x", &x) == B_OK - && event->FindInt32("y", &y) == B_OK) { + if (event->FindInt32("x", &x) == B_OK + && event->FindInt32("y", &y) == B_OK) { fMousePos.x += x; fMousePos.y -= y; fMousePos.ConstrainTo(fFrame); @@ -1474,23 +1474,23 @@ PRINT(("new position: %f, %f, %ld, %ld\n", fMousePos.x, fMousePos.y, x, y)); - } else if (event->FindFloat("x", &absX) == B_OK - && event->FindFloat("y", &absY) == B_OK) { - // device gives us absolute screen coords - // in range 0..1 - // convert to absolute screen pos - // (the message is supposed to contain the original - // absolute coordinates as "be:tablet_x/y") - fMousePos.x = absX * fFrame.Width(); - fMousePos.y = absY * fFrame.Height(); + } else if (event->FindFloat("x", &absX) == B_OK + && event->FindFloat("y", &absY) == B_OK) { + // device gives us absolute screen coords + // in range 0..1 + // convert to absolute screen pos + // (the message is supposed to contain the original + // absolute coordinates as "be:tablet_x/y") + fMousePos.x = absX * fFrame.Width(); + fMousePos.y = absY * fFrame.Height(); fMousePos.ConstrainTo(fFrame); event->RemoveName("x"); event->RemoveName("y"); event->AddPoint("where", fMousePos); PRINT(("new position : %f, %f\n", fMousePos.x, fMousePos.y)); - } else if (event->FindPoint("where", &where) == B_OK) { - fMousePos = where; + } else if (event->FindPoint("where", &where) == B_OK) { + fMousePos = where; fMousePos.ConstrainTo(fFrame); event->ReplacePoint("where", fMousePos); @@ -1531,7 +1531,7 @@ // to next input method // (pressing "shift" will let us switch to the previous method) - PRINT(("SanitizeEvents: %lx, %lx\n", fKeyInfo.modifiers, + PRINT(("SanitizeEvents: %lx, %x\n", fKeyInfo.modifiers, fKeyInfo.key_states[KEY_Spacebar >> 3])); uint8 byte; From teammaui at web.de Wed Sep 3 23:15:25 2008 From: teammaui at web.de (=?utf-8?Q?Ralf_Sch=C3=BClke?=) Date: Wed, 03 Sep 2008 23:15:25 +0200 Subject: [Haiku-commits] r27299 - haiku/trunk/src/apps/aboutsystem In-Reply-To: <200809031340.m83Deuh8018471@sheep.berlios.de> References: <200809031340.m83Deuh8018471@sheep.berlios.de> Message-ID: On Wed, 03 Sep 2008 15:40:56 +0200, stippi at BerliOS wrote: > * Added Ralf Schuelke to the Contributors for his Pairs game > contribution. WoW, nice, thank you. -- Ralf Sch?lke aka stargater From ingo_weinhold at gmx.de Wed Sep 3 23:21:33 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Wed, 03 Sep 2008 23:21:33 +0200 Subject: [Haiku-commits] r27268 - haiku/trunk/src/system/kernel/posix In-Reply-To: References: <200809011616.m81GG3N6001985@sheep.berlios.de> <20080902141010.632.3@knochen-vm.localdomain> <20080902152256.728.4@knochen-vm.localdomain> <20080903145432.490.1@knochen-vm.localdomain> <20080903153950.463.3@knochen-vm.localdomain> <20080903154655.1820.8@stippis2.1220433860.fake> <20080903163738.550.4@knochen-vm.localdomain> Message-ID: <20080903232133.510.1@knochen-vm.localdomain> On 2008-09-03 at 16:47:25 [+0200], Salvatore Benedetto wrote: > As for now there is a limit of MAX_XSI_SEMAPHORE set to 2048, which is > the total number > of semaphores (not sets) that one create in the system. It's a static > limit of course, > and in the future could be based on available memory. We could add a > limit to the > total number of set as well and prevent any sort of bad situation from > happening. I guess we'll have to see what ports actually use XSI semaphores and how. For now the limit is fine. > Of course the limit must be lower than the maximun value the counter can > reach. The two aren't really related. The counter wouldn't be a unique identification anyway. It's just a means to keep the probability for this weird race condition low. CU, Ingo From emitrax at gmail.com Wed Sep 3 23:24:27 2008 From: emitrax at gmail.com (Salvatore Benedetto) Date: Wed, 3 Sep 2008 21:24:27 +0000 Subject: [Haiku-commits] r27268 - haiku/trunk/src/system/kernel/posix In-Reply-To: <20080903232133.510.1@knochen-vm.localdomain> References: <200809011616.m81GG3N6001985@sheep.berlios.de> <20080902152256.728.4@knochen-vm.localdomain> <20080903145432.490.1@knochen-vm.localdomain> <20080903153950.463.3@knochen-vm.localdomain> <20080903154655.1820.8@stippis2.1220433860.fake> <20080903163738.550.4@knochen-vm.localdomain> <20080903232133.510.1@knochen-vm.localdomain> Message-ID: 2008/9/3 Ingo Weinhold : > > On 2008-09-03 at 16:47:25 [+0200], Salvatore Benedetto > wrote: >> As for now there is a limit of MAX_XSI_SEMAPHORE set to 2048, which is >> the total number >> of semaphores (not sets) that one create in the system. It's a static >> limit of course, >> and in the future could be based on available memory. We could add a >> limit to the >> total number of set as well and prevent any sort of bad situation from >> happening. > > I guess we'll have to see what ports actually use XSI semaphores and how. For > now the limit is fine. I agree. > >> Of course the limit must be lower than the maximun value the counter can >> reach. > > The two aren't really related. The counter wouldn't be a unique > identification anyway. It's just a means to keep the probability for this > weird race condition low. The way I generate ID is just wrong. I knew that from the start, but I didn't think it would cause such as trouble. I'm going to re-see that part, since the same problem is obviously going to be reproduced in the other IPC subsystems. Regards, -- Salvatore Benedetto (a.k.a. emitrax) Student of Computer Engineer University of Pisa www.haiku-os.it From bonefish at mail.berlios.de Thu Sep 4 02:07:13 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Thu, 4 Sep 2008 02:07:13 +0200 Subject: [Haiku-commits] r27312 - in haiku/trunk: headers/private/system src/system/kernel Message-ID: <200809040007.m8407DsC004834@sheep.berlios.de> Author: bonefish Date: 2008-09-04 02:07:11 +0200 (Thu, 04 Sep 2008) New Revision: 27312 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27312&view=rev Modified: haiku/trunk/headers/private/system/scheduler_defs.h haiku/trunk/src/system/kernel/scheduler.cpp Log: Scheduling analysis: Also record the number of times a thread waits on a locking primitive. Modified: haiku/trunk/headers/private/system/scheduler_defs.h =================================================================== --- haiku/trunk/headers/private/system/scheduler_defs.h 2008-09-03 20:58:19 UTC (rev 27311) +++ haiku/trunk/headers/private/system/scheduler_defs.h 2008-09-04 00:07:11 UTC (rev 27312) @@ -49,6 +49,7 @@ thread_id thread; scheduling_analysis_wait_object* wait_object; bigtime_t wait_time; + int64 waits; scheduling_analysis_thread_wait_object* next_in_list; }; Modified: haiku/trunk/src/system/kernel/scheduler.cpp =================================================================== --- haiku/trunk/src/system/kernel/scheduler.cpp 2008-09-03 20:58:19 UTC (rev 27311) +++ haiku/trunk/src/system/kernel/scheduler.cpp 2008-09-04 00:07:11 UTC (rev 27312) @@ -897,6 +897,7 @@ this->thread = thread; wait_object = waitObject; wait_time = 0; + waits = 0; next_in_list = NULL; } @@ -1467,6 +1468,7 @@ bigtime_t diffTime = entry->Time() - thread->lastTime; if (thread->waitObject != NULL) { thread->waitObject->wait_time += diffTime; + thread->waitObject->waits++; thread->waitObject = NULL; } else if (thread->state != UNKNOWN) thread->unspecified_wait_time += diffTime; From bonefish at mail.berlios.de Thu Sep 4 02:13:54 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Thu, 4 Sep 2008 02:13:54 +0200 Subject: [Haiku-commits] r27313 - haiku/trunk/src/tests/system/kernel Message-ID: <200809040013.m840DsaX006474@sheep.berlios.de> Author: bonefish Date: 2008-09-04 02:13:53 +0200 (Thu, 04 Sep 2008) New Revision: 27313 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27313&view=rev Modified: haiku/trunk/src/tests/system/kernel/time_stats.cpp Log: * In the timing table user and kernel time were swapped. * Scheduling analysis output: - Sort the threads by total run time. - Group the locking primitives a thread has waited on by common type and name. E.g. all "I/O request finished" condition variables are put in a single group. The sum wait time and wait count is printed for the group, so it is easy to see how often and how long the thread had waited for I/O. - Both the groups and their elements are sorted by wait time. Modified: haiku/trunk/src/tests/system/kernel/time_stats.cpp =================================================================== --- haiku/trunk/src/tests/system/kernel/time_stats.cpp 2008-09-04 00:07:11 UTC (rev 27312) +++ haiku/trunk/src/tests/system/kernel/time_stats.cpp 2008-09-04 00:13:53 UTC (rev 27313) @@ -60,6 +60,51 @@ }; +struct wait_object_group { + scheduling_analysis_thread_wait_object** objects; + int32 count; + bigtime_t wait_time; + int64 waits; +}; + +struct ThreadRunTimeComparator { + inline bool operator()(const scheduling_analysis_thread* a, + const scheduling_analysis_thread* b) + { + return a->total_run_time > b->total_run_time; + } +}; + + +struct WaitObjectGroupingComparator { + inline bool operator()(const scheduling_analysis_thread_wait_object* a, + const scheduling_analysis_thread_wait_object* b) + { + return a->wait_object->type < b->wait_object->type + || a->wait_object->type == b->wait_object->type + && strcmp(a->wait_object->name, b->wait_object->name) < 0; + } +}; + + +struct WaitObjectTimeComparator { + inline bool operator()(const scheduling_analysis_thread_wait_object* a, + const scheduling_analysis_thread_wait_object* b) + { + return a->wait_time > b->wait_time; + } +}; + + +struct WaitObjectGroupTimeComparator { + inline bool operator()(const wait_object_group& a, + const wait_object_group& b) + { + return a.wait_time > b.wait_time; + } +}; + + static int32 get_usage_infos(thread_info* infos) { @@ -104,19 +149,28 @@ static const char* -wait_object_to_string(scheduling_analysis_wait_object* waitObject, char* buffer) +wait_object_to_string(scheduling_analysis_wait_object* waitObject, char* buffer, + bool nameOnly = false) { uint32 type = waitObject->type; void* object = waitObject->object; switch (type) { case THREAD_BLOCK_TYPE_SEMAPHORE: - sprintf(buffer, "sem %ld (%s)", (sem_id)(addr_t)object, - waitObject->name); + if (nameOnly) { + sprintf(buffer, "sem \"%s\"", waitObject->name); + } else { + sprintf(buffer, "sem %ld (%s)", (sem_id)(addr_t)object, + waitObject->name); + } break; case THREAD_BLOCK_TYPE_CONDITION_VARIABLE: - sprintf(buffer, "cvar %p (%s %p)", object, waitObject->name, - waitObject->referenced_object); + if (nameOnly) { + sprintf(buffer, "cvar \"%s\"", waitObject->name); + } else { + sprintf(buffer, "cvar %p (%s %p)", object, waitObject->name, + waitObject->referenced_object); + } break; case THREAD_BLOCK_TYPE_SNOOZE: strcpy(buffer, "snooze"); @@ -125,13 +179,19 @@ strcpy(buffer, "signal"); break; case THREAD_BLOCK_TYPE_MUTEX: - sprintf(buffer, "mutex %p (%s)", object, waitObject->name); + if (nameOnly) + sprintf(buffer, "mutex \"%s\"", waitObject->name); + else + sprintf(buffer, "mutex %p (%s)", object, waitObject->name); break; case THREAD_BLOCK_TYPE_RW_LOCK: - sprintf(buffer, "rwlock %p (%s)", object, waitObject->name); + if (nameOnly) + sprintf(buffer, "rwlock \"%s\"", waitObject->name); + else + sprintf(buffer, "rwlock %p (%s)", object, waitObject->name); break; case THREAD_BLOCK_TYPE_OTHER: - sprintf(buffer, "other %p", object); + sprintf(buffer, "other %p (%s)", object, waitObject->name); break; default: sprintf(buffer, "unknown %p", object); @@ -166,22 +226,77 @@ exit(1); } + // allocate arrays for grouping and sorting the wait objects + scheduling_analysis_thread_wait_object** waitObjects + = new(std::nothrow) scheduling_analysis_thread_wait_object*[ + analysis.thread_wait_object_count]; + ArrayDeleter _2(waitObjects); + + wait_object_group* waitObjectGroups = new(std::nothrow) wait_object_group[ + analysis.thread_wait_object_count]; + ArrayDeleter _3(waitObjectGroups); + + if (waitObjects == NULL || waitObjectGroups == NULL) { + fprintf(stderr, "Error: Out of memory\n"); + exit(1); + } + printf("scheduling analysis: %lu threads, %llu wait objects, " "%llu thread wait objects\n", analysis.thread_count, analysis.wait_object_count, analysis.thread_wait_object_count); + // sort the thread by run time + std::sort(analysis.threads, analysis.threads + analysis.thread_count, + ThreadRunTimeComparator()); + for (uint32 i = 0; i < analysis.thread_count; i++) { scheduling_analysis_thread* thread = analysis.threads[i]; - // compute total wait time + // compute total wait time and prepare the objects for sorting + int32 waitObjectCount = 0; bigtime_t waitTime = 0; scheduling_analysis_thread_wait_object* threadWaitObject = thread->wait_objects; while (threadWaitObject != NULL) { + waitObjects[waitObjectCount++] = threadWaitObject; waitTime += threadWaitObject->wait_time; threadWaitObject = threadWaitObject->next_in_list; } + // sort the wait objects by type + name + std::sort(waitObjects, waitObjects + waitObjectCount, + WaitObjectGroupingComparator()); + + // create the groups + wait_object_group* group = NULL; + int32 groupCount = 0; + for (int32 i = 0; i < waitObjectCount; i++) { + scheduling_analysis_thread_wait_object* threadWaitObject + = waitObjects[i]; + scheduling_analysis_wait_object* waitObject + = threadWaitObject->wait_object; + + if (groupCount == 0 || strcmp(waitObject->name, "?") == 0 + || waitObject->type != group->objects[0]->wait_object->type + || strcmp(waitObject->name, + group->objects[0]->wait_object->name) != 0) { + // create a new group + group = &waitObjectGroups[groupCount++]; + group->objects = waitObjects + i; + group->count = 0; + group->wait_time = 0; + group->waits = 0; + } + + group->count++; + group->wait_time += threadWaitObject->wait_time; + group->waits += threadWaitObject->waits; + } + + // sort the groups by wait time + std::sort(waitObjectGroups, waitObjectGroups + groupCount, + WaitObjectGroupTimeComparator()); + printf("\nthread %ld \"%s\":\n", thread->id, thread->name); printf(" run time: %lld us (%lld runs)\n", thread->total_run_time, thread->runs); @@ -191,16 +306,43 @@ printf(" preemptions: %lld us (%lld)\n", thread->total_rerun_time, thread->reruns); printf(" unspecified: %lld us\n", thread->unspecified_wait_time); + printf(" waited on:\n"); - threadWaitObject = thread->wait_objects; - while (threadWaitObject != NULL) { - scheduling_analysis_wait_object* waitObject - = threadWaitObject->wait_object; + for (int32 i = 0; i < groupCount; i++) { + wait_object_group& group = waitObjectGroups[i]; char buffer[1024]; - wait_object_to_string(waitObject, buffer); - printf(" %s: %lld us\n", buffer, threadWaitObject->wait_time); - threadWaitObject = threadWaitObject->next_in_list; + if (group.count == 1) { + // only one element -- just print it + scheduling_analysis_thread_wait_object* threadWaitObject + = group.objects[0]; + scheduling_analysis_wait_object* waitObject + = threadWaitObject->wait_object; + wait_object_to_string(waitObject, buffer); + printf(" %s: %lld us (%lld)\n", buffer, + threadWaitObject->wait_time, threadWaitObject->waits); + } else { + // sort the wait objects by wait time + std::sort(group.objects, group.objects + group.count, + WaitObjectTimeComparator()); + + // print the group line + wait_object_to_string(group.objects[0]->wait_object, buffer, + true); + printf(" group %s: %lld us (%lld)\n", buffer, + group.wait_time, group.waits); + + // print the wait objects + for (int32 k = 0; k < group.count; k++) { + scheduling_analysis_thread_wait_object* threadWaitObject + = group.objects[k]; + scheduling_analysis_wait_object* waitObject + = threadWaitObject->wait_object; + wait_object_to_string(waitObject, buffer); + printf(" %s: %lld us (%lld)\n", buffer, + threadWaitObject->wait_time, threadWaitObject->waits); + } + } } } } @@ -314,7 +456,7 @@ bigtime_t total = info.user_time + info.kernel_time; printf("%7ld %-32s %10lld %10lld %10lld %6.2f\n", info.thread, - info.name, info.user_time, info.kernel_time, total, + info.name, info.kernel_time, info.user_time, total, (double)total / runTime * 100); if (highlight) From bonefish at mail.berlios.de Thu Sep 4 02:32:14 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Thu, 4 Sep 2008 02:32:14 +0200 Subject: [Haiku-commits] r27314 - haiku/trunk/src/system/kernel Message-ID: <200809040032.m840WE4M008339@sheep.berlios.de> Author: bonefish Date: 2008-09-04 02:32:12 +0200 (Thu, 04 Sep 2008) New Revision: 27314 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27314&view=rev Modified: haiku/trunk/src/system/kernel/sem.cpp Log: release_sem_etc(): Reschedule only when a thread with a priority greater than that of the current thread has been woken up. I didn't see the reason why the thread should otherwise relinquish the rest of its quantum. I noticed for instance that client and app server window threads were ping-ponging more than seemed necessary. In most cases when the client sent a port message it would be unscheduled although it had run only for a few microseconds and had still stuff to do. I measured a relatively Terminal-heavy "find /boot" (second run), which does now take 5-10% less time. Modified: haiku/trunk/src/system/kernel/sem.cpp =================================================================== --- haiku/trunk/src/system/kernel/sem.cpp 2008-09-04 00:13:53 UTC (rev 27313) +++ haiku/trunk/src/system/kernel/sem.cpp 2008-09-04 00:32:12 UTC (rev 27314) @@ -919,7 +919,8 @@ flags |= B_RELEASE_IF_WAITING_ONLY; } - bool unblockedAny = false; + struct thread* currentThread = thread_get_current_thread(); + bool reschedule = false; SpinLocker threadLocker(gThreadSpinlock); @@ -948,7 +949,7 @@ sSems[slot].u.used.count += delta; sSems[slot].u.used.net_count += delta - entry->count; count -= delta; - unblockedAny = true; + reschedule |= entry->thread->priority > currentThread->priority; } else { // The thread is no longer waiting, but still queued, which // means acquiration failed and we can just remove it. @@ -966,7 +967,7 @@ // If we've unblocked another thread reschedule, if we've not explicitly // been told not to. - if (unblockedAny && (flags & B_DO_NOT_RESCHEDULE) == 0) { + if (reschedule && (flags & B_DO_NOT_RESCHEDULE) == 0) { semLocker.Unlock(); threadLocker.Lock(); scheduler_reschedule(); From jackburton at mail.berlios.de Thu Sep 4 10:22:02 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Thu, 4 Sep 2008 10:22:02 +0200 Subject: [Haiku-commits] r27315 - haiku/trunk/src/kits/interface Message-ID: <200809040822.m848M2G9011120@sheep.berlios.de> Author: jackburton Date: 2008-09-04 10:22:00 +0200 (Thu, 04 Sep 2008) New Revision: 27315 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27315&view=rev Modified: haiku/trunk/src/kits/interface/PicturePlayer.cpp Log: Fixed memcpy in case a smaller function table is provided. Improved readability of the SET_CLIPPING_RECT op block. Modified: haiku/trunk/src/kits/interface/PicturePlayer.cpp =================================================================== --- haiku/trunk/src/kits/interface/PicturePlayer.cpp 2008-09-04 00:32:12 UTC (rev 27314) +++ haiku/trunk/src/kits/interface/PicturePlayer.cpp 2008-09-04 08:22:00 UTC (rev 27315) @@ -159,10 +159,10 @@ if ((uint32)tableEntries < kOpsTableSize) { #if DEBUG - fprintf(file, "A smaller than needed function table was supplied.\n"); + fprintf(file, "PicturePlayer: A smaller than needed function table was supplied.\n"); #endif functionTable = dummyTable; - memcpy(functionTable, callBackTable, (kOpsTableSize - tableEntries) * sizeof(void *)); + memcpy(functionTable, callBackTable, tableEntries * sizeof(void *)); } const char *data = reinterpret_cast(fData); @@ -352,9 +352,10 @@ case B_PIC_SET_CLIPPING_RECTS: { // TODO: Not sure if it's compatible with R5's BPicture version - ((fnc_PBRecti)functionTable[20])(userData, - reinterpret_cast(data + sizeof(uint32)), - *reinterpret_cast(data)); + const uint32 numRects = *reinterpret_cast(data); + const BRect *rects = reinterpret_cast(data + sizeof(uint32)); + ((fnc_PBRecti)functionTable[20])(userData, rects, numRects); + break; } From jackburton at mail.berlios.de Thu Sep 4 11:30:31 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Thu, 4 Sep 2008 11:30:31 +0200 Subject: [Haiku-commits] r27316 - haiku/trunk/src/tests/kits/interface/flatten_picture Message-ID: <200809040930.m849UVpe019278@sheep.berlios.de> Author: jackburton Date: 2008-09-04 11:30:29 +0200 (Thu, 04 Sep 2008) New Revision: 27316 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27316&view=rev Modified: haiku/trunk/src/tests/kits/interface/flatten_picture/PictureTestCases.cpp Log: Added a test (not that cool) for SetDrawingMode(). For some reasons it fails, although the images look the same to me. Modified: haiku/trunk/src/tests/kits/interface/flatten_picture/PictureTestCases.cpp =================================================================== --- haiku/trunk/src/tests/kits/interface/flatten_picture/PictureTestCases.cpp 2008-09-04 08:22:00 UTC (rev 27315) +++ haiku/trunk/src/tests/kits/interface/flatten_picture/PictureTestCases.cpp 2008-09-04 09:30:29 UTC (rev 27316) @@ -682,8 +682,19 @@ view->DrawString("Haiku"); } +static void testSetDrawingMode(BView *view, BRect frame) +{ + view->StrokeLine(frame.LeftTop(), frame.RightBottom()); + view->StrokeLine(frame.LeftBottom(), frame.RightTop()); + view->SetDrawingMode(B_OP_ALPHA); + rgb_color color = kRed; + color.alpha = 127; + view->SetHighColor(color); + view->FillRect(frame, B_SOLID_HIGH); +} + + // TODO -// - drawing mode // - blending mode // - line mode // - push/pop state @@ -745,6 +756,7 @@ { "Test SetOriginAndScale4", testSetOriginAndScale4 }, { "Test SetOriginAndScale5", testSetOriginAndScale5 }, { "Test SetFontSize", testSetFontSize }, + { "Test SetDrawingMode", testSetDrawingMode }, { NULL, NULL } }; From jackburton at mail.berlios.de Thu Sep 4 12:20:09 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Thu, 4 Sep 2008 12:20:09 +0200 Subject: [Haiku-commits] r27317 - haiku/trunk/src/tests/kits/interface/flatten_picture Message-ID: <200809041020.m84AK9Fj023328@sheep.berlios.de> Author: jackburton Date: 2008-09-04 12:20:07 +0200 (Thu, 04 Sep 2008) New Revision: 27317 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27317&view=rev Modified: haiku/trunk/src/tests/kits/interface/flatten_picture/PictureTestCases.cpp Log: added test for push/pop state (very basic) Modified: haiku/trunk/src/tests/kits/interface/flatten_picture/PictureTestCases.cpp =================================================================== --- haiku/trunk/src/tests/kits/interface/flatten_picture/PictureTestCases.cpp 2008-09-04 09:30:29 UTC (rev 27316) +++ haiku/trunk/src/tests/kits/interface/flatten_picture/PictureTestCases.cpp 2008-09-04 10:20:07 UTC (rev 27317) @@ -684,6 +684,7 @@ static void testSetDrawingMode(BView *view, BRect frame) { + frame.InsetBy(2, 2); view->StrokeLine(frame.LeftTop(), frame.RightBottom()); view->StrokeLine(frame.LeftBottom(), frame.RightTop()); view->SetDrawingMode(B_OP_ALPHA); @@ -693,7 +694,18 @@ view->FillRect(frame, B_SOLID_HIGH); } +static void testPushPopState(BView *view, BRect frame) +{ + frame.InsetBy(2, 2); + view->SetHighColor(kGreen); + view->PushState(); + view->SetHighColor(kRed); + view->PopState(); + + view->FillRect(frame, B_SOLID_HIGH); +} + // TODO // - blending mode // - line mode @@ -757,6 +769,7 @@ { "Test SetOriginAndScale5", testSetOriginAndScale5 }, { "Test SetFontSize", testSetFontSize }, { "Test SetDrawingMode", testSetDrawingMode }, + { "Test PushPopState", testPushPopState }, { NULL, NULL } }; From jackburton at mail.berlios.de Thu Sep 4 12:21:48 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Thu, 4 Sep 2008 12:21:48 +0200 Subject: [Haiku-commits] r27318 - haiku/trunk/src/tests/kits/interface/flatten_picture Message-ID: <200809041021.m84ALmgs023457@sheep.berlios.de> Author: jackburton Date: 2008-09-04 12:21:47 +0200 (Thu, 04 Sep 2008) New Revision: 27318 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27318&view=rev Modified: haiku/trunk/src/tests/kits/interface/flatten_picture/TestResultItem.cpp Log: Added a column where the picture generated bitmap is subtracted from the direct generated bitmapi (to be able to see small differences, is it correct or it doesn't work like this?). In many cases the result is a black rectangle (as it should), but some others don't look correct. Any idea ? Modified: haiku/trunk/src/tests/kits/interface/flatten_picture/TestResultItem.cpp =================================================================== --- haiku/trunk/src/tests/kits/interface/flatten_picture/TestResultItem.cpp 2008-09-04 10:20:07 UTC (rev 27317) +++ haiku/trunk/src/tests/kits/interface/flatten_picture/TestResultItem.cpp 2008-09-04 10:21:47 UTC (rev 27318) @@ -73,7 +73,13 @@ owner->DrawBitmap(fArchivedBitmap); } owner->MovePenBy(fBitmapSize.Width() + distance, 0); + + owner->DrawBitmap(fDirectBitmap); + owner->SetDrawingMode(B_OP_SUBTRACT); + owner->DrawBitmap(fOriginalBitmap); + owner->MovePenBy(fBitmapSize.Width() + distance, 0); + owner->SetDrawingMode(B_OP_OVER); BFont font; owner->GetFont(&font); From jackburton at mail.berlios.de Thu Sep 4 13:58:05 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Thu, 4 Sep 2008 13:58:05 +0200 Subject: [Haiku-commits] r27319 - haiku/trunk/src/kits/interface/layouter Message-ID: <200809041158.m84Bw554022013@sheep.berlios.de> Author: jackburton Date: 2008-09-04 13:58:01 +0200 (Thu, 04 Sep 2008) New Revision: 27319 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27319&view=rev Modified: haiku/trunk/src/kits/interface/layouter/ComplexLayouter.cpp haiku/trunk/src/kits/interface/layouter/ComplexLayouter.h haiku/trunk/src/kits/interface/layouter/SimpleLayouter.cpp haiku/trunk/src/kits/interface/layouter/SimpleLayouter.h Log: Changed spacing parameter type from int32 to float. Modified: haiku/trunk/src/kits/interface/layouter/ComplexLayouter.cpp =================================================================== --- haiku/trunk/src/kits/interface/layouter/ComplexLayouter.cpp 2008-09-04 10:21:47 UTC (rev 27318) +++ haiku/trunk/src/kits/interface/layouter/ComplexLayouter.cpp 2008-09-04 11:58:01 UTC (rev 27319) @@ -157,9 +157,9 @@ // constructor -ComplexLayouter::ComplexLayouter(int32 elementCount, int32 spacing) +ComplexLayouter::ComplexLayouter(int32 elementCount, float spacing) : fElementCount(elementCount), - fSpacing(spacing), + fSpacing((int32)spacing), fConstraints(new(nothrow) Constraint*[elementCount]), fWeights(new(nothrow) float[elementCount]), fSums(new(nothrow) SumItem[elementCount + 1]), Modified: haiku/trunk/src/kits/interface/layouter/ComplexLayouter.h =================================================================== --- haiku/trunk/src/kits/interface/layouter/ComplexLayouter.h 2008-09-04 10:21:47 UTC (rev 27318) +++ haiku/trunk/src/kits/interface/layouter/ComplexLayouter.h 2008-09-04 11:58:01 UTC (rev 27319) @@ -20,7 +20,7 @@ class ComplexLayouter : public Layouter { public: ComplexLayouter(int32 elementCount, - int32 spacing); + float spacing); virtual ~ComplexLayouter(); virtual status_t InitCheck() const; Modified: haiku/trunk/src/kits/interface/layouter/SimpleLayouter.cpp =================================================================== --- haiku/trunk/src/kits/interface/layouter/SimpleLayouter.cpp 2008-09-04 10:21:47 UTC (rev 27318) +++ haiku/trunk/src/kits/interface/layouter/SimpleLayouter.cpp 2008-09-04 11:58:01 UTC (rev 27319) @@ -113,9 +113,9 @@ // constructor -SimpleLayouter::SimpleLayouter(int32 elementCount, int32 spacing) +SimpleLayouter::SimpleLayouter(int32 elementCount, float spacing) : fElementCount(elementCount), - fSpacing(spacing), + fSpacing((int32)spacing), fMin(0), fMax(B_SIZE_UNLIMITED), fPreferred(0), Modified: haiku/trunk/src/kits/interface/layouter/SimpleLayouter.h =================================================================== --- haiku/trunk/src/kits/interface/layouter/SimpleLayouter.h 2008-09-04 10:21:47 UTC (rev 27318) +++ haiku/trunk/src/kits/interface/layouter/SimpleLayouter.h 2008-09-04 11:58:01 UTC (rev 27319) @@ -19,7 +19,7 @@ class SimpleLayouter : public Layouter { public: SimpleLayouter(int32 elementCount, - int32 spacing); + float spacing); virtual ~SimpleLayouter(); virtual void AddConstraints(int32 element, int32 length, From sbenedetto at mail.berlios.de Thu Sep 4 14:34:26 2008 From: sbenedetto at mail.berlios.de (sbenedetto at BerliOS) Date: Thu, 4 Sep 2008 14:34:26 +0200 Subject: [Haiku-commits] r27320 - haiku/trunk/src/system/kernel/posix Message-ID: <200809041234.m84CYQkF025171@sheep.berlios.de> Author: sbenedetto Date: 2008-09-04 14:34:26 +0200 (Thu, 04 Sep 2008) New Revision: 27320 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27320&view=rev Modified: haiku/trunk/src/system/kernel/posix/xsi_semaphore.cpp Log: * split Wait() method into Enqueue() - BlockAndUnlock() - Deque() in order to remove a race condition pointed out by Ingo, hopefully in a clean way. The set is now unlocked right before blocking * Reworked the way ID were assgned: the current time is now used as ID. This lower quite a lot the probability of having an ID reused. * Introduced a sequence number field in the set class as a second ID, as suggested by Ingo. It is used on wake up in order not to confuse a no more existing set with a new one with the same ID * Removed a now unnecessary UnsetID() method * Increased the arbitraty limit of max sempahore allowed in the system, and introduced a new one for the total number of set. Modified: haiku/trunk/src/system/kernel/posix/xsi_semaphore.cpp =================================================================== --- haiku/trunk/src/system/kernel/posix/xsi_semaphore.cpp 2008-09-04 11:58:01 UTC (rev 27319) +++ haiku/trunk/src/system/kernel/posix/xsi_semaphore.cpp 2008-09-04 12:34:26 UTC (rev 27320) @@ -136,6 +136,42 @@ } } + status_t BlockAndUnlock(struct thread *thread, MutexLocker *setLocker) + { + thread_prepare_to_block(thread, B_CAN_INTERRUPT, + THREAD_BLOCK_TYPE_OTHER, (void*)"xsi semaphore"); + // Unlock the set before blocking + setLocker->Unlock(); + + InterruptsSpinLocker _(gThreadSpinlock); + return thread_block_locked(thread); + } + + void Deque(queued_thread *queueEntry, bool waitForZero) + { + if (queueEntry->queued) { + if (waitForZero) { + fWaitingToBeZeroQueue.Remove(queueEntry); + fThreadsWaitingToBeZero--; + } else { + fWaitingToIncreaseQueue.Remove(queueEntry); + fThreadsWaitingToIncrease--; + } + } + } + + void Enqueue(queued_thread *queueEntry, bool waitForZero) + { + if (waitForZero) { + fWaitingToBeZeroQueue.Add(queueEntry); + fThreadsWaitingToBeZero++; + } else { + fWaitingToIncreaseQueue.Add(queueEntry); + fThreadsWaitingToIncrease++; + } + queueEntry->queued = true; + } + pid_t LastPid() const { return fLastPidOperation; @@ -175,42 +211,6 @@ return fValue; } - status_t Wait(int32 count, bool waitForZero) - { - TRACE(("XsiSemaphore::Wait: going to sleep\n")); - // enqueue the thread in the appropriate - // queue and get ready to wait - struct thread *thread = thread_get_current_thread(); - queued_thread queueEntry(thread, count); - if (waitForZero) { - fWaitingToBeZeroQueue.Add(&queueEntry); - fThreadsWaitingToBeZero++; - } else { - fWaitingToIncreaseQueue.Add(&queueEntry); - fThreadsWaitingToIncrease++; - } - queueEntry.queued = true; - - thread_prepare_to_block(thread, B_CAN_INTERRUPT, - THREAD_BLOCK_TYPE_OTHER, (void*)"xsi semaphore"); - - InterruptsSpinLocker _(gThreadSpinlock); - status_t result = thread_block_locked(thread); - - if (queueEntry.queued) { - // If we are still queued, we failed to acquire - // the semaphore for some reason - if (waitForZero) { - fWaitingToBeZeroQueue.Remove(&queueEntry); - fThreadsWaitingToBeZero--; - } else { - fWaitingToIncreaseQueue.Remove(&queueEntry); - fThreadsWaitingToIncrease--; - } - } - return result; - } - void WakeUpThread(bool waitingForZero) { InterruptsSpinLocker _(gThreadSpinlock); @@ -269,7 +269,6 @@ TRACE(("XsiSemaphoreSet::~XsiSemaphoreSet(): removing semaphore " "set %d\n", fID)); mutex_destroy(&fLock); - UnsetID(); delete[] fSemaphores; } @@ -340,7 +339,7 @@ return HasPermission(); } - int ID() const + int ID() const { return fID; } @@ -477,7 +476,12 @@ return &fSemaphores[nth]; } - // Implemented after sSemaphoreHashTable is declared + uint32 SequenceNumber() const + { + return fSequenceNumber; + } + + // Implemented after sGlobalSequenceNumber is declared void SetID(); void SetIpcKey(key_t key) @@ -507,9 +511,6 @@ return fUndoList; } - // Implemented after sSemaphoreHashTable is declared - void UnsetID(); - HashTableLink* Link() { return &fLink; @@ -522,6 +523,7 @@ time_t fLastSemopTime; // sem_otime ushort fNumberOfSemaphores; // sem_nsems struct ipc_perm fPermissions; // sem_perm + uint32 fSequenceNumber; // used as a second id XsiSemaphore *fSemaphores; // array of semaphores UndoList fUndoList; // undo list requests mutex fLock; // private lock @@ -618,15 +620,17 @@ }; // Arbitrary limit -#define MAX_XSI_SEMAPHORE 2048 +#define MAX_XSI_SEMAPHORE 4096 +#define MAX_XSI_SEMAPHORE_SET 2048 static OpenHashTable sIpcHashTable; static OpenHashTable sSemaphoreHashTable; static mutex sIpcLock; static mutex sXsiSemaphoreSetLock; -static vint32 sNextAvailableID = 1; +static uint32 sGlobalSequenceNumber = 1; static vint32 sXsiSemaphoreCount = 0; +static vint32 sXsiSemaphoreSetCount = 0; // #pragma mark - @@ -635,23 +639,18 @@ void XsiSemaphoreSet::SetID() { + fID = real_time_clock(); // The lock is held before calling us while (true) { - if (sSemaphoreHashTable.Lookup(sNextAvailableID) == NULL) + if (sSemaphoreHashTable.Lookup(fID) == NULL) break; - sNextAvailableID++; + fID = (fID + 1) % INT_MAX; } - fID = sNextAvailableID++; + sGlobalSequenceNumber = (sGlobalSequenceNumber + 1) % UINT_MAX; + fSequenceNumber = sGlobalSequenceNumber; } -void -XsiSemaphoreSet::UnsetID() -{ - sNextAvailableID = fID; -} - - // #pragma mark - Kernel exported API @@ -781,7 +780,8 @@ TRACE_ERROR(("xsi_semget: numberOfSemaphores out of range\n")); return EINVAL; } - if (sXsiSemaphoreCount >= MAX_XSI_SEMAPHORE) { + if (sXsiSemaphoreCount >= MAX_XSI_SEMAPHORE + || sXsiSemaphoreSetCount >= MAX_XSI_SEMAPHORE_SET) { TRACE_ERROR(("xsi_semget: reached limit of maximum number of " "semaphores allowed\n")); return ENOSPC; @@ -795,6 +795,7 @@ return ENOMEM; } atomic_add(&sXsiSemaphoreCount, numberOfSemaphores); + atomic_add(&sXsiSemaphoreSetCount, 1); MutexLocker _(sXsiSemaphoreSetLock); semaphoreSet->SetID(); @@ -805,6 +806,8 @@ ipcKey->SetSemaphoreSetID(semaphoreSet); } sSemaphoreHashTable.Insert(semaphoreSet); + TRACE(("semget: new set = %d created, sequence = %ld\n", + semaphoreSet->ID(), semaphoreSet->SequenceNumber())); } return semaphoreSet->ID(); @@ -1030,6 +1033,7 @@ if (key != -1) delete ipcKey; atomic_add(&sXsiSemaphoreCount, -semaphoreSet->NumberOfSemaphores()); + atomic_add(&sXsiSemaphoreSetCount, -1); // Remove any sem_undo request while (struct sem_undo *entry = semaphoreSet->GetUndoList().RemoveHead()) { @@ -1154,23 +1158,40 @@ if (result != 0) return result; + // We have to wait: first enqueue the thread + // in the appropriate set waiting list, then + // unlock the set itself and block the thread. bool waitOnZero = true; if (operations[i].sem_op != 0) waitOnZero = false; - setLocker.Unlock(); - result = semaphore->Wait((int32)operations[i].sem_op, waitOnZero); - TRACE(("xsi_semop: back to life\n")); + struct thread *thread = thread_get_current_thread(); + queued_thread queueEntry(thread, (int32)operations[i].sem_op); + semaphore->Enqueue(&queueEntry, waitOnZero); - // We are back to life. - // Find out why! + uint32 sequenceNumber = semaphoreSet->SequenceNumber(); + + TRACE(("xsi_semop: thread %d going to sleep\n", (int)thread->id)); + result = semaphore->BlockAndUnlock(thread, &setLocker); + TRACE(("xsi_semop: thread %d back to life\n", (int)thread->id)); + + // We are back to life. Find out why! + // Make sure the set hasn't been deleted or worst yet + // replaced. setHashLocker.Lock(); semaphoreSet = sSemaphoreHashTable.Lookup(semaphoreID); - if (result == EIDRM || result == B_INTERRUPTED - || semaphoreSet == NULL) { - TRACE_ERROR(("xsi_semop: semaphore set id %d got destroyed\n", + if (result == EIDRM || semaphoreSet == NULL || (semaphoreSet != NULL + && sequenceNumber != semaphoreSet->SequenceNumber())) { + TRACE_ERROR(("xsi_semop: semaphore set id %d (sequence = %ld) " + "got destroyed\n", semaphoreID, sequenceNumber)); + notDone = false; + result = EIDRM; + } else if (result == B_INTERRUPTED) { + TRACE_ERROR(("xsi_semop: thread %d got interrupted while " + "waiting on semaphore set id %d\n",(int)thread->id, semaphoreID)); - result = EIDRM; + semaphore->Deque(&queueEntry, waitOnZero); + result = EINTR; notDone = false; } else { setLocker.Lock(); From jackburton at mail.berlios.de Thu Sep 4 15:59:42 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Thu, 4 Sep 2008 15:59:42 +0200 Subject: [Haiku-commits] r27321 - haiku/trunk/src/kits/interface Message-ID: <200809041359.m84Dxgik000291@sheep.berlios.de> Author: jackburton Date: 2008-09-04 15:59:41 +0200 (Thu, 04 Sep 2008) New Revision: 27321 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27321&view=rev Modified: haiku/trunk/src/kits/interface/View.cpp Log: implemented a client side (and very slow) version of BView::ClipToPicture. See bug #1397 Modified: haiku/trunk/src/kits/interface/View.cpp =================================================================== --- haiku/trunk/src/kits/interface/View.cpp 2008-09-04 12:34:26 UTC (rev 27320) +++ haiku/trunk/src/kits/interface/View.cpp 2008-09-04 13:59:41 UTC (rev 27321) @@ -4394,6 +4394,61 @@ if (!picture) return; +#if 1 + // TODO: Move the implementation to the server!!! + + // Here the idea is to get rid of the padding bytes in the bitmap, + // as padding complicates and slows down the iteration. + // TODO: Maybe it's not so nice as it assumes BBitmaps to be aligned + // to a 4 byte boundary. + BRect bounds(Bounds()); + if ((bounds.IntegerWidth() + 1) % 32) + bounds.right = bounds.left + ((bounds.IntegerWidth() + 1) / 32 + 1) * 32 - 1; + + // TODO: I used a RGBA32 bitmap because drawing on a GRAY8 doesn't work. + BBitmap *bitmap = new BBitmap(bounds, B_RGBA32, true); + if (bitmap && bitmap->InitCheck() == B_OK && bitmap->Lock()) { + BView *view = new BView(bounds, "drawing view", B_FOLLOW_NONE, 0); + bitmap->AddChild(view); + view->DrawPicture(picture, where); + view->Sync(); + bitmap->Unlock(); + } + + BRegion region; + int32 width = bounds.IntegerWidth() + 1; + int32 height = bounds.IntegerHeight() + 1; + if (bitmap->LockBits() == B_OK) { + uint32 bit = 0; + uint32 *bits = (uint32 *)bitmap->Bits(); + clipping_rect rect; + + // TODO: A possible optimization would be adding "spans" instead + // of 1x1 rects. That would probably help with very complex + // BPictures + for (int32 y = 0; y < height; y++) { + for (int32 x = 0; x < width; x++) { + bit = *bits++; + if (bit != (uint32)-1) { + rect.left = x; + rect.right = rect.left; + rect.top = rect.bottom = y; + region.Include(rect); + } + } + } + bitmap->UnlockBits(); + } + delete bitmap; + + if (invert) { + BRegion inverseRegion; + inverseRegion.Include(Bounds()); + inverseRegion.Exclude(®ion); + ConstrainClippingRegion(&inverseRegion); + } else + ConstrainClippingRegion(®ion); +#else if (_CheckOwnerLockAndSwitchCurrent()) { fOwner->fLink->StartMessage(AS_VIEW_CLIP_TO_PICTURE); fOwner->fLink->Attach(picture->Token()); @@ -4409,6 +4464,7 @@ } fState->archiving_flags |= B_VIEW_CLIP_REGION_BIT; +#endif } From julun at mail.berlios.de Thu Sep 4 18:07:12 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Thu, 4 Sep 2008 18:07:12 +0200 Subject: [Haiku-commits] r27322 - haiku/trunk/src/system/libroot/os Message-ID: <200809041607.m84G7CL5018099@sheep.berlios.de> Author: julun Date: 2008-09-04 18:07:11 +0200 (Thu, 04 Sep 2008) New Revision: 27322 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27322&view=rev Modified: haiku/trunk/src/system/libroot/os/thread.c Log: * calling receive_data with NULL as first argument(thread_id) failed on Haiku, this makes e.g. painting in ArtPaint work Don't know if this is the best place to fix it though. Modified: haiku/trunk/src/system/libroot/os/thread.c =================================================================== --- haiku/trunk/src/system/libroot/os/thread.c 2008-09-04 13:59:41 UTC (rev 27321) +++ haiku/trunk/src/system/libroot/os/thread.c 2008-09-04 16:07:11 UTC (rev 27322) @@ -115,7 +115,7 @@ { callback_node *node = tls_get(TLS_ON_EXIT_THREAD_SLOT); callback_node *next; - + while (node != NULL) { next = node->next; @@ -179,6 +179,10 @@ int32 receive_data(thread_id *_sender, void *buffer, size_t bufferSize) { + if (_sender == NULL) { + thread_id id; + return _kern_receive_data(&id, buffer, bufferSize); + } return _kern_receive_data(_sender, buffer, bufferSize); } From emitrax at gmail.com Thu Sep 4 18:32:41 2008 From: emitrax at gmail.com (Salvatore Benedetto) Date: Thu, 4 Sep 2008 16:32:41 +0000 Subject: [Haiku-commits] r27322 - haiku/trunk/src/system/libroot/os In-Reply-To: <200809041607.m84G7CL5018099@sheep.berlios.de> References: <200809041607.m84G7CL5018099@sheep.berlios.de> Message-ID: 2008/9/4 julun at BerliOS : > Author: julun > Date: 2008-09-04 18:07:11 +0200 (Thu, 04 Sep 2008) > New Revision: 27322 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27322&view=rev > > Modified: > haiku/trunk/src/system/libroot/os/thread.c > Log: > * calling receive_data with NULL as first argument(thread_id) > failed on Haiku, this makes e.g. painting in ArtPaint work > > Don't know if this is the best place to fix it though. > > > > Modified: haiku/trunk/src/system/libroot/os/thread.c > =================================================================== > --- haiku/trunk/src/system/libroot/os/thread.c 2008-09-04 13:59:41 UTC (rev 27321) > +++ haiku/trunk/src/system/libroot/os/thread.c 2008-09-04 16:07:11 UTC (rev 27322) > @@ -115,7 +115,7 @@ > { > callback_node *node = tls_get(TLS_ON_EXIT_THREAD_SLOT); > callback_node *next; > - > + > while (node != NULL) { > next = node->next; > > @@ -179,6 +179,10 @@ > int32 > receive_data(thread_id *_sender, void *buffer, size_t bufferSize) > { > + if (_sender == NULL) { > + thread_id id; > + return _kern_receive_data(&id, buffer, bufferSize); > + } > return _kern_receive_data(_sender, buffer, bufferSize); > } > Probably not. If the caller is not interested in the sender as in this case, I think it should be fixed in _user_receive_data and receive_data_etc in src/system/kernel/thread.cpp. Regards, -- Salvatore Benedetto (a.k.a. emitrax) Student of Computer Engineer University of Pisa www.haiku-os.it From host.haiku at gmx.de Thu Sep 4 18:37:42 2008 From: host.haiku at gmx.de (julun) Date: Thu, 04 Sep 2008 18:37:42 +0200 Subject: [Haiku-commits] r27322 - haiku/trunk/src/system/libroot/os In-Reply-To: References: <200809041607.m84G7CL5018099@sheep.berlios.de> Message-ID: <48C00ED6.3060105@gmx.de> Salvatore Benedetto schrieb: > 2008/9/4 julun at BerliOS : >> Author: julun >> Date: 2008-09-04 18:07:11 +0200 (Thu, 04 Sep 2008) >> New Revision: 27322 >> ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27322&view=rev >> >> Modified: >> haiku/trunk/src/system/libroot/os/thread.c >> Log: >> * calling receive_data with NULL as first argument(thread_id) >> failed on Haiku, this makes e.g. painting in ArtPaint work >> >> Don't know if this is the best place to fix it though. >> > > Probably not. If the caller is not interested in the sender as in this case, > I think it should be fixed in _user_receive_data and receive_data_etc in > src/system/kernel/thread.cpp. > I tried it there first, but it doesn't get that far at all? That's why i did it in libroot. Karsten From emitrax at gmail.com Thu Sep 4 18:42:52 2008 From: emitrax at gmail.com (Salvatore Benedetto) Date: Thu, 4 Sep 2008 16:42:52 +0000 Subject: [Haiku-commits] r27322 - haiku/trunk/src/system/libroot/os In-Reply-To: <48C00ED6.3060105@gmx.de> References: <200809041607.m84G7CL5018099@sheep.berlios.de> <48C00ED6.3060105@gmx.de> Message-ID: 2008/9/4 julun : > Salvatore Benedetto schrieb: >> 2008/9/4 julun at BerliOS : >>> Author: julun >>> Date: 2008-09-04 18:07:11 +0200 (Thu, 04 Sep 2008) >>> New Revision: 27322 >>> ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27322&view=rev >>> >>> Modified: >>> haiku/trunk/src/system/libroot/os/thread.c >>> Log: >>> * calling receive_data with NULL as first argument(thread_id) >>> failed on Haiku, this makes e.g. painting in ArtPaint work >>> >>> Don't know if this is the best place to fix it though. >>> > > > >> >> Probably not. If the caller is not interested in the sender as in this case, >> I think it should be fixed in _user_receive_data and receive_data_etc in >> src/system/kernel/thread.cpp. >> > > I tried it there first, but it doesn't get that far at all? That's why > i did it in libroot. you mean it does not get to _user_receive_data() ? There is the following check that could explain the failure in _user_receive_data when NULL is passed if (!IS_USER_ADDRESS(_userSender) || !IS_USER_ADDRESS(buffer)) return B_BAD_ADDRESS; and of course, the user_memcpy that comes next. Regards, -- Salvatore Benedetto (a.k.a. emitrax) Student of Computer Engineer University of Pisa www.haiku-os.it From julun at mail.berlios.de Thu Sep 4 19:00:06 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Thu, 4 Sep 2008 19:00:06 +0200 Subject: [Haiku-commits] r27323 - in haiku/trunk/src/system: kernel libroot/os Message-ID: <200809041700.m84H06Le027012@sheep.berlios.de> Author: julun Date: 2008-09-04 19:00:01 +0200 (Thu, 04 Sep 2008) New Revision: 27323 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27323&view=rev Modified: haiku/trunk/src/system/kernel/thread.cpp haiku/trunk/src/system/libroot/os/thread.c Log: * revert r27322 and apply the patch provided by Salvatore Thanks you! :) Modified: haiku/trunk/src/system/kernel/thread.cpp =================================================================== --- haiku/trunk/src/system/kernel/thread.cpp 2008-09-04 16:07:11 UTC (rev 27322) +++ haiku/trunk/src/system/kernel/thread.cpp 2008-09-04 17:00:01 UTC (rev 27323) @@ -2855,15 +2855,16 @@ thread_id sender; status_t code; - if (!IS_USER_ADDRESS(_userSender) + if ((!IS_USER_ADDRESS(_userSender) && _userSender != NULL) || !IS_USER_ADDRESS(buffer)) return B_BAD_ADDRESS; code = receive_data_etc(&sender, buffer, bufferSize, B_KILL_CAN_INTERRUPT); // supports userland buffers - if (user_memcpy(_userSender, &sender, sizeof(thread_id)) < B_OK) - return B_BAD_ADDRESS; + if (_userSender != NULL) + if (user_memcpy(_userSender, &sender, sizeof(thread_id)) < B_OK) + return B_BAD_ADDRESS; return code; } Modified: haiku/trunk/src/system/libroot/os/thread.c =================================================================== --- haiku/trunk/src/system/libroot/os/thread.c 2008-09-04 16:07:11 UTC (rev 27322) +++ haiku/trunk/src/system/libroot/os/thread.c 2008-09-04 17:00:01 UTC (rev 27323) @@ -179,10 +179,6 @@ int32 receive_data(thread_id *_sender, void *buffer, size_t bufferSize) { - if (_sender == NULL) { - thread_id id; - return _kern_receive_data(&id, buffer, bufferSize); - } return _kern_receive_data(_sender, buffer, bufferSize); } From anevilyak at gmail.com Thu Sep 4 19:01:53 2008 From: anevilyak at gmail.com (Rene Gollent) Date: Thu, 4 Sep 2008 12:01:53 -0500 Subject: [Haiku-commits] r27323 - in haiku/trunk/src/system: kernel libroot/os In-Reply-To: <200809041700.m84H06Le027012@sheep.berlios.de> References: <200809041700.m84H06Le027012@sheep.berlios.de> Message-ID: On Thu, Sep 4, 2008 at 12:00 PM, julun at BerliOS wrote: > Author: julun > Date: 2008-09-04 19:00:01 +0200 (Thu, 04 Sep 2008) > New Revision: 27323 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27323&view=rev > > Modified: > haiku/trunk/src/system/kernel/thread.cpp > haiku/trunk/src/system/libroot/os/thread.c > Log: > * revert r27322 and apply the patch provided by Salvatore > Thanks you! :) Nice :) I would guess this likely fixes a bunch of other things besides ArtPaint, I know quite a few older apps used send/receive_data as a cheap way to do thread blocking. Regards, Rene From emitrax at gmail.com Thu Sep 4 19:05:06 2008 From: emitrax at gmail.com (Salvatore Benedetto) Date: Thu, 4 Sep 2008 17:05:06 +0000 Subject: [Haiku-commits] r27323 - in haiku/trunk/src/system: kernel libroot/os In-Reply-To: References: <200809041700.m84H06Le027012@sheep.berlios.de> Message-ID: 2008/9/4 Rene Gollent : > On Thu, Sep 4, 2008 at 12:00 PM, julun at BerliOS wrote: >> Author: julun >> Date: 2008-09-04 19:00:01 +0200 (Thu, 04 Sep 2008) >> New Revision: 27323 >> ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27323&view=rev >> >> Modified: >> haiku/trunk/src/system/kernel/thread.cpp >> haiku/trunk/src/system/libroot/os/thread.c >> Log: >> * revert r27322 and apply the patch provided by Salvatore >> Thanks you! :) > Thanks to you for finding the bug! ;-) Regards, -- Salvatore Benedetto (a.k.a. emitrax) Student of Computer Engineer University of Pisa www.haiku-os.it From laplace at mail.berlios.de Thu Sep 4 19:08:24 2008 From: laplace at mail.berlios.de (laplace at mail.berlios.de) Date: Thu, 4 Sep 2008 19:08:24 +0200 Subject: [Haiku-commits] r27324 - haiku/trunk/src/tests/kits/interface/flatten_picture Message-ID: <200809041708.m84H8O1g004421@sheep.berlios.de> Author: laplace Date: 2008-09-04 19:08:20 +0200 (Thu, 04 Sep 2008) New Revision: 27324 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27324&view=rev Modified: haiku/trunk/src/tests/kits/interface/flatten_picture/PictureTest.cpp haiku/trunk/src/tests/kits/interface/flatten_picture/PictureTest.h Log: Provided detailed information when two bitmaps are different. Modified: haiku/trunk/src/tests/kits/interface/flatten_picture/PictureTest.cpp =================================================================== --- haiku/trunk/src/tests/kits/interface/flatten_picture/PictureTest.cpp 2008-09-04 17:00:01 UTC (rev 27323) +++ haiku/trunk/src/tests/kits/interface/flatten_picture/PictureTest.cpp 2008-09-04 17:08:20 UTC (rev 27324) @@ -6,6 +6,7 @@ * Michael Pfeiffer */ +#include #include #include @@ -202,8 +203,19 @@ fBitmapFromRestoredPicture = CreateBitmap(archivedPicture, frame); TEST_AND_RETURN(fBitmapFromRestoredPicture == NULL, "Could not create bitmap from archived picture!", false); - TEST_AND_RETURN(!IsSame(fDirectBitmap, fBitmapFromPicture), "Bitmap from picture differs from direct drawing bitmap", false); - TEST_AND_RETURN(!IsSame(fDirectBitmap, fBitmapFromRestoredPicture), "Bitmap from picture differs from direct drawing bitmap", false); + BString reason; + if (!IsSame(fDirectBitmap, fBitmapFromPicture, reason)) { + BString message("Bitmap from picture differs from direct drawing bitmap: "); + message += reason; + SetErrorMessage(message.String()); + return false; + } + if (!IsSame(fDirectBitmap, fBitmapFromRestoredPicture, reason)) { + BString message("Bitmap from restored picture differs from direct drawing bitmap: "); + message += reason; + SetErrorMessage(message.String()); + return false; + } return true; } @@ -247,16 +259,69 @@ } +static void setMismatchReason(int32 x, int32 y, uint8 *pixel1, uint8 *pixel2, + int32 bpp, BString &reason) +{ + char buffer1[32]; + char buffer2[32]; + uint32 color1 = 0; + uint32 color2 = 0; + memcpy(&color1, pixel1, bpp); + memcpy(&color2, pixel2, bpp); + sprintf(buffer1, "0x%8.8x", (int)color1); + sprintf(buffer2, "0x%8.8x", (int)color2); + + reason = "Pixel at "; + reason << x << ", " << y << " differs: " << buffer1 << " != " << buffer2; + // TODO remove when scrolling horizontally works in result list + fprintf(stderr, "%s\n", reason.String()); +} + + bool -PictureTest::IsSame(BBitmap *bitmap1, BBitmap *bitmap2) +PictureTest::IsSame(BBitmap *bitmap1, BBitmap *bitmap2, BString &reason) { - if (bitmap1->ColorSpace() != bitmap2->ColorSpace()) + if (bitmap1->ColorSpace() != bitmap2->ColorSpace()) { + reason = "ColorSpace() differs"; return false; + } - if (bitmap1->BitsLength() != bitmap2->BitsLength()) + if (bitmap1->BitsLength() != bitmap2->BitsLength()) { + reason = "BitsLength() differs"; return false; + } - return memcmp(bitmap1->Bits(), bitmap2->Bits(), bitmap1->BitsLength()) == 0; + size_t rowAlignment; + size_t pixelChunk; + size_t pixelsPerChunk; + if (get_pixel_size_for(bitmap1->ColorSpace(), &rowAlignment, &pixelChunk, + &pixelsPerChunk) != B_OK) { + reason = "get_pixel_size_for() not supported for this color space"; + return false; + } + if (pixelsPerChunk != 1) { + reason = "Unsupported color_space; IsSame(...) supports 1 pixels per chunk only"; + return false; + } + int32 bpp = (int32)pixelChunk; + uint8* row1 = (uint8*)bitmap1->Bits(); + uint8* row2 = (uint8*)bitmap2->Bits(); + int32 bpr = bitmap1->BytesPerRow(); + int32 width = bitmap1->Bounds().IntegerWidth() + 1; + int32 height = bitmap1->Bounds().IntegerHeight() + 1; + for (int y = 0; y < height; y ++, row1 += bpr, row2 += bpr) { + uint8* pixel1 = row1; + uint8* pixel2 = row2; + for (int x = 0; x < width; x ++, pixel1 += bpp, pixel2 += bpp) { + if (memcmp(pixel1, pixel2, bpp) != 0) { + setMismatchReason(x, y, pixel1, pixel2, bpp, reason); + return false; + } + } + } + + reason = ""; + return true; } Modified: haiku/trunk/src/tests/kits/interface/flatten_picture/PictureTest.h =================================================================== --- haiku/trunk/src/tests/kits/interface/flatten_picture/PictureTest.h 2008-09-04 17:00:01 UTC (rev 27323) +++ haiku/trunk/src/tests/kits/interface/flatten_picture/PictureTest.h 2008-09-04 17:08:20 UTC (rev 27324) @@ -43,7 +43,7 @@ BBitmap *CreateBitmap(draw_func* func, BRect frame); BBitmap *CreateBitmap(BPicture *picture, BRect frame); - bool IsSame(BBitmap *bitmap1, BBitmap *bitmap2); + bool IsSame(BBitmap *bitmap1, BBitmap *bitmap2, BString &reason); color_space fColorSpace; From michael.w.pfeiffer at gmail.com Thu Sep 4 19:18:08 2008 From: michael.w.pfeiffer at gmail.com (Michael Pfeiffer) Date: Thu, 4 Sep 2008 19:18:08 +0200 Subject: [Haiku-commits] r27316 - haiku/trunk/src/tests/kits/interface/flatten_picture In-Reply-To: <200809040930.m849UVpe019278@sheep.berlios.de> References: <200809040930.m849UVpe019278@sheep.berlios.de> Message-ID: Am 04.09.2008 um 11:30 schrieb jackburton at mail.berlios.de: > Author: jackburton > Date: 2008-09-04 11:30:29 +0200 (Thu, 04 Sep 2008) > New Revision: 27316 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27316&view=rev > > Modified: > haiku/trunk/src/tests/kits/interface/flatten_picture/ > PictureTestCases.cpp > Log: > Added a test (not that cool) for SetDrawingMode(). For some reasons > it fails, although the images look the same to me. The bitmap created from "direct drawing" does not match the one from "restored picture drawing". The alpha value in the bitmap from the first is 0x18 and the other is 0x00. The test application prints now to stderr the position of the first not matching pixel and its value as a "long" hexadecimal value for RGB32 this is two digits for A,R,G and B. The information is also appended to the message in the list, however scrolling horizontally does not work correctly, so to see the reason you need a high horizontal screen resolution. I have not examined yet if this is because of a bug in the testing application. Will do when I have time. - Michael From michael.w.pfeiffer at gmail.com Thu Sep 4 19:27:11 2008 From: michael.w.pfeiffer at gmail.com (Michael Pfeiffer) Date: Thu, 4 Sep 2008 19:27:11 +0200 Subject: [Haiku-commits] r27316 - haiku/trunk/src/tests/kits/interface/flatten_picture In-Reply-To: References: <200809040930.m849UVpe019278@sheep.berlios.de> Message-ID: > The information is also appended to the message > in the list, however scrolling horizontally does not work correctly, so to > see the reason you need a high horizontal screen resolution. Moving the window to the left and then enlarging it works too :) - Michael From korli at mail.berlios.de Thu Sep 4 20:44:01 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Thu, 4 Sep 2008 20:44:01 +0200 Subject: [Haiku-commits] r27325 - haiku/trunk/build/jam Message-ID: <200809041844.m84Ii1xA022349@sheep.berlios.de> Author: korli Date: 2008-09-04 20:44:01 +0200 (Thu, 04 Sep 2008) New Revision: 27325 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27325&view=rev Modified: haiku/trunk/build/jam/HaikuImage Log: added input_server addons user directories to the image Modified: haiku/trunk/build/jam/HaikuImage =================================================================== --- haiku/trunk/build/jam/HaikuImage 2008-09-04 17:08:20 UTC (rev 27324) +++ haiku/trunk/build/jam/HaikuImage 2008-09-04 18:44:01 UTC (rev 27325) @@ -423,6 +423,9 @@ AddFilesToHaikuImage beos system add-ons disk_systems : intel bfs ; +AddDirectoryToHaikuImage home config add-ons input_server devices ; +AddDirectoryToHaikuImage home config add-ons input_server filters ; +AddDirectoryToHaikuImage home config add-ons input_server methods ; AddDirectoryToHaikuImage home config add-ons Tracker ; AddDirectoryToHaikuImage home config add-ons Screen\ Savers ; AddDirectoryToHaikuImage home config add-ons Translators ; From korli at mail.berlios.de Thu Sep 4 21:08:06 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Thu, 4 Sep 2008 21:08:06 +0200 Subject: [Haiku-commits] r27326 - in haiku/trunk/headers: os/kernel private/shared Message-ID: <200809041908.m84J864Q024659@sheep.berlios.de> Author: korli Date: 2008-09-04 21:08:05 +0200 (Thu, 04 Sep 2008) New Revision: 27326 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27326&view=rev Modified: haiku/trunk/headers/os/kernel/OS.h haiku/trunk/headers/private/shared/cpu_type.h Log: added B_CPU_INTEL_ATOM, untested Modified: haiku/trunk/headers/os/kernel/OS.h =================================================================== --- haiku/trunk/headers/os/kernel/OS.h 2008-09-04 18:44:01 UTC (rev 27325) +++ haiku/trunk/headers/os/kernel/OS.h 2008-09-04 19:08:05 UTC (rev 27326) @@ -476,6 +476,7 @@ B_CPU_INTEL_PENTIUM_M = 0x1069, B_CPU_INTEL_PENTIUM_III_XEON = 0x106a, B_CPU_INTEL_PENTIUM_III_MODEL_11 = 0x106b, + B_CPU_INTEL_ATOM = 0x106c, B_CPU_INTEL_PENTIUM_M_MODEL_13 = 0x106d, /* Dothan */ B_CPU_INTEL_PENTIUM_CORE, B_CPU_INTEL_PENTIUM_CORE_2, Modified: haiku/trunk/headers/private/shared/cpu_type.h =================================================================== --- haiku/trunk/headers/private/shared/cpu_type.h 2008-09-04 18:44:01 UTC (rev 27325) +++ haiku/trunk/headers/private/shared/cpu_type.h 2008-09-04 19:08:05 UTC (rev 27326) @@ -107,6 +107,8 @@ case B_CPU_INTEL_PENTIUM_M: case B_CPU_INTEL_PENTIUM_M_MODEL_13: return "Pentium M"; + case B_CPU_INTEL_ATOM: + return "Atom"; case B_CPU_INTEL_PENTIUM_CORE: return "Core"; case B_CPU_INTEL_PENTIUM_CORE_2: From sbenedetto at mail.berlios.de Thu Sep 4 21:45:02 2008 From: sbenedetto at mail.berlios.de (sbenedetto at BerliOS) Date: Thu, 4 Sep 2008 21:45:02 +0200 Subject: [Haiku-commits] r27327 - haiku/trunk/src/system/kernel/posix Message-ID: <200809041945.m84Jj28E027768@sheep.berlios.de> Author: sbenedetto Date: 2008-09-04 21:45:02 +0200 (Thu, 04 Sep 2008) New Revision: 27327 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27327&view=rev Modified: haiku/trunk/src/system/kernel/posix/xsi_message_queue.cpp Log: * Implemented msgrcv and msgsnd. Not complete yet. * Reworked the way IDs are geneterad in the same way they are in xsi semaphores Modified: haiku/trunk/src/system/kernel/posix/xsi_message_queue.cpp =================================================================== --- haiku/trunk/src/system/kernel/posix/xsi_message_queue.cpp 2008-09-04 19:08:05 UTC (rev 27326) +++ haiku/trunk/src/system/kernel/posix/xsi_message_queue.cpp 2008-09-04 19:45:02 UTC (rev 27327) @@ -24,7 +24,7 @@ #include -//#define TRACE_XSI_MSG_QUEUE +#define TRACE_XSI_MSG_QUEUE #ifdef TRACE_XSI_MSG_QUEUE # define TRACE(x) dprintf x # define TRACE_ERROR(x) dprintf x @@ -76,6 +76,15 @@ free(message); } + status_t copy_to_user_buffer(void *_message, ssize_t _length) + { + if (user_memcpy(_message, &type, sizeof(long)) != B_OK + || user_memcpy((void *)((long *)_message + sizeof(long)), message, + _length) != B_OK) + return B_ERROR; + return B_OK; + } + bool initOK; ssize_t length; char *message; @@ -91,7 +100,9 @@ public: XsiMessageQueue(int flags) : - fBytesInQueue(0) + fBytesInQueue(0), + fThreadsWaitingToReceive(0), + fThreadsWaitingToSend(0) { mutex_init(&fLock, "XsiMessageQueue private mutex"); SetIpcKey((key_t)-1); @@ -105,10 +116,21 @@ ~XsiMessageQueue() { mutex_destroy(&fLock); - UnsetID(); // TODO: free up all messages + // TODO: Wake up any thread still waiting } + status_t BlockAndUnlock(struct thread *thread, MutexLocker *queueLocker) + { + thread_prepare_to_block(thread, B_CAN_INTERRUPT, + THREAD_BLOCK_TYPE_OTHER, (void*)"xsi message queue"); + // Unlock the queue before blocking + queueLocker->Unlock(); + + InterruptsSpinLocker _(gThreadSpinlock); + return thread_block_locked(thread); + } + void DoIpcSet(struct msqid_ds *result) { fMessageQueue.msg_perm.uid = result->msg_perm.uid; @@ -118,6 +140,36 @@ fMessageQueue.msg_ctime = (time_t)real_time_clock(); } + void Deque(queued_thread *queueEntry, bool waitForMessage) + { + if (queueEntry->queued) { + if (waitForMessage) { + fWaitingToReceive.Remove(queueEntry); + fThreadsWaitingToReceive--; + } else { + fWaitingToSend.Remove(queueEntry); + fThreadsWaitingToSend--; + } + } + } + + void Enqueue(queued_thread *queueEntry, bool waitForMessage) + { + if (waitForMessage) { + fWaitingToReceive.Add(queueEntry); + fThreadsWaitingToReceive++; + } else { + fWaitingToSend.Add(queueEntry); + fThreadsWaitingToSend++; + } + queueEntry->queued = true; + } + + struct msqid_ds &GetMessageQueue() + { + return fMessageQueue; + } + bool HasPermission() const { if ((fMessageQueue.msg_perm.mode & S_IWOTH) != 0) @@ -165,9 +217,12 @@ return fMessageQueue.msg_qbytes; } - struct msqid_ds &GetMessageQueue() + // Implemented after sXsiMessageCountLock is declared + queued_message *Remove(long typeRequested); + + uint32 SequenceNumber() const { - return fMessageQueue; + return fSequenceNumber; } // Implemented after sMessageQueueHashTable is declared @@ -185,14 +240,6 @@ fMessageQueue.msg_perm.mode = (flags & 0x01ff); } - // Implemented after sMessageQueueHashTable is declared - void UnsetID(); - - status_t Wait(queued_message *message) - { - return B_ERROR; - } - HashTableLink* Link() { return &fLink; @@ -204,9 +251,13 @@ mutex fLock; MessageQueue fMessage; struct msqid_ds fMessageQueue; - ThreadQueue fThreadWaitingToSend; - ThreadQueue fThreadWaitingToReceive; + uint32 fSequenceNumber; + uint32 fThreadsWaitingToReceive; + uint32 fThreadsWaitingToSend; + ThreadQueue fWaitingToReceive; + ThreadQueue fWaitingToSend; + ::HashTableLink fLink; }; @@ -309,7 +360,7 @@ static mutex sXsiMessageQueueLock; static mutex sXsiMessageCountLock; -static vint32 sNextAvailableID = 1; +static uint32 sGlobalSequenceNumber = 1; static vint32 sXsiMessageCount = 0; static vint32 sXsiMessageQueueCount = 0; @@ -334,30 +385,71 @@ fMessageQueue.msg_stime = real_time_clock(); fBytesInQueue += message->length; sXsiMessageCount++; + // TODO: Wake up any thread waiting on receive return false; } +queued_message* +XsiMessageQueue::Remove(long typeRequested) +{ + queued_message *message = NULL; + if (typeRequested < 0) { + // Return first message of the lowest type + // that is less than or equal to the absolute + // value of type requested. + MessageQueue::Iterator iterator = fMessage.GetIterator(); + while (iterator.HasNext()) { + queued_message *current = iterator.Next(); + if (current->type <= -typeRequested) { + message = iterator.Remove(); + break; + } + } + } else if (typeRequested == 0) { + // Return the first message on the queue + message = fMessage.RemoveHead(); + } else { + // Return the first message of type requested + MessageQueue::Iterator iterator = fMessage.GetIterator(); + while (iterator.HasNext()) { + queued_message *current = iterator.Next(); + if (current->type == typeRequested) { + message = iterator.Remove(); + break; + } + } + } + + if (message == NULL) + return NULL; + + fMessageQueue.msg_qnum--; + fMessageQueue.msg_lrpid = getpid(); + fMessageQueue.msg_rtime = real_time_clock(); + fBytesInQueue -= message->length; + MutexLocker _(sXsiMessageCountLock); + sXsiMessageCount--; + // TODO: Wake up any thread waiting on send + return message; +} + + void XsiMessageQueue::SetID() { + fID = real_time_clock(); // The lock is held before calling us while (true) { - if (sMessageQueueHashTable.Lookup(sNextAvailableID) == NULL) + if (sMessageQueueHashTable.Lookup(fID) == NULL) break; - sNextAvailableID++; + fID++; } - fID = sNextAvailableID++; + sGlobalSequenceNumber = (sGlobalSequenceNumber + 1) % UINT_MAX; + fSequenceNumber = sGlobalSequenceNumber; } -void -XsiMessageQueue::UnsetID() -{ - sNextAvailableID = fID; -} - - // #pragma mark - Kernel exported API @@ -489,7 +581,7 @@ int _user_xsi_msgget(key_t key, int flags) { - TRACE(("xsi_msgget: key = %d, flags = %d\n", (nt)key, flags)); + TRACE(("xsi_msgget: key = %d, flags = %d\n", (int)key, flags)); XsiMessageQueue *messageQueue = NULL; Ipc *ipcKey = NULL; // Default assumptions @@ -513,7 +605,7 @@ "for key %d\n", (int)key)); return ENOMEM; } - sIpcHashTable.Lookup(key); + sIpcHashTable.Insert(ipcKey); } else { // The IPC key exist and it already has a message queue if ((flags & IPC_CREAT) && (flags & IPC_EXCL)) { @@ -569,7 +661,99 @@ _user_xsi_msgrcv(int messageQueueID, void *messagePointer, size_t messageSize, long messageType, int messageFlags) { - // TODO + TRACE(("xsi_msgrcv: messageQueueID = %d, messageSize = %ld\n", + messageQueueID, messageSize)); + MutexLocker messageQueueHashLocker(sXsiMessageQueueLock); + XsiMessageQueue *messageQueue = sMessageQueueHashTable.Lookup(messageQueueID); + if (messageQueue == NULL) { + TRACE_ERROR(("xsi_msgrcv: message queue id %d not valid\n", + messageQueueID)); + return EINVAL; + } + MutexLocker messageQueueLocker(messageQueue->Lock()); + messageQueueHashLocker.Unlock(); + + if (messageSize < 0 || messageSize > MAX_BYTES_PER_QUEUE) { + TRACE_ERROR(("xsi_msgrcv: message size is out of range\n")); + return EINVAL; + } + if (!messageQueue->HasPermission()) { + TRACE_ERROR(("xsi_msgrcv: calling process has not permission " + "on message queue id %d, key %d\n", messageQueueID, + (int)messageQueue->IpcKey())); + return EACCES; + } + if (!IS_USER_ADDRESS(messagePointer)) { + TRACE_ERROR(("xsi_msgrcv: message address is not valid\n")); + return B_BAD_ADDRESS; + } + + queued_message *message = NULL; + bool notReceived = true; + while (notReceived) { + message = messageQueue->Remove(messageType); + + if (message == NULL && !(messageFlags & IPC_NOWAIT)) { + // We are going to sleep + struct thread *thread = thread_get_current_thread(); + queued_thread queueEntry(thread, messageSize); + messageQueue->Enqueue(&queueEntry, /* waitForMessage */ true); + + uint32 sequenceNumber = messageQueue->SequenceNumber(); + + TRACE(("xsi_msgrcv: thread %d going to sleep\n", (int)thread->id)); + status_t result + = messageQueue->BlockAndUnlock(thread, &messageQueueLocker); + TRACE(("xsi_msgrcv: thread %d back to life\n", (int)thread->id)); + + messageQueueHashLocker.Lock(); + messageQueue = sMessageQueueHashTable.Lookup(messageQueueID); + if (result == EIDRM || messageQueue == NULL || (messageQueue != NULL + && sequenceNumber != messageQueue->SequenceNumber())) { + TRACE_ERROR(("xsi_msgrcv: message queue id %d (sequence = %ld) " + "got destroyed\n", messageQueueID, sequenceNumber)); + notReceived = false; + result = EIDRM; + } else if (result == B_INTERRUPTED) { + TRACE_ERROR(("xsi_msgrcv: thread %d got interrupted while " + "waiting on message queue %d\n",(int)thread->id, + messageQueueID)); + messageQueue->Deque(&queueEntry, /* waitForMessage */ true); + notReceived = false; + result = EINTR; + } else { + messageQueueLocker.Lock(); + messageQueueHashLocker.Unlock(); + } + } else if (message == NULL) { + // There is not message of type requested and + // we can't wait + return ENOMSG; + } else { + // Message received correctly (so far) + if ((ssize_t)messageSize > message->length + && !(messageFlags & MSG_NOERROR)) { + TRACE_ERROR(("xsi_msgrcv: message too big!\n")); + // Put the message back inside. Since we hold the + // queue message lock, not one else could have filled + // up the queue meanwhile + messageQueue->Insert(message); + return E2BIG; + } + + status_t result + = message->copy_to_user_buffer(messagePointer, messageSize); + if (result != B_OK) { + messageQueue->Insert(message); + return B_BAD_ADDRESS; + } + + delete message; + TRACE(("xsi_msgrcv: message received correctly\n")); + notReceived = false; + } + } + return B_ERROR; } @@ -578,7 +762,7 @@ _user_xsi_msgsnd(int messageQueueID, const void *messagePointer, size_t messageSize, int messageFlags) { - TRACE(("xsi_msgsnd: messageQueueID = %d, messageSize = %Ld\n", + TRACE(("xsi_msgsnd: messageQueueID = %d, messageSize = %ld\n", messageQueueID, messageSize)); MutexLocker messageQueueHashLocker(sXsiMessageQueueLock); XsiMessageQueue *messageQueue = sMessageQueueHashTable.Lookup(messageQueueID); @@ -605,19 +789,52 @@ return B_BAD_ADDRESS; } + queued_message *message + = new(std::nothrow) queued_message(messagePointer, messageSize); + if (message == NULL || message->initOK != true) { + TRACE_ERROR(("xsi_msgsnd: failed to create new message to queue\n")); + delete message; + return ENOMEM; + } + bool notSent = true; while (notSent) { - queued_message *message - = new(std::nothrow) queued_message(messagePointer, messageSize); - if (message == NULL || message->initOK != true) { - TRACE_ERROR(("xsi_msgsnd: failed to create new message to queue\n")); - delete message; - return ENOMEM; - } bool goToSleep = messageQueue->Insert(message); + if (goToSleep && !(messageFlags & IPC_NOWAIT)) { // We are going to sleep - messageQueue->Wait(message); + struct thread *thread = thread_get_current_thread(); + queued_thread queueEntry(thread, messageSize); + messageQueue->Enqueue(&queueEntry, /* waitForMessage */ false); + + uint32 sequenceNumber = messageQueue->SequenceNumber(); + + TRACE(("xsi_msgsnd: thread %d going to sleep\n", (int)thread->id)); + status_t result + = messageQueue->BlockAndUnlock(thread, &messageQueueLocker); + TRACE(("xsi_msgsnd: thread %d back to life\n", (int)thread->id)); + + messageQueueHashLocker.Lock(); + messageQueue = sMessageQueueHashTable.Lookup(messageQueueID); + if (result == EIDRM || messageQueue == NULL || (messageQueue != NULL + && sequenceNumber != messageQueue->SequenceNumber())) { + TRACE_ERROR(("xsi_msgsnd: message queue id %d (sequence = %ld) " + "got destroyed\n", messageQueueID, sequenceNumber)); + delete message; + notSent = false; + result = EIDRM; + } else if (result == B_INTERRUPTED) { + TRACE_ERROR(("xsi_msgsnd: thread %d got interrupted while " + "waiting on message queue %d\n",(int)thread->id, + messageQueueID)); + messageQueue->Deque(&queueEntry, /* waitForMessage */ false); + delete message; + notSent = false; + result = EINTR; + } else { + messageQueueLocker.Lock(); + messageQueueHashLocker.Unlock(); + } } else if (goToSleep) { // We did not send the message and we can't wait delete message; From laplace at mail.berlios.de Thu Sep 4 21:57:34 2008 From: laplace at mail.berlios.de (laplace at mail.berlios.de) Date: Thu, 4 Sep 2008 21:57:34 +0200 Subject: [Haiku-commits] r27328 - haiku/trunk/src/kits/interface Message-ID: <200809041957.m84JvYSO028943@sheep.berlios.de> Author: laplace Date: 2008-09-04 21:57:31 +0200 (Thu, 04 Sep 2008) New Revision: 27328 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27328&view=rev Modified: haiku/trunk/src/kits/interface/ListView.cpp Log: * In BeOS R5 BListItem::DrawItem frame.left is always 0 regardless of BListView origin or update rectangle. This fixes the horizontal scrolling bug in FlattenPictureTest application. * When the list is scrolled horizontally ScrollToSelection() resets the origin x-coordinate to 0. When using the keyboard to move to the next or previous item this is not desired. Now the x-coordinate is not changed from its old value anymore. Modified: haiku/trunk/src/kits/interface/ListView.cpp =================================================================== --- haiku/trunk/src/kits/interface/ListView.cpp 2008-09-04 19:45:02 UTC (rev 27327) +++ haiku/trunk/src/kits/interface/ListView.cpp 2008-09-04 19:57:31 UTC (rev 27328) @@ -179,7 +179,7 @@ if (count == 0) return; - BRect itemFrame(Bounds().left, 0, Bounds().right, -1); + BRect itemFrame(0, 0, Bounds().right, -1); for (int i = 0; i < count; i++) { BListItem* item = ItemAt(i); itemFrame.bottom = itemFrame.top + ceilf(item->Height()) - 1; @@ -800,9 +800,9 @@ return; if (itemFrame.top < Bounds().top) - ScrollTo(0, itemFrame.top); + ScrollTo(itemFrame.left, itemFrame.top); else - ScrollTo(0, itemFrame.bottom - Bounds().Height()); + ScrollTo(itemFrame.left, itemFrame.bottom - Bounds().Height()); } @@ -1023,7 +1023,6 @@ frame.bottom = -1; } else { BListItem* item = ItemAt(index); - frame.left = 0.0; frame.top = item->Top(); frame.bottom = item->Bottom(); } From michael.w.pfeiffer at gmail.com Thu Sep 4 21:59:37 2008 From: michael.w.pfeiffer at gmail.com (Michael Pfeiffer) Date: Thu, 4 Sep 2008 21:59:37 +0200 Subject: [Haiku-commits] r27328 - haiku/trunk/src/kits/interface In-Reply-To: <200809041957.m84JvYSO028943@sheep.berlios.de> References: <200809041957.m84JvYSO028943@sheep.berlios.de> Message-ID: Am 04.09.2008 um 21:57 schrieb laplace at mail.berlios.de: > Author: laplace > Date: 2008-09-04 21:57:31 +0200 (Thu, 04 Sep 2008) > New Revision: 27328 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27328&view=rev > > Modified: > haiku/trunk/src/kits/interface/ListView.cpp > Log: > * In BeOS R5 BListItem::DrawItem frame.left is always 0 regardless > of BListView origin or update rectangle. This fixes the horizontal > scrolling bug in FlattenPictureTest application. > * When the list is scrolled horizontally ScrollToSelection() resets > the origin x-coordinate to 0. When using the keyboard to move to the > next or previous item this is not desired. Now the x-coordinate is > not changed from its old value anymore. Please test that these "fixes" do not have any bad side effects. There is still a bug: When the selected item is outside the visible area, clicking on an item does not select it. Before I file a bug report, maybe someone who knows the code better wants to have a look at it first. - Michael From anevilyak at gmail.com Thu Sep 4 22:03:50 2008 From: anevilyak at gmail.com (Rene Gollent) Date: Thu, 4 Sep 2008 15:03:50 -0500 Subject: [Haiku-commits] r27328 - haiku/trunk/src/kits/interface In-Reply-To: References: <200809041957.m84JvYSO028943@sheep.berlios.de> Message-ID: On Thu, Sep 4, 2008 at 2:59 PM, Michael Pfeiffer wrote: > There is still a bug: When the selected item is outside the visible > area, clicking on an item does not select it. Before I file a bug > report, maybe someone who knows the code better wants to have a look > at it first. > Can I verify that I'm understanding this correctly? As in, you select item A, scroll down so item A is outside the view, and then you cannot select a different item from the visible ones? Regards, Rene From michael.w.pfeiffer at gmail.com Thu Sep 4 22:05:45 2008 From: michael.w.pfeiffer at gmail.com (Michael Pfeiffer) Date: Thu, 4 Sep 2008 22:05:45 +0200 Subject: [Haiku-commits] r27328 - haiku/trunk/src/kits/interface In-Reply-To: References: <200809041957.m84JvYSO028943@sheep.berlios.de> Message-ID: <41520531-DDF9-422C-9660-EDB1C16B5BA9@gmail.com> Am 04.09.2008 um 22:03 schrieb Rene Gollent: > On Thu, Sep 4, 2008 at 2:59 PM, Michael Pfeiffer > wrote: >> There is still a bug: When the selected item is outside the visible >> area, clicking on an item does not select it. Before I file a bug >> report, maybe someone who knows the code better wants to have a look >> at it first. >> > > Can I verify that I'm understanding this correctly? As in, you select > item A, scroll down so item A is outside the view, and then you cannot > select a different item from the visible ones? Exactly. - Michael From anevilyak at gmail.com Thu Sep 4 22:19:32 2008 From: anevilyak at gmail.com (Rene Gollent) Date: Thu, 4 Sep 2008 15:19:32 -0500 Subject: [Haiku-commits] r27328 - haiku/trunk/src/kits/interface In-Reply-To: <41520531-DDF9-422C-9660-EDB1C16B5BA9@gmail.com> References: <200809041957.m84JvYSO028943@sheep.berlios.de> <41520531-DDF9-422C-9660-EDB1C16B5BA9@gmail.com> Message-ID: On Thu, Sep 4, 2008 at 3:05 PM, Michael Pfeiffer wrote: > Exactly. Will look into it tonight then, the item selection code should be mine, though off the top of my head I can't think of what would cause that....do you have a testcase app already? Regards, Rene From michael.w.pfeiffer at gmail.com Thu Sep 4 22:29:23 2008 From: michael.w.pfeiffer at gmail.com (Michael Pfeiffer) Date: Thu, 4 Sep 2008 22:29:23 +0200 Subject: [Haiku-commits] r27328 - haiku/trunk/src/kits/interface In-Reply-To: References: <200809041957.m84JvYSO028943@sheep.berlios.de> <41520531-DDF9-422C-9660-EDB1C16B5BA9@gmail.com> Message-ID: <703EDFD2-E7FC-4173-9B52-A587183D990F@gmail.com> Am 04.09.2008 um 22:19 schrieb Rene Gollent: > On Thu, Sep 4, 2008 at 3:05 PM, Michael Pfeiffer > wrote: >> Exactly. > > Will look into it tonight then, the item selection code should be > mine, though off the top of my head I can't think of what would cause > that....do you have a testcase app already? If you mean a unit test, then no. If you mean an application that reveals the bug then yes. Its called FlattenPictureTest and is in the repository (src/tests/kits/interface/flatten_picture). After the application is launched press ALT+S to fill the list. - Michael From anevilyak at gmail.com Thu Sep 4 22:31:25 2008 From: anevilyak at gmail.com (Rene Gollent) Date: Thu, 4 Sep 2008 15:31:25 -0500 Subject: [Haiku-commits] r27328 - haiku/trunk/src/kits/interface In-Reply-To: <703EDFD2-E7FC-4173-9B52-A587183D990F@gmail.com> References: <200809041957.m84JvYSO028943@sheep.berlios.de> <41520531-DDF9-422C-9660-EDB1C16B5BA9@gmail.com> <703EDFD2-E7FC-4173-9B52-A587183D990F@gmail.com> Message-ID: On Thu, Sep 4, 2008 at 3:29 PM, Michael Pfeiffer wrote: > If you mean a unit test, then no. If you mean an application that > reveals the bug then yes. Its called FlattenPictureTest and is in the > repository (src/tests/kits/interface/flatten_picture). After the > application is launched press ALT+S to fill the list. Perfect, thanks :) Regards, Rene From laplace at mail.berlios.de Thu Sep 4 22:32:33 2008 From: laplace at mail.berlios.de (laplace at mail.berlios.de) Date: Thu, 4 Sep 2008 22:32:33 +0200 Subject: [Haiku-commits] r27329 - haiku/trunk/src/tests/kits/interface/flatten_picture Message-ID: <200809042032.m84KWX9D000527@sheep.berlios.de> Author: laplace Date: 2008-09-04 22:32:31 +0200 (Thu, 04 Sep 2008) New Revision: 27329 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27329&view=rev Modified: haiku/trunk/src/tests/kits/interface/flatten_picture/PictureTest.cpp Log: Removed debug output, it is not required anymore, as scrolling horizontally should work now. Modified: haiku/trunk/src/tests/kits/interface/flatten_picture/PictureTest.cpp =================================================================== --- haiku/trunk/src/tests/kits/interface/flatten_picture/PictureTest.cpp 2008-09-04 19:57:31 UTC (rev 27328) +++ haiku/trunk/src/tests/kits/interface/flatten_picture/PictureTest.cpp 2008-09-04 20:32:31 UTC (rev 27329) @@ -273,8 +273,6 @@ reason = "Pixel at "; reason << x << ", " << y << " differs: " << buffer1 << " != " << buffer2; - // TODO remove when scrolling horizontally works in result list - fprintf(stderr, "%s\n", reason.String()); } From michael.w.pfeiffer at gmail.com Thu Sep 4 22:57:27 2008 From: michael.w.pfeiffer at gmail.com (Michael Pfeiffer) Date: Thu, 4 Sep 2008 22:57:27 +0200 Subject: [Haiku-commits] r27328 - haiku/trunk/src/kits/interface In-Reply-To: References: <200809041957.m84JvYSO028943@sheep.berlios.de> <41520531-DDF9-422C-9660-EDB1C16B5BA9@gmail.com> <703EDFD2-E7FC-4173-9B52-A587183D990F@gmail.com> Message-ID: Am 04.09.2008 um 22:31 schrieb Rene Gollent: > On Thu, Sep 4, 2008 at 3:29 PM, Michael Pfeiffer > wrote: >> If you mean a unit test, then no. If you mean an application that >> reveals the bug then yes. Its called FlattenPictureTest and is in the >> repository (src/tests/kits/interface/flatten_picture). After the >> application is launched press ALT+S to fill the list. I forgot, you can ignore the display artifacts (white vertical lines) when scrolling horizontally this is a bug in that application, not in the interface kit. Since it is a test application I didn't care to fix it already. Maybe I will do that tomorrow. - Michael From julun at mail.berlios.de Fri Sep 5 00:05:41 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Fri, 5 Sep 2008 00:05:41 +0200 Subject: [Haiku-commits] r27330 - haiku/trunk/src/kits/interface Message-ID: <200809042205.m84M5fFH009910@sheep.berlios.de> Author: julun Date: 2008-09-05 00:05:40 +0200 (Fri, 05 Sep 2008) New Revision: 27330 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27330&view=rev Modified: haiku/trunk/src/kits/interface/TextControl.cpp Log: * ResizeToPreferred und GetPreferredSize now behave more closely to R5 this fixes mostly all windows containing TextControls in ArtPaint and should fix also ticket #2543 ArtPaint was calling the BTextControl ctor with an empty rect, followed by ResizeToPreferred, which made in the best case the TextInput visible but it did not take the label into account. Should help more R5 apps. Some more tests on R5 have shown that even if you pass an extra large width, a call to ResizeToPreferred will not respect the passed width. Also the _BTextInput_ seems to grow with the length of the passed label. Modified: haiku/trunk/src/kits/interface/TextControl.cpp =================================================================== --- haiku/trunk/src/kits/interface/TextControl.cpp 2008-09-04 20:32:31 UTC (rev 27329) +++ haiku/trunk/src/kits/interface/TextControl.cpp 2008-09-04 22:05:40 UTC (rev 27330) @@ -120,7 +120,7 @@ if (archive->HasInt32("_a_text")) archive->FindInt32("_a_text", &textAlignment); - + SetAlignment((alignment)labelAlignment, (alignment)textAlignment); if (archive->HasFloat("_divide")) @@ -432,11 +432,12 @@ } if (_width) { - // TODO: this one I need to find out - float width = 20.0f + ceilf(StringWidth(Label())); - if (width < Bounds().Width()) - width = Bounds().Width(); - *_width = width; + *_width = Bounds().Width(); + const char* label = Label(); + if (label) { + float width = ceilf(StringWidth(label)); + *_width = (width * 1.3) + width + 4.0; + } } } @@ -444,8 +445,14 @@ void BTextControl::ResizeToPreferred() { - // TODO: change divider? BView::ResizeToPreferred(); + + fDivider = 0.0; + const char* label = Label(); + if (label) + fDivider = ceil(StringWidth(label)) + 2.0; + + _LayoutTextView(); } @@ -752,10 +759,10 @@ void BTextControl::_ValidateLayout() { - float height; - BTextControl::GetPreferredSize(NULL, &height); + float width, height; + BTextControl::GetPreferredSize(&width, &height); - ResizeTo(Bounds().Width(), height); + ResizeTo(width, height); _LayoutTextView(); From sbenedetto at mail.berlios.de Fri Sep 5 00:14:59 2008 From: sbenedetto at mail.berlios.de (sbenedetto at BerliOS) Date: Fri, 5 Sep 2008 00:14:59 +0200 Subject: [Haiku-commits] r27331 - haiku/trunk/src/system/kernel/posix Message-ID: <200809042214.m84MExF2010869@sheep.berlios.de> Author: sbenedetto Date: 2008-09-05 00:14:59 +0200 (Fri, 05 Sep 2008) New Revision: 27331 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27331&view=rev Modified: haiku/trunk/src/system/kernel/posix/xsi_message_queue.cpp Log: * Fix cast in user_memcpy * Fix comparison send and receive simple message seems to work now. Modified: haiku/trunk/src/system/kernel/posix/xsi_message_queue.cpp =================================================================== --- haiku/trunk/src/system/kernel/posix/xsi_message_queue.cpp 2008-09-04 22:05:40 UTC (rev 27330) +++ haiku/trunk/src/system/kernel/posix/xsi_message_queue.cpp 2008-09-04 22:14:59 UTC (rev 27331) @@ -62,7 +62,7 @@ return; if (user_memcpy(&type, _message, sizeof(long)) != B_OK - || user_memcpy(message, (void *)((long *)_message + sizeof(long)), + || user_memcpy(message, (void *)((char *)_message + sizeof(long)), _length) != B_OK) { free(message); return; @@ -79,7 +79,7 @@ status_t copy_to_user_buffer(void *_message, ssize_t _length) { if (user_memcpy(_message, &type, sizeof(long)) != B_OK - || user_memcpy((void *)((long *)_message + sizeof(long)), message, + || user_memcpy((void *)((char *)_message + sizeof(long)), message, _length) != B_OK) return B_ERROR; return B_OK; @@ -376,7 +376,7 @@ MutexLocker _(sXsiMessageCountLock); if (fBytesInQueue == fMessageQueue.msg_qbytes || fBytesInQueue + message->length > fMessageQueue.msg_qbytes - || sXsiMessageCount <= MAX_XSI_MESSAGE) + || sXsiMessageCount >= MAX_XSI_MESSAGE) return true; fMessage.Add(message); From julun at mail.berlios.de Fri Sep 5 01:44:04 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Fri, 5 Sep 2008 01:44:04 +0200 Subject: [Haiku-commits] r27332 - haiku/trunk/src/kits/interface Message-ID: <200809042344.m84Ni4jp014438@sheep.berlios.de> Author: julun Date: 2008-09-05 01:44:04 +0200 (Fri, 05 Sep 2008) New Revision: 27332 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27332&view=rev Modified: haiku/trunk/src/kits/interface/TextControl.cpp Log: * partly revert, we need to keep the initial width dont overwrite with preferred, it needs to called explicit Modified: haiku/trunk/src/kits/interface/TextControl.cpp =================================================================== --- haiku/trunk/src/kits/interface/TextControl.cpp 2008-09-04 22:14:59 UTC (rev 27331) +++ haiku/trunk/src/kits/interface/TextControl.cpp 2008-09-04 23:44:04 UTC (rev 27332) @@ -759,10 +759,10 @@ void BTextControl::_ValidateLayout() { - float width, height; - BTextControl::GetPreferredSize(&width, &height); + float height; + BTextControl::GetPreferredSize(NULL, &height); - ResizeTo(width, height); + ResizeTo(Bounds().Width(), height); _LayoutTextView(); From anevilyak at gmail.com Fri Sep 5 02:00:44 2008 From: anevilyak at gmail.com (Rene Gollent) Date: Thu, 4 Sep 2008 19:00:44 -0500 Subject: [Haiku-commits] r27328 - haiku/trunk/src/kits/interface In-Reply-To: References: <200809041957.m84JvYSO028943@sheep.berlios.de> <41520531-DDF9-422C-9660-EDB1C16B5BA9@gmail.com> <703EDFD2-E7FC-4173-9B52-A587183D990F@gmail.com> Message-ID: On Thu, Sep 4, 2008 at 3:57 PM, Michael Pfeiffer > > I forgot, you can ignore the display artifacts (white vertical lines) > when scrolling horizontally this is a bug in that application, not in > the interface kit. Since it is a test application I didn't care to fix > it already. Maybe I will do that tomorrow. Ok, having looked into it, this is in fact a drawing problem, not a selection problem. The correct item does get selected, but apparently the view doesn't invalidate it properly. You can verify this by scrolling, picking an item, then switching to another workspace and back. The selection will be highlighted as it should be. Looking into why now. Regards, Rene From anevilyak at gmail.com Fri Sep 5 02:32:17 2008 From: anevilyak at gmail.com (Rene Gollent) Date: Thu, 4 Sep 2008 19:32:17 -0500 Subject: [Haiku-commits] r27328 - haiku/trunk/src/kits/interface In-Reply-To: References: <200809041957.m84JvYSO028943@sheep.berlios.de> <41520531-DDF9-422C-9660-EDB1C16B5BA9@gmail.com> <703EDFD2-E7FC-4173-9B52-A587183D990F@gmail.com> Message-ID: On Thu, Sep 4, 2008 at 7:00 PM, Rene Gollent wrote: > Ok, having looked into it, this is in fact a drawing problem, not a > selection problem. The correct item does get selected, but apparently > the view doesn't invalidate it properly. You can verify this by > scrolling, picking an item, then switching to another workspace and > back. The selection will be highlighted as it should be. Looking into > why now. Has anything changed with respect to maintenance of the clip region recently? The rect that's being invalidated is correct, but it's not actually being redrawn. I don't yet see a logical reason why. Regards, Rene From host.haiku at gmx.de Fri Sep 5 02:40:52 2008 From: host.haiku at gmx.de (julun) Date: Fri, 05 Sep 2008 02:40:52 +0200 Subject: [Haiku-commits] r27328 - haiku/trunk/src/kits/interface In-Reply-To: References: <200809041957.m84JvYSO028943@sheep.berlios.de> <41520531-DDF9-422C-9660-EDB1C16B5BA9@gmail.com> <703EDFD2-E7FC-4173-9B52-A587183D990F@gmail.com> Message-ID: <48C08014.9030406@gmx.de> Hi Rene, Rene Gollent schrieb: > On Thu, Sep 4, 2008 at 7:00 PM, Rene Gollent wrote: >> Ok, having looked into it, this is in fact a drawing problem, not a >> selection problem. The correct item does get selected, but apparently >> the view doesn't invalidate it properly. You can verify this by >> scrolling, picking an item, then switching to another workspace and >> back. The selection will be highlighted as it should be. Looking into >> why now. > > Has anything changed with respect to maintenance of the clip region > recently? The rect that's being invalidated is correct, but it's not > actually being redrawn. I don't yet see a logical reason why. i guess i had a similar problem recently, code that worked before with Invalidate(someRect) needs now a call with Draw(someRect) to be updated properly. Is that what you are seeing? Karsten From anevilyak at gmail.com Fri Sep 5 02:43:48 2008 From: anevilyak at gmail.com (Rene Gollent) Date: Thu, 4 Sep 2008 19:43:48 -0500 Subject: [Haiku-commits] r27328 - haiku/trunk/src/kits/interface In-Reply-To: <48C08014.9030406@gmx.de> References: <200809041957.m84JvYSO028943@sheep.berlios.de> <41520531-DDF9-422C-9660-EDB1C16B5BA9@gmail.com> <703EDFD2-E7FC-4173-9B52-A587183D990F@gmail.com> <48C08014.9030406@gmx.de> Message-ID: On Thu, Sep 4, 2008 at 7:40 PM, julun wrote: > > i guess i had a similar problem recently, code that worked before with > Invalidate(someRect) needs now a call with Draw(someRect) to be > updated properly. Is that what you are seeing? > I actually haven't tried forcing it to call Draw() at that point, but yes, I could swear this used to redraw correctly. Invalidate() should force a Draw() call for the passed in rect, within the constraints of the clipping region. Invalidate() is definitely being called with the correct rect right now. Let me try printing the clip region and seeing what I get back from that. Regards, Rene From anevilyak at gmail.com Fri Sep 5 03:02:28 2008 From: anevilyak at gmail.com (Rene Gollent) Date: Thu, 4 Sep 2008 20:02:28 -0500 Subject: [Haiku-commits] r27314 - haiku/trunk/src/system/kernel In-Reply-To: <200809040032.m840WE4M008339@sheep.berlios.de> References: <200809040032.m840WE4M008339@sheep.berlios.de> Message-ID: On Wed, Sep 3, 2008 at 7:32 PM, wrote: > Author: bonefish > Date: 2008-09-04 02:32:12 +0200 (Thu, 04 Sep 2008) > New Revision: 27314 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27314&view=rev > > Modified: > haiku/trunk/src/system/kernel/sem.cpp > Log: > release_sem_etc(): Reschedule only when a thread with a priority greater > than that of the current thread has been woken up. I didn't see the > reason why the thread should otherwise relinquish the rest of its > quantum. I noticed for instance that client and app server window > threads were ping-ponging more than seemed necessary. In most cases Just curious, could this possibly have also been partly responsible for some of the audio skipping under load problems that we have? Regards, Rene From anevilyak at gmail.com Fri Sep 5 02:52:09 2008 From: anevilyak at gmail.com (Rene Gollent) Date: Thu, 4 Sep 2008 19:52:09 -0500 Subject: [Haiku-commits] r27328 - haiku/trunk/src/kits/interface In-Reply-To: References: <200809041957.m84JvYSO028943@sheep.berlios.de> <41520531-DDF9-422C-9660-EDB1C16B5BA9@gmail.com> <703EDFD2-E7FC-4173-9B52-A587183D990F@gmail.com> <48C08014.9030406@gmx.de> Message-ID: On Thu, Sep 4, 2008 at 7:43 PM, Rene Gollent wrote: > On Thu, Sep 4, 2008 at 7:40 PM, julun wrote: >> >> i guess i had a similar problem recently, code that worked before with >> Invalidate(someRect) needs now a call with Draw(someRect) to be >> updated properly. Is that what you are seeing? >> Clipping region looks correct also: _Select() asking to redraw item 69 (0x180498a8) BRect(l:0.0, t:2020.0, r:606.0, b:2412.0) data[0] = BRect(l:0.0, t:2020.0, r:606.0, b:2412.0) ItemFrame(69) BRect(l:0.0, t:2286.0, r:606.0, b:2319.0) I'm confused as to why this only happens if you select and then scroll though. The only difference I can think of is that there will be an _Deselect() call to tell the previously selected item to redraw itself in normal unselected state, which in this case will be offscreen. Regards, Rene From mmu_man at mail.berlios.de Fri Sep 5 03:52:32 2008 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Fri, 5 Sep 2008 03:52:32 +0200 Subject: [Haiku-commits] r27333 - haiku/trunk/src/add-ons/kernel/bus_managers/pci Message-ID: <200809050152.m851qWSP025585@sheep.berlios.de> Author: mmu_man Date: 2008-09-05 03:52:31 +0200 (Fri, 05 Sep 2008) New Revision: 27333 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27333&view=rev Modified: haiku/trunk/src/add-ons/kernel/bus_managers/pci/pci_fixup.cpp Log: Sanitized version of my ATI IXP fix. This one checks for host bridge PCI ID so it shouldn't harm other machines. Works for me (cold boots ok). This should fix bug #2342. Please test. Modified: haiku/trunk/src/add-ons/kernel/bus_managers/pci/pci_fixup.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/pci/pci_fixup.cpp 2008-09-04 23:44:04 UTC (rev 27332) +++ haiku/trunk/src/add-ons/kernel/bus_managers/pci/pci_fixup.cpp 2008-09-05 01:52:31 UTC (rev 27333) @@ -6,6 +6,8 @@ #include "pci.h" #include "pci_fixup.h" +#include + #include @@ -153,6 +155,37 @@ } +static void +ati_fixup_ixp(PCI *pci, int domain, uint8 bus, uint8 device, uint8 function, uint16 deviceId) +{ +#ifdef __INTEL__ + /* ATI Technologies Inc, IXP chipset: + * This chipset seems broken, at least on my laptop I must force + * the timer IRQ trigger mode, else no interrupt comes in. + * mmu_man. + */ + // XXX: should I use host or isa bridges for detection ?? + switch (deviceId) { + // Host bridges + case 0x5950: // RS480 Host Bridge + case 0x5830: + break; + // ISA bridges + case 0x4377: // IXP SB400 PCI-ISA Bridge + default: + return; + } + dprintf("ati_fixup_ixp: domain %u, bus %u, device %u, function %u, deviceId 0x%04x\n", + domain, bus, device, function, deviceId); + + dprintf("ati_fixup_ixp: found IXP chipset, forcing IRQ 0 as level triggered.\n"); + // XXX: maybe use pic_*() ? + arch_int_configure_io_interrupt(0, B_LEVEL_TRIGGERED); + +#endif +} + + void pci_fixup_device(PCI *pci, int domain, uint8 bus, uint8 device, uint8 function) { @@ -172,6 +205,10 @@ case 0x8086: intel_fixup_ahci(pci, domain, bus, device, function, deviceId); break; + + case 0x1002: + ati_fixup_ixp(pci, domain, bus, device, function, deviceId); + break; } } From stefano.ceccherini at gmail.com Fri Sep 5 10:45:35 2008 From: stefano.ceccherini at gmail.com (Stefano Ceccherini) Date: Fri, 5 Sep 2008 10:45:35 +0200 Subject: [Haiku-commits] r27316 - haiku/trunk/src/tests/kits/interface/flatten_picture In-Reply-To: References: <200809040930.m849UVpe019278@sheep.berlios.de> Message-ID: <894b9700809050145n27358c89ibf726ae19bbf66f1@mail.gmail.com> 2008/9/4 Michael Pfeiffer : > The bitmap created from "direct drawing" does not match the one from > "restored picture drawing". > The alpha value in the bitmap from the first is 0x18 and the other is > 0x00. > The test application prints now to stderr the position of the first > not matching pixel and its value as a "long" hexadecimal value for > RGB32 this is two digits for A,R,G and B. The information is also > appended to the message in the list, however scrolling horizontally > does not work correctly, so to see the reason you need a high > horizontal screen resolution. > Thanks for these changes. > I have not examined yet if this is because of a bug in the testing > application. Will do when I have time. > I have also noticed that doing the tests on all color spaces fails because, it seems, because a bitmap is recycled without being emptied: IOW: you can see traces of an old drawing on it. From jackburton at mail.berlios.de Fri Sep 5 11:10:28 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Fri, 5 Sep 2008 11:10:28 +0200 Subject: [Haiku-commits] r27334 - haiku/trunk/build/jam Message-ID: <200809050910.m859ASWG025049@sheep.berlios.de> Author: jackburton Date: 2008-09-05 11:10:24 +0200 (Fri, 05 Sep 2008) New Revision: 27334 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27334&view=rev Modified: haiku/trunk/build/jam/HaikuImage Log: Removed PictureTest from the image since it's not that cool as a demo, and we have a better unit test anyway (FlattenPictureTest) Modified: haiku/trunk/build/jam/HaikuImage =================================================================== --- haiku/trunk/build/jam/HaikuImage 2008-09-05 01:52:31 UTC (rev 27333) +++ haiku/trunk/build/jam/HaikuImage 2008-09-05 09:10:24 UTC (rev 27334) @@ -64,7 +64,7 @@ ScreenSaver Sounds Time VirtualMemory ; BEOS_DEMOS = BSnow Chart Clock $(X86_ONLY)Cortex FontDemo - $(X86_ONLY)GLDirectMode $(X86_ONLY)GLTeapot Mandelbrot Pairs PictureTest + $(X86_ONLY)GLDirectMode $(X86_ONLY)GLTeapot Mandelbrot Pairs Playground Pulse Sudoku ; BEOS_SYSTEM_LIBS = libbe.so $(HAIKU_LIBSTDC++) libmedia.so libtracker.so @@ -293,11 +293,6 @@ = [ FDirName $(HAIKU_TOP) src apps mail ] ; AddFilesToHaikuImage beos etc word_dictionary : $(spellFiles) ; -local svgFiles = "lion.svg" ; -SEARCH on $(svgFiles) - = [ FDirName $(HAIKU_TOP) src tests kits interface picture ] ; -AddFilesToHaikuImage beos etc artwork : $(svgFiles) ; - local etcFiles = inputrc profile teapot.data ; etcFiles = $(etcFiles:G=etc) ; SEARCH on $(etcFiles) = [ FDirName $(HAIKU_TOP) data etc ] ; From bga at bug-br.org.br Fri Sep 5 11:25:32 2008 From: bga at bug-br.org.br (Bruno Albuquerque) Date: Fri, 05 Sep 2008 06:25:32 -0300 Subject: [Haiku-commits] r27328 - haiku/trunk/src/kits/interface In-Reply-To: References: <200809041957.m84JvYSO028943@sheep.berlios.de> <41520531-DDF9-422C-9660-EDB1C16B5BA9@gmail.com> <703EDFD2-E7FC-4173-9B52-A587183D990F@gmail.com> Message-ID: <48C0FB0C.7060202@bug-br.org.br> Rene Gollent escreveu: >> Ok, having looked into it, this is in fact a drawing problem, not a >> selection problem. The correct item does get selected, but apparently >> the view doesn't invalidate it properly. You can verify this by >> scrolling, picking an item, then switching to another workspace and >> back. The selection will be highlighted as it should be. Looking into >> why now. > > Has anything changed with respect to maintenance of the clip region > recently? The rect that's being invalidated is correct, but it's not > actually being redrawn. I don't yet see a logical reason why. I am seeing similar things: 1 - MDR status window has update problems. 2 - DriveSetup has update problems (collapsing/expanding the device trees only shows after you either obscure the window partially or after you click on the window. -Bruno From superstippi at gmx.de Fri Sep 5 11:37:02 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Fri, 05 Sep 2008 11:37:02 +0200 Subject: [Haiku-commits] r27314 - haiku/trunk/src/system/kernel In-Reply-To: References: <200809040032.m840WE4M008339@sheep.berlios.de> Message-ID: <20080905093702.181740@gmx.net> -------- Original-Nachricht -------- > Datum: Thu, 4 Sep 2008 20:02:28 -0500 > Von: "Rene Gollent" > An: "SVN commits to the Haiku source repository" > Betreff: Re: [Haiku-commits] r27314 - haiku/trunk/src/system/kernel > On Wed, Sep 3, 2008 at 7:32 PM, wrote: > > Author: bonefish > > Date: 2008-09-04 02:32:12 +0200 (Thu, 04 Sep 2008) > > New Revision: 27314 > > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27314&view=rev > > > > Modified: > > haiku/trunk/src/system/kernel/sem.cpp > > Log: > > release_sem_etc(): Reschedule only when a thread with a priority greater > > than that of the current thread has been woken up. I didn't see the > > reason why the thread should otherwise relinquish the rest of its > > quantum. I noticed for instance that client and app server window > > threads were ping-ponging more than seemed necessary. In most cases > > Just curious, could this possibly have also been partly responsible > for some of the audio skipping under load problems that we have? I've had the same thought and experimented a bit yesterday. I can reduce the OSS driver buffer (and latency) by quite a bit, but when I launch Firefox, I can still hear some clicks.In the OSS Node, the realtime thread that feeds the audio buffers to the driver has to grab a lock, fetch the pointer for the next BBuffer from a list and then unlocks again. At this moment, it could be rescheduled due to the previous sem code before feeding the BBuffer to the driver. Anyhow, the situation does not improve substantially enough after the change, although subjectively, it seems to have improved somewhat. Also the lock used is a BLocker, so the semaphore is likely not even used very often (benaphore style locking). Best regards, -Stephan From ingo_weinhold at gmx.de Fri Sep 5 15:26:56 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Fri, 05 Sep 2008 15:26:56 +0200 Subject: [Haiku-commits] r27314 - haiku/trunk/src/system/kernel In-Reply-To: <20080905093702.181740@gmx.net> References: <200809040032.m840WE4M008339@sheep.berlios.de> <20080905093702.181740@gmx.net> Message-ID: <20080905152656.731.2@knochen-vm.localdomain> On 2008-09-05 at 11:37:02 [+0200], Stephan Assmus wrote: > -------- Original-Nachricht -------- > > Datum: Thu, 4 Sep 2008 20:02:28 -0500 > > Von: "Rene Gollent" [...] > > Just curious, could this possibly have also been partly responsible > > for some of the audio skipping under load problems that we have? > > I've had the same thought and experimented a bit yesterday. I can reduce > the OSS driver buffer (and latency) by quite a bit, but when I launch > Firefox, I can still hear some clicks.In the OSS Node, the realtime thread > that feeds the audio buffers to the driver has to grab a lock, fetch the > pointer for the next BBuffer from a list and then unlocks again. At this > moment, it could be rescheduled due to the previous sem code before feeding > the BBuffer to the driver. If the thread does indeed have real-time priority (>= 100), rescheduling would not have unscheduled it, unless there was a thread with an even higher priority. I.e. the only negative effect in this case should have been the unnecessary trip through the scheduler. Generally I wouldn't expect this change to have any effect on latencies at all. It should only save a few unnecessary context switches, though increasing the throughput (as in my test). > Anyhow, the situation does not improve > substantially enough after the change, although subjectively, it seems to > have improved somewhat. Also the lock used is a BLocker, so the semaphore > is likely not even used very often (benaphore style locking). The scheduler kernel tracing has been in place for a while now; you just have to enable it to be able to verify whether something went wrong with the scheduling. The "scheduler" debugger command tells you about latencies and wait times after preemption. So it really should take only a few seconds to find out whether there are unusually high figures involved. If not, then it's likely not a scheduler problem and syscall tracing can help to find out why the audio thread is late (if that is the case at all). CU, Ingo From laplace at mail.berlios.de Fri Sep 5 15:33:15 2008 From: laplace at mail.berlios.de (laplace at mail.berlios.de) Date: Fri, 5 Sep 2008 15:33:15 +0200 Subject: [Haiku-commits] r27335 - haiku/trunk/src/tests/kits/interface/flatten_picture Message-ID: <200809051333.m85DXF3S010964@sheep.berlios.de> Author: laplace Date: 2008-09-05 15:33:13 +0200 (Fri, 05 Sep 2008) New Revision: 27335 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27335&view=rev Modified: haiku/trunk/src/tests/kits/interface/flatten_picture/TestResultItem.cpp Log: Fixed display artifacts when scrolling horizontally. Modified: haiku/trunk/src/tests/kits/interface/flatten_picture/TestResultItem.cpp =================================================================== --- haiku/trunk/src/tests/kits/interface/flatten_picture/TestResultItem.cpp 2008-09-05 09:10:24 UTC (rev 27334) +++ haiku/trunk/src/tests/kits/interface/flatten_picture/TestResultItem.cpp 2008-09-05 13:33:13 UTC (rev 27335) @@ -34,20 +34,13 @@ TestResultItem::DrawItem(BView *owner, BRect itemRect, bool drawEverthing) { owner->SetDrawingMode(B_OP_COPY); + owner->PushState(); if (IsSelected()) { - owner->SetHighColor(128, 128, 128); + rgb_color lowColor = owner->LowColor(); + owner->SetHighColor(tint_color(lowColor, B_DARKEN_2_TINT)); } - else { - owner->SetHighColor(255, 255, 255); - } - owner->StrokeRect(itemRect); - owner->PopState(); - - itemRect.InsetBy(1, 1); - - owner->PushState(); - if (fOk) { + else if (fOk) { // green background color on success owner->SetHighColor(200, 255, 200); } @@ -57,6 +50,8 @@ } owner->FillRect(itemRect); owner->PopState(); + + itemRect.InsetBy(1, 1); owner->MovePenTo(itemRect.left+1, itemRect.top+1); if (fDirectBitmap != NULL) { From laplace at mail.berlios.de Fri Sep 5 15:39:07 2008 From: laplace at mail.berlios.de (laplace at mail.berlios.de) Date: Fri, 5 Sep 2008 15:39:07 +0200 Subject: [Haiku-commits] r27336 - haiku/trunk/src/tests/kits/interface/flatten_picture Message-ID: <200809051339.m85Dd79c011322@sheep.berlios.de> Author: laplace Date: 2008-09-05 15:39:06 +0200 (Fri, 05 Sep 2008) New Revision: 27336 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27336&view=rev Modified: haiku/trunk/src/tests/kits/interface/flatten_picture/PictureTest.cpp Log: * Used wrong argument order for pixelChunk and rowAlignment in get_pixel_size_for(), so bitmap comparison was wrong for a color spaces with bytes per pixel != 4. Modified: haiku/trunk/src/tests/kits/interface/flatten_picture/PictureTest.cpp =================================================================== --- haiku/trunk/src/tests/kits/interface/flatten_picture/PictureTest.cpp 2008-09-05 13:33:13 UTC (rev 27335) +++ haiku/trunk/src/tests/kits/interface/flatten_picture/PictureTest.cpp 2008-09-05 13:39:06 UTC (rev 27336) @@ -292,7 +292,7 @@ size_t rowAlignment; size_t pixelChunk; size_t pixelsPerChunk; - if (get_pixel_size_for(bitmap1->ColorSpace(), &rowAlignment, &pixelChunk, + if (get_pixel_size_for(bitmap1->ColorSpace(), &pixelChunk, &rowAlignment, &pixelsPerChunk) != B_OK) { reason = "get_pixel_size_for() not supported for this color space"; return false; From michael.w.pfeiffer at gmail.com Fri Sep 5 18:11:40 2008 From: michael.w.pfeiffer at gmail.com (Michael Pfeiffer) Date: Fri, 5 Sep 2008 18:11:40 +0200 Subject: [Haiku-commits] r27316 - haiku/trunk/src/tests/kits/interface/flatten_picture In-Reply-To: <894b9700809050145n27358c89ibf726ae19bbf66f1@mail.gmail.com> References: <200809040930.m849UVpe019278@sheep.berlios.de> <894b9700809050145n27358c89ibf726ae19bbf66f1@mail.gmail.com> Message-ID: Am 05.09.2008 um 10:45 schrieb Stefano Ceccherini: > I have also noticed that doing the tests on all color spaces fails > because, it seems, because a bitmap is recycled without being emptied: > IOW: you can see traces of an old drawing on it. It seems that all color spaces are effected but B_RGB32. The application does not cache BBitmaps so their "Bits" are initialized in the constructor, which I enforced too using memset after construction of the BBitmaps. I could get rid of the "traces" if an additional step was performed before the drawing operations of a test case: view->SetHighColor(255, 255, 255); view->FillRect(BRect(0, 0, 1000, 1000)); view->SetHighColor(0, 0, 0); view->Sync(); In other words the BBitmap was again filled with white color, which is the default for a BBitmap. Without knowing the app_server drawing code, my impression is, that this code did reset some internal "offscreen" buffer that is used for drawing before the results are written back into the BBitmap. Hope these findings help in fixing the problem. - Michael -------------- next part -------------- An HTML attachment was scrubbed... URL: From anevilyak at gmail.com Fri Sep 5 18:11:54 2008 From: anevilyak at gmail.com (Rene Gollent) Date: Fri, 5 Sep 2008 11:11:54 -0500 Subject: [Haiku-commits] r27328 - haiku/trunk/src/kits/interface In-Reply-To: <48C0FB0C.7060202@bug-br.org.br> References: <200809041957.m84JvYSO028943@sheep.berlios.de> <41520531-DDF9-422C-9660-EDB1C16B5BA9@gmail.com> <703EDFD2-E7FC-4173-9B52-A587183D990F@gmail.com> <48C0FB0C.7060202@bug-br.org.br> Message-ID: On Fri, Sep 5, 2008 at 4:25 AM, Bruno Albuquerque wrote: > I am seeing similar things: > > 1 - MDR status window has update problems. > 2 - DriveSetup has update problems (collapsing/expanding the device > trees only shows after you either obscure the window partially or after > you click on the window. The problem appears to be the check in View.cpp line 3413. If the update requested flag is already set, it will not flush the link. As a consequence the message doesn't get sent to the app_server and the invalidate never happens, hence the drawing issue. What is the reasoning behind that conditional? Stephan? Regards, Rene From superstippi at gmx.de Fri Sep 5 19:01:52 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Fri, 05 Sep 2008 19:01:52 +0200 Subject: [Haiku-commits] r27328 - haiku/trunk/src/kits/interface In-Reply-To: References: <200809041957.m84JvYSO028943@sheep.berlios.de> <41520531-DDF9-422C-9660-EDB1C16B5BA9@gmail.com> <703EDFD2-E7FC-4173-9B52-A587183D990F@gmail.com> <48C0FB0C.7060202@bug-br.org.br> Message-ID: <20080905190152.648.1@bepc.1220630502.fake> On 2008-09-05 at 18:49:55 [+0200], Rene Gollent wrote: > On Fri, Sep 5, 2008 at 4:25 AM, Bruno Albuquerque > wrote: > > I am seeing similar things: > > > > 1 - MDR status window has update problems. > > 2 - DriveSetup has update problems (collapsing/expanding the device > > trees only shows after you either obscure the window partially or after > > you click on the window. > > The problem appears to be the check in View.cpp line 3413. If the update > requested flag is already set, it will not flush the link. As a > consequence the message doesn't get sent to the app_server and the > invalidate never happens, hence the drawing issue. What is the reasoning > behind that conditional? Stephan? The reason is that flushing should not be necessary. This code "appeared" to work before, but maybe I am missing something. Maybe it was always broken and perhaps Ingo's change to the sem code exposed this bug (he specifically mentioned too much ping-ponging between clients and app_server)? The theory is that the app_server would pull all messages from the port before it sends the update request to the client. But perhaps the problem is that some data simply has not been sent over the port yet. Data is only sent when either the buffer is full or the client specifically requests it (flushes the link). It definitely looks like the data in the queue is written correctly but has simply not been sent. When the app_server processes a redraw request, it is in a synchronous communication with the client app, so it cannot pull more messages from the port at this point. I need to think about it. For now, please just disable this check, it will have no other negative consequences, it was only introduced to make Invalidate() a much cheaper call. Best regards, -Stephan From anevilyak at mail.berlios.de Fri Sep 5 19:07:38 2008 From: anevilyak at mail.berlios.de (anevilyak at BerliOS) Date: Fri, 5 Sep 2008 19:07:38 +0200 Subject: [Haiku-commits] r27337 - haiku/trunk/src/kits/interface Message-ID: <200809051707.m85H7cVT007796@sheep.berlios.de> Author: anevilyak Date: 2008-09-05 19:07:36 +0200 (Fri, 05 Sep 2008) New Revision: 27337 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27337&view=rev Modified: haiku/trunk/src/kits/interface/View.cpp Log: Temporarily disable this check in Invalidate() as requested by Stephan. This fixes the problem with redraws seen in FlattenPictureTest and a few other places. Modified: haiku/trunk/src/kits/interface/View.cpp =================================================================== --- haiku/trunk/src/kits/interface/View.cpp 2008-09-05 13:39:06 UTC (rev 27336) +++ haiku/trunk/src/kits/interface/View.cpp 2008-09-05 17:07:36 UTC (rev 27337) @@ -3410,10 +3410,14 @@ fOwner->fLink->StartMessage(AS_VIEW_INVALIDATE_RECT); fOwner->fLink->Attach(invalRect); +// TODO: determine why this check isn't working correctly. +#if 0 if (!fOwner->fUpdateRequested) { fOwner->fLink->Flush(); fOwner->fUpdateRequested = true; } +#endif + fOwner->fLink->Flush(); } From anevilyak at gmail.com Fri Sep 5 19:09:00 2008 From: anevilyak at gmail.com (Rene Gollent) Date: Fri, 5 Sep 2008 12:09:00 -0500 Subject: [Haiku-commits] r27328 - haiku/trunk/src/kits/interface In-Reply-To: <20080905190152.648.1@bepc.1220630502.fake> References: <200809041957.m84JvYSO028943@sheep.berlios.de> <703EDFD2-E7FC-4173-9B52-A587183D990F@gmail.com> <48C0FB0C.7060202@bug-br.org.br> <20080905190152.648.1@bepc.1220630502.fake> Message-ID: On Fri, Sep 5, 2008 at 12:01 PM, Stephan Assmus wrote: > point. I need to think about it. For now, please just disable this check, > it will have no other negative consequences, it was only introduced to make > Invalidate() a much cheaper call. Done, thanks for looking into it! Regards, Rene From bga at bug-br.org.br Fri Sep 5 19:17:55 2008 From: bga at bug-br.org.br (Bruno Albuquerque) Date: Fri, 05 Sep 2008 14:17:55 -0300 Subject: [Haiku-commits] r27328 - haiku/trunk/src/kits/interface In-Reply-To: <20080905190152.648.1@bepc.1220630502.fake> References: <200809041957.m84JvYSO028943@sheep.berlios.de> <41520531-DDF9-422C-9660-EDB1C16B5BA9@gmail.com> <703EDFD2-E7FC-4173-9B52-A587183D990F@gmail.com> <48C0FB0C.7060202@bug-br.org.br> <20080905190152.648.1@bepc.1220630502.fake> Message-ID: <48C169C3.5030501@bug-br.org.br> Stephan Assmus wrote: > The reason is that flushing should not be necessary. This code "appeared" > to work before, but maybe I am missing something. Maybe it was always > broken and perhaps Ingo's change to the sem code exposed this bug (he > specifically mentioned too much ping-ponging between clients and > app_server)? Nope. This bug predates Ingo's scheduler change. -Bruno From korli at mail.berlios.de Fri Sep 5 22:58:04 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Fri, 5 Sep 2008 22:58:04 +0200 Subject: [Haiku-commits] r27338 - in haiku/trunk/src/system/libroot/posix/glibc/arch: generic x86 Message-ID: <200809052058.m85Kw4es005032@sheep.berlios.de> Author: korli Date: 2008-09-05 22:58:03 +0200 (Fri, 05 Sep 2008) New Revision: 27338 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27338&view=rev Added: haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_lroundl.c haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_matherr.c haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_roundl.c Modified: haiku/trunk/src/system/libroot/posix/glibc/arch/x86/Jamfile Log: added matherr, lroundl and roundl Added: haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_lroundl.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_lroundl.c 2008-09-05 17:07:36 UTC (rev 27337) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_lroundl.c 2008-09-05 20:58:03 UTC (rev 27338) @@ -0,0 +1,81 @@ +/* Round long double value to long int. + Copyright (C) 1997, 2004 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper , 1997. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include + +#include "math_private.h" + + +long int +__lroundl (long double x) +{ + int32_t j0; + u_int32_t se, i1, i0; + long int result; + int sign; + + GET_LDOUBLE_WORDS (se, i0, i1, x); + j0 = (se & 0x7fff) - 0x3fff; + sign = (se & 0x8000) != 0 ? -1 : 1; + + if (j0 < 31) + { + if (j0 < 0) + return j0 < -1 ? 0 : sign; + else + { + u_int32_t j = i0 + (0x40000000 >> j0); + if (j < i0) + { + j >>= 1; + j |= 0x80000000; + ++j0; + } + + result = j >> (31 - j0); + } + } + else if (j0 < (int32_t) (8 * sizeof (long int)) - 1) + { + if (j0 >= 63) + result = ((long int) i0 << (j0 - 31)) | (i1 << (j0 - 63)); + else + { + u_int32_t j = i1 + (0x80000000 >> (j0 - 31)); + if (j < i1) + ++i0; + + if (j0 == 31) + result = (long int) i0; + else + result = ((long int) i0 << (j0 - 31)) | (j >> (63 - j0)); + } + } + else + { + /* The number is too large. It is left implementation defined + what happens. */ + return (long int) x; + } + + return sign * result; +} + +weak_alias (__lroundl, lroundl) Added: haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_matherr.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_matherr.c 2008-09-05 17:07:36 UTC (rev 27337) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_matherr.c 2008-09-05 20:58:03 UTC (rev 27338) @@ -0,0 +1,35 @@ +/* @(#)s_matherr.c 5.1 93/09/24 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#if defined(LIBM_SCCS) && !defined(lint) +static char rcsid[] = "$NetBSD: s_matherr.c,v 1.6 1995/05/10 20:47:53 jtc Exp $"; +#endif + +#include "math.h" +#include "math_private.h" + +#ifdef __STDC__ + int + weak_function + __matherr(struct exception *x) +#else + int + weak_function + __matherr(x) + struct exception *x; +#endif +{ + int n=0; + if(x->arg1!=x->arg1) return 0; + return n; +} +weak_alias (__matherr, matherr) Added: haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_roundl.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_roundl.c 2008-09-05 17:07:36 UTC (rev 27337) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_roundl.c 2008-09-05 20:58:03 UTC (rev 27338) @@ -0,0 +1,106 @@ +/* Round long double to integer away from zero. + Copyright (C) 1997 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper , 1997. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include + +#include "math_private.h" + + +static const long double huge = 1.0e4930; + + +long double +__roundl (long double x) +{ + int32_t j0; + u_int32_t se, i1, i0; + + GET_LDOUBLE_WORDS (se, i0, i1, x); + j0 = (se & 0x7fff) - 0x3fff; + if (j0 < 31) + { + if (j0 < 0) + { + if (huge + x > 0.0) + { + se &= 0x8000; + i0 = i1 = 0; + if (j0 == -1) + { + se |= 0x3fff; + i0 = 0x80000000; + } + } + } + else + { + u_int32_t i = 0x7fffffff >> j0; + if (((i0 & i) | i1) == 0) + /* X is integral. */ + return x; + if (huge + x > 0.0) + { + /* Raise inexact if x != 0. */ + u_int32_t j = i0 + (0x40000000 >> j0); + if (j < i0) + se += 1; + i0 = (j & ~i) | 0x80000000; + i1 = 0; + } + } + } + else if (j0 > 62) + { + if (j0 == 0x4000) + /* Inf or NaN. */ + return x + x; + else + return x; + } + else + { + u_int32_t i = 0xffffffff >> (j0 - 31); + if ((i1 & i) == 0) + /* X is integral. */ + return x; + + if (huge + x > 0.0) + { + /* Raise inexact if x != 0. */ + u_int32_t j = i1 + (1 << (62 - j0)); + if (j < i1) + { + u_int32_t k = i0 + 1; + if (k < i0) + { + se += 1; + k |= 0x80000000; + } + i0 = k; + } + i1 = j; + } + i1 &= ~i; + } + + SET_LDOUBLE_WORDS (x, se, i0, i1); + return x; +} +weak_alias (__roundl, roundl) Modified: haiku/trunk/src/system/libroot/posix/glibc/arch/x86/Jamfile =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/x86/Jamfile 2008-09-05 17:07:36 UTC (rev 27337) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/x86/Jamfile 2008-09-05 20:58:03 UTC (rev 27338) @@ -56,12 +56,13 @@ s_isinf.c s_isinff.c s_isnan.c s_isnanf.c s_ldexp.c s_ldexpf.c #s_ldexpl.c - s_lround.c s_lroundf.c + s_lround.c s_lroundf.c s_lroundl.c + s_matherr.c s_modf.c s_modff.c # s_modfl.c s_nan.c s_nanf.c s_nextafter.c s_signbit.c s_signbitf.c s_signbitl.c - s_round.c s_roundf.c # s_roundl.c + s_round.c s_roundf.c s_roundl.c s_signgam.c s_tanh.c s_tanhf.c From ingo_weinhold at gmx.de Fri Sep 5 23:57:52 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Fri, 05 Sep 2008 23:57:52 +0200 Subject: [Haiku-commits] r27328 - haiku/trunk/src/kits/interface In-Reply-To: <20080905190152.648.1@bepc.1220630502.fake> References: <200809041957.m84JvYSO028943@sheep.berlios.de> <41520531-DDF9-422C-9660-EDB1C16B5BA9@gmail.com> <703EDFD2-E7FC-4173-9B52-A587183D990F@gmail.com> <48C0FB0C.7060202@bug-br.org.br> <20080905190152.648.1@bepc.1220630502.fake> Message-ID: <20080905235752.535.3@knochen-vm.localdomain> On 2008-09-05 at 19:01:52 [+0200], Stephan Assmus wrote: > > On 2008-09-05 at 18:49:55 [+0200], Rene Gollent wrote: > > On Fri, Sep 5, 2008 at 4:25 AM, Bruno Albuquerque > > wrote: > > > I am seeing similar things: > > > > > > 1 - MDR status window has update problems. > > > 2 - DriveSetup has update problems (collapsing/expanding the device > > > trees only shows after you either obscure the window partially or after > > > you click on the window. > > > > The problem appears to be the check in View.cpp line 3413. If the update > > requested flag is already set, it will not flush the link. As a > > consequence the message doesn't get sent to the app_server and the > > invalidate never happens, hence the drawing issue. What is the reasoning > > behind that conditional? Stephan? > > The reason is that flushing should not be necessary. This code "appeared" > to work before, but maybe I am missing something. Maybe it was always > broken and perhaps Ingo's change to the sem code exposed this bug (he > specifically mentioned too much ping-ponging between clients and > app_server)? The theory is that the app_server would pull all messages from > the port before it sends the update request to the client. But perhaps the > problem is that some data simply has not been sent over the port yet. Data > is only sent when either the buffer is full or the client specifically > requests it (flushes the link). It definitely looks like the data in the > queue is written correctly but has simply not been sent. When the > app_server processes a redraw request, it is in a synchronous communication > with the client app, so it cannot pull more messages from the port at this > point. I need to think about it. For now, please just disable this check, > it will have no other negative consequences, it was only introduced to make > Invalidate() a much cheaper call. Maybe I miss something, but in the BWindow::DispatchMessage() _UPDATE_ case, the client sends an AS_BEGIN_UPDATE and waits for a reply. So obviously all preceding Invalidate()s should have been processed by the time the app server gets the message. The only thing I can imagine that can go wrong is that the initial Invalidate() region is totally obscured, so that the app server doesn't send an _UPDATE_ message in the first place. Not knowing the respective app server code, I can't say whether that could really happen. CU, Ingo From superstippi at gmx.de Sat Sep 6 00:03:46 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Sat, 06 Sep 2008 00:03:46 +0200 Subject: [Haiku-commits] r27328 - haiku/trunk/src/kits/interface In-Reply-To: <20080905235752.535.3@knochen-vm.localdomain> References: <200809041957.m84JvYSO028943@sheep.berlios.de> <41520531-DDF9-422C-9660-EDB1C16B5BA9@gmail.com> <703EDFD2-E7FC-4173-9B52-A587183D990F@gmail.com> <48C0FB0C.7060202@bug-br.org.br> <20080905190152.648.1@bepc.1220630502.fake> <20080905235752.535.3@knochen-vm.localdomain> Message-ID: <20080906000346.9790.1@bepc.1220644607.fake> On 2008-09-05 at 23:58:14 [+0200], Ingo Weinhold wrote: > > On 2008-09-05 at 19:01:52 [+0200], Stephan Assmus > wrote: > > > > On 2008-09-05 at 18:49:55 [+0200], Rene Gollent > > wrote: > > > On Fri, Sep 5, 2008 at 4:25 AM, Bruno Albuquerque > > > wrote: > > > > I am seeing similar things: > > > > > > > > 1 - MDR status window has update problems. > > > > 2 - DriveSetup has update problems (collapsing/expanding the device > > > > trees only shows after you either obscure the window partially or > > > > after you click on the window. > > > > > > The problem appears to be the check in View.cpp line 3413. If the > > > update requested flag is already set, it will not flush the link. As > > > a consequence the message doesn't get sent to the app_server and the > > > invalidate never happens, hence the drawing issue. What is the > > > reasoning behind that conditional? Stephan? > > > > The reason is that flushing should not be necessary. This code > > "appeared" to work before, but maybe I am missing something. Maybe it > > was always broken and perhaps Ingo's change to the sem code exposed > > this bug (he specifically mentioned too much ping-ponging between > > clients and app_server)? The theory is that the app_server would pull > > all messages from the port before it sends the update request to the > > client. But perhaps the problem is that some data simply has not been > > sent over the port yet. Data is only sent when either the buffer is > > full or the client specifically requests it (flushes the link). It > > definitely looks like the data in the queue is written correctly but > > has simply not been sent. When the app_server processes a redraw > > request, it is in a synchronous communication with the client app, so > > it cannot pull more messages from the port at this point. I need to > > think about it. For now, please just disable this check, it will have > > no other negative consequences, it was only introduced to make > > Invalidate() a much cheaper call. > > Maybe I miss something, but in the BWindow::DispatchMessage() _UPDATE_ > case, the client sends an AS_BEGIN_UPDATE and waits for a reply. So > obviously all preceding Invalidate()s should have been processed by the > time the app server gets the message. Ah yes! I knew there was something like that. > The only thing I can imagine that > can go wrong is that the initial Invalidate() region is totally obscured, > so that the app server doesn't send an _UPDATE_ message in the first > place. Not knowing the respective app server code, I can't say whether > that could really happen. That may well be. It's possibly more involved to get rid of this "check", since it is somewhat "implicit" by the design. I can have a look later. Best regards, -Stephan From korli at mail.berlios.de Sat Sep 6 01:21:34 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Sat, 6 Sep 2008 01:21:34 +0200 Subject: [Haiku-commits] r27339 - in haiku/trunk: headers/posix src/system/libroot/posix/glibc/arch/generic src/system/libroot/posix/glibc/arch/x86 Message-ID: <200809052321.m85NLYS5028981@sheep.berlios.de> Author: korli Date: 2008-09-06 01:21:33 +0200 (Sat, 06 Sep 2008) New Revision: 27339 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27339&view=rev Added: haiku/trunk/src/system/libroot/posix/glibc/arch/generic/e_acoshl.c haiku/trunk/src/system/libroot/posix/glibc/arch/generic/e_asinl.c haiku/trunk/src/system/libroot/posix/glibc/arch/generic/e_atan2l.c haiku/trunk/src/system/libroot/posix/glibc/arch/generic/e_coshl.c haiku/trunk/src/system/libroot/posix/glibc/arch/generic/e_hypotl.c haiku/trunk/src/system/libroot/posix/glibc/arch/generic/e_sinhl.c Modified: haiku/trunk/headers/posix/math.h haiku/trunk/src/system/libroot/posix/glibc/arch/x86/Jamfile Log: added a few more math functions, rearranged some functions in math.h Modified: haiku/trunk/headers/posix/math.h =================================================================== --- haiku/trunk/headers/posix/math.h 2008-09-05 20:58:03 UTC (rev 27338) +++ haiku/trunk/headers/posix/math.h 2008-09-05 23:21:33 UTC (rev 27339) @@ -116,9 +116,12 @@ /* double math functions */ extern double acos(double x); +extern double acosh(double x); extern double asin(double x); +extern double asinh(double x); extern double atan(double x); extern double atan2(double x, double y); +extern double atanh(double x); extern double ceil(double x); extern double cos(double x); extern double cosh(double x); @@ -144,14 +147,17 @@ extern double trunc(double x); /* long double math functions */ +extern long double acosl(long double x); +extern long double acoshl(long double x); +extern long double asinl(long double x); +extern long double atanl(long double x); +extern long double atanhl(long double x); +extern long double atan2l(long double y, long double x); extern long double lgammal(long double x); extern long double roundl(long double x); extern long lroundl(long double x); /* some BSD non-ANSI or POSIX math functions */ -extern double acosh(double x); -extern double asinh(double x); -extern double atanh(double x); extern double cbrt(double x); extern double erf(double x); extern double erfc(double x); @@ -203,8 +209,10 @@ extern float remainderf(float x, float y); extern float scalbf(float x, float n); extern float scalbnf(float x, int n); -extern int ilogbf(float x); +extern int ilogbf(float x); +extern long double remainderl(long double x, long double y); + /* prototypes for functions used in the macros below */ extern int __fpclassifyf(float value); extern int __signbitf(float value); Added: haiku/trunk/src/system/libroot/posix/glibc/arch/generic/e_acoshl.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/generic/e_acoshl.c 2008-09-05 20:58:03 UTC (rev 27338) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/generic/e_acoshl.c 2008-09-05 23:21:33 UTC (rev 27339) @@ -0,0 +1,72 @@ +/* e_acoshl.c -- long double version of e_acosh.c. + * Conversion to long double by Ulrich Drepper, + * Cygnus Support, drepper at cygnus.com. + */ + +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#if defined(LIBM_SCCS) && !defined(lint) +static char rcsid[] = "$NetBSD: $"; +#endif + +/* __ieee754_acoshl(x) + * Method : + * Based on + * acoshl(x) = logl [ x + sqrtl(x*x-1) ] + * we have + * acoshl(x) := logl(x)+ln2, if x is large; else + * acoshl(x) := logl(2x-1/(sqrtl(x*x-1)+x)) if x>2; else + * acoshl(x) := log1pl(t+sqrtl(2.0*t+t*t)); where t=x-1. + * + * Special cases: + * acoshl(x) is NaN with signal if x<1. + * acoshl(NaN) is NaN without signal. + */ + +#include "math.h" +#include "math_private.h" + +#ifdef __STDC__ +static const long double +#else +static long double +#endif +one = 1.0, +ln2 = 6.931471805599453094287e-01L; /* 0x3FFE, 0xB17217F7, 0xD1CF79AC */ + +#ifdef __STDC__ + long double __ieee754_acoshl(long double x) +#else + long double __ieee754_acoshl(x) + long double x; +#endif +{ + long double t; + u_int32_t se,i0,i1; + GET_LDOUBLE_WORDS(se,i0,i1,x); + if(se<0x3fff || se & 0x8000) { /* x < 1 */ + return (x-x)/(x-x); + } else if(se >=0x401d) { /* x > 2**30 */ + if(se >=0x7fff) { /* x is inf of NaN */ + return x+x; + } else + return __ieee754_logl(x)+ln2; /* acoshl(huge)=logl(2x) */ + } else if(((se-0x3fff)|i0|i1)==0) { + return 0.0; /* acosh(1) = 0 */ + } else if (se > 0x4000) { /* 2**28 > x > 2 */ + t=x*x; + return __ieee754_logl(2.0*x-one/(x+__ieee754_sqrtl(t-one))); + } else { /* 1 + and are incorporated herein by permission of the author. The author + reserves the right to distribute this material elsewhere under different + copying permissions. These modifications are distributed here under + the following terms: + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* __ieee754_asin(x) + * Method : + * Since asin(x) = x + x^3/6 + x^5*3/40 + x^7*15/336 + ... + * we approximate asin(x) on [0,0.5] by + * asin(x) = x + x*x^2*R(x^2) + * + * For x in [0.5,1] + * asin(x) = pi/2-2*asin(sqrt((1-x)/2)) + * Let y = (1-x), z = y/2, s := sqrt(z), and pio2_hi+pio2_lo=pi/2; + * then for x>0.98 + * asin(x) = pi/2 - 2*(s+s*z*R(z)) + * = pio2_hi - (2*(s+s*z*R(z)) - pio2_lo) + * For x<=0.98, let pio4_hi = pio2_hi/2, then + * f = hi part of s; + * c = sqrt(z) - f = (z-f*f)/(s+f) ...f+c=sqrt(z) + * and + * asin(x) = pi/2 - 2*(s+s*z*R(z)) + * = pio4_hi+(pio4-2s)-(2s*z*R(z)-pio2_lo) + * = pio4_hi+(pio4-2f)-(2s*z*R(z)-(pio2_lo+2c)) + * + * Special cases: + * if x is NaN, return x itself; + * if |x|>1, return NaN with invalid signal. + * + */ + + +#include "math.h" +#include "math_private.h" + +#ifdef __STDC__ +static const long double +#else +static long double +#endif + one = 1.0L, + huge = 1.0e+4932L, + pio2_hi = 1.5707963267948966192021943710788178805159986950457096099853515625L, + pio2_lo = 2.9127320560933561582586004641843300502121E-20L, + pio4_hi = 7.8539816339744830960109718553940894025800E-1L, + + /* coefficient for R(x^2) */ + + /* asin(x) = x + x^3 pS(x^2) / qS(x^2) + 0 <= x <= 0.5 + peak relative error 1.9e-21 */ + pS0 = -1.008714657938491626019651170502036851607E1L, + pS1 = 2.331460313214179572063441834101394865259E1L, + pS2 = -1.863169762159016144159202387315381830227E1L, + pS3 = 5.930399351579141771077475766877674661747E0L, + pS4 = -6.121291917696920296944056882932695185001E-1L, + pS5 = 3.776934006243367487161248678019350338383E-3L, + + qS0 = -6.052287947630949712886794360635592886517E1L, + qS1 = 1.671229145571899593737596543114258558503E2L, + qS2 = -1.707840117062586426144397688315411324388E2L, + qS3 = 7.870295154902110425886636075950077640623E1L, + qS4 = -1.568433562487314651121702982333303458814E1L; + /* 1.000000000000000000000000000000000000000E0 */ + +#ifdef __STDC__ +long double +__ieee754_asinl (long double x) +#else +double +__ieee754_asinl (x) + long double x; +#endif +{ + long double t, w, p, q, c, r, s; + int32_t ix; + u_int32_t se, i0, i1, k; + + GET_LDOUBLE_WORDS (se, i0, i1, x); + ix = se & 0x7fff; + ix = (ix << 16) | (i0 >> 16); + if (ix >= 0x3fff8000) + { /* |x|>= 1 */ + if (ix == 0x3fff8000 && ((i0 - 0x80000000) | i1) == 0) + /* asin(1)=+-pi/2 with inexact */ + return x * pio2_hi + x * pio2_lo; + return (x - x) / (x - x); /* asin(|x|>1) is NaN */ + } + else if (ix < 0x3ffe8000) + { /* |x|<0.5 */ + if (ix < 0x3fde8000) + { /* if |x| < 2**-33 */ + if (huge + x > one) + return x; /* return x with inexact if x!=0 */ + } + else + { + t = x * x; + p = + t * (pS0 + + t * (pS1 + t * (pS2 + t * (pS3 + t * (pS4 + t * pS5))))); + q = qS0 + t * (qS1 + t * (qS2 + t * (qS3 + t * (qS4 + t)))); + w = p / q; + return x + x * w; + } + } + /* 1> |x|>= 0.5 */ + w = one - fabsl (x); + t = w * 0.5; + p = t * (pS0 + t * (pS1 + t * (pS2 + t * (pS3 + t * (pS4 + t * pS5))))); + q = qS0 + t * (qS1 + t * (qS2 + t * (qS3 + t * (qS4 + t)))); + s = __ieee754_sqrtl (t); + if (ix >= 0x3ffef999) + { /* if |x| > 0.975 */ + w = p / q; + t = pio2_hi - (2.0 * (s + s * w) - pio2_lo); + } + else + { + GET_LDOUBLE_WORDS (k, i0, i1, s); + i1 = 0; + SET_LDOUBLE_WORDS (w,k,i0,i1); + c = (t - w * w) / (s + w); + r = p / q; + p = 2.0 * s * r - (pio2_lo - 2.0 * c); + q = pio4_hi - 2.0 * w; + t = pio4_hi - (p - q); + } + if ((se & 0x8000) == 0) + return t; + else + return -t; +} Added: haiku/trunk/src/system/libroot/posix/glibc/arch/generic/e_atan2l.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/generic/e_atan2l.c 2008-09-05 20:58:03 UTC (rev 27338) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/generic/e_atan2l.c 2008-09-05 23:21:33 UTC (rev 27339) @@ -0,0 +1,136 @@ +/* e_atan2l.c -- long double version of e_atan2.c. + * Conversion to long double by Ulrich Drepper, + * Cygnus Support, drepper at cygnus.com. + */ + +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#if defined(LIBM_SCCS) && !defined(lint) +static char rcsid[] = "$NetBSD: $"; +#endif + +/* __ieee754_atan2l(y,x) + * Method : + * 1. Reduce y to positive by atan2(y,x)=-atan2(-y,x). + * 2. Reduce x to positive by (if x and y are unexceptional): + * ARG (x+iy) = arctan(y/x) ... if x > 0, + * ARG (x+iy) = pi - arctan[y/(-x)] ... if x < 0, + * + * Special cases: + * + * ATAN2((anything), NaN ) is NaN; + * ATAN2(NAN , (anything) ) is NaN; + * ATAN2(+-0, +(anything but NaN)) is +-0 ; + * ATAN2(+-0, -(anything but NaN)) is +-pi ; + * ATAN2(+-(anything but 0 and NaN), 0) is +-pi/2; + * ATAN2(+-(anything but INF and NaN), +INF) is +-0 ; + * ATAN2(+-(anything but INF and NaN), -INF) is +-pi; + * ATAN2(+-INF,+INF ) is +-pi/4 ; + * ATAN2(+-INF,-INF ) is +-3pi/4; + * ATAN2(+-INF, (anything but,0,NaN, and INF)) is +-pi/2; + * + * Constants: + * The hexadecimal values are the intended ones for the following + * constants. The decimal values may be used, provided that the + * compiler will convert from decimal to binary accurately enough + * to produce the hexadecimal values shown. + */ + +#include "math.h" +#include "math_private.h" + +#ifdef __STDC__ +static const long double +#else +static long double +#endif +tiny = 1.0e-4900L, +zero = 0.0, +pi_o_4 = 7.85398163397448309628202E-01L, /* 0x3FFE, 0xC90FDAA2, 0x2168C235 */ +pi_o_2 = 1.5707963267948966192564E+00L, /* 0x3FFF, 0xC90FDAA2, 0x2168C235 */ +pi = 3.14159265358979323851281E+00L, /* 0x4000, 0xC90FDAA2, 0x2168C235 */ +pi_lo = -5.01655761266833202345176e-20L;/* 0xBFBE, 0xECE675D1, 0xFC8F8CBB */ + +#ifdef __STDC__ + long double __ieee754_atan2l(long double y, long double x) +#else + long double __ieee754_atan2l(y,x) + long double y,x; +#endif +{ + long double z; + int32_t k,m,hx,hy,ix,iy; + u_int32_t sx,sy,lx,ly; + + GET_LDOUBLE_WORDS(sx,hx,lx,x); + ix = sx&0x7fff; + lx |= hx & 0x7fffffff; + GET_LDOUBLE_WORDS(sy,hy,ly,y); + iy = sy&0x7fff; + ly |= hy & 0x7fffffff; + if(((2*ix|((lx|-lx)>>31))>0xfffe)|| + ((2*iy|((ly|-ly)>>31))>0xfffe)) /* x or y is NaN */ + return x+y; + if(((sx-0x3fff)|lx)==0) return __atanl(y); /* x=1.0 */ + m = ((sy>>15)&1)|((sx>>14)&2); /* 2*sign(x)+sign(y) */ + + /* when y = 0 */ + if((iy|ly)==0) { + switch(m) { + case 0: + case 1: return y; /* atan(+-0,+anything)=+-0 */ + case 2: return pi+tiny;/* atan(+0,-anything) = pi */ + case 3: return -pi-tiny;/* atan(-0,-anything) =-pi */ + } + } + /* when x = 0 */ + if((ix|lx)==0) return (sy>=0x8000)? -pi_o_2-tiny: pi_o_2+tiny; + + /* when x is INF */ + if(ix==0x7fff) { + if(iy==0x7fff) { + switch(m) { + case 0: return pi_o_4+tiny;/* atan(+INF,+INF) */ + case 1: return -pi_o_4-tiny;/* atan(-INF,+INF) */ + case 2: return 3.0*pi_o_4+tiny;/*atan(+INF,-INF)*/ + case 3: return -3.0*pi_o_4-tiny;/*atan(-INF,-INF)*/ + } + } else { + switch(m) { + case 0: return zero ; /* atan(+...,+INF) */ + case 1: return -zero ; /* atan(-...,+INF) */ + case 2: return pi+tiny ; /* atan(+...,-INF) */ + case 3: return -pi-tiny ; /* atan(-...,-INF) */ + } + } + } + /* when y is INF */ + if(iy==0x7fff) return (sy>=0x8000)? -pi_o_2-tiny: pi_o_2+tiny; + + /* compute y/x */ + k = sy-sx; + if(k > 70) z=pi_o_2+0.5*pi_lo; /* |y/x| > 2**70 */ + else if(sx>=0x8000&&k<-70) z=0.0; /* |y|/x < -2**70 */ + else z=__atanl(fabsl(y/x)); /* safe to do y/x */ + switch (m) { + case 0: return z ; /* atan(+,+) */ + case 1: { + u_int32_t sz; + GET_LDOUBLE_EXP(sz,z); + SET_LDOUBLE_EXP(z,sz ^ 0x8000); + } + return z ; /* atan(-,+) */ + case 2: return pi-(z-pi_lo);/* atan(+,-) */ + default: /* case 3 */ + return (z-pi_lo)-pi;/* atan(-,-) */ + } +} Added: haiku/trunk/src/system/libroot/posix/glibc/arch/generic/e_coshl.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/generic/e_coshl.c 2008-09-05 20:58:03 UTC (rev 27338) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/generic/e_coshl.c 2008-09-05 23:21:33 UTC (rev 27339) @@ -0,0 +1,93 @@ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#if defined(LIBM_SCCS) && !defined(lint) +static char rcsid[] = "$NetBSD: e_cosh.c,v 1.7 1995/05/10 20:44:58 jtc Exp $"; +#endif + +/* __ieee754_coshl(x) + * Method : + * mathematically coshl(x) if defined to be (exp(x)+exp(-x))/2 + * 1. Replace x by |x| (coshl(x) = coshl(-x)). + * 2. + * [ exp(x) - 1 ]^2 + * 0 <= x <= ln2/2 : coshl(x) := 1 + ------------------- + * 2*exp(x) + * + * exp(x) + 1/exp(x) + * ln2/2 <= x <= 22 : coshl(x) := ------------------- + * 2 + * 22 <= x <= lnovft : coshl(x) := expl(x)/2 + * lnovft <= x <= ln2ovft: coshl(x) := expl(x/2)/2 * expl(x/2) + * ln2ovft < x : coshl(x) := huge*huge (overflow) + * + * Special cases: + * coshl(x) is |x| if x is +INF, -INF, or NaN. + * only coshl(0)=1 is exact for finite x. + */ + +#include "math.h" +#include "math_private.h" + +#ifdef __STDC__ +static const long double one = 1.0, half=0.5, huge = 1.0e4900L; +#else +static long double one = 1.0, half=0.5, huge = 1.0e4900L; +#endif + +#ifdef __STDC__ + long double __ieee754_coshl(long double x) +#else + long double __ieee754_coshl(x) + long double x; +#endif +{ + long double t,w; + int32_t ex; + u_int32_t mx,lx; + + /* High word of |x|. */ + GET_LDOUBLE_WORDS(ex,mx,lx,x); + ex &= 0x7fff; + + /* x is INF or NaN */ + if(ex==0x7fff) return x*x; + + /* |x| in [0,0.5*ln2], return 1+expm1l(|x|)^2/(2*expl(|x|)) */ + if(ex < 0x3ffd || (ex == 0x3ffd && mx < 0xb17217f7u)) { + t = __expm1l(fabsl(x)); + w = one+t; + if (ex<0x3fbc) return w; /* cosh(tiny) = 1 */ + return one+(t*t)/(w+w); + } + + /* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */ + if (ex < 0x4003 || (ex == 0x4003 && mx < 0xb0000000u)) { + t = __ieee754_expl(fabsl(x)); + return half*t+half/t; + } + + /* |x| in [22, ln(maxdouble)] return half*exp(|x|) */ + if (ex < 0x400c || (ex == 0x400c && mx < 0xb1700000u)) + return half*__ieee754_expl(fabsl(x)); + + /* |x| in [log(maxdouble), log(2*maxdouble)) */ + if (ex == 0x400c && (mx < 0xb174ddc0u + || (mx == 0xb174ddc0u && lx < 0x31aec0ebu))) + { + w = __ieee754_expl(half*fabsl(x)); + t = half*w; + return t*w; + } + + /* |x| >= log(2*maxdouble), cosh(x) overflow */ + return huge*huge; +} Added: haiku/trunk/src/system/libroot/posix/glibc/arch/generic/e_hypotl.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/generic/e_hypotl.c 2008-09-05 20:58:03 UTC (rev 27338) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/generic/e_hypotl.c 2008-09-05 23:21:33 UTC (rev 27339) @@ -0,0 +1,133 @@ +/* e_hypotl.c -- long double version of e_hypot.c. + * Conversion to long double by Ulrich Drepper, + * Cygnus Support, drepper at cygnus.com. + */ + +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#if defined(LIBM_SCCS) && !defined(lint) +static char rcsid[] = "$NetBSD: $"; +#endif + +/* __ieee754_hypotl(x,y) + * + * Method : + * If (assume round-to-nearest) z=x*x+y*y + * has error less than sqrt(2)/2 ulp, than + * sqrt(z) has error less than 1 ulp (exercise). + * + * So, compute sqrt(x*x+y*y) with some care as + * follows to get the error below 1 ulp: + * + * Assume x>y>0; + * (if possible, set rounding to round-to-nearest) + * 1. if x > 2y use + * x1*x1+(y*y+(x2*(x+x1))) for x*x+y*y + * where x1 = x with lower 32 bits cleared, x2 = x-x1; else + * 2. if x <= 2y use + * t1*y1+((x-y)*(x-y)+(t1*y2+t2*y)) + * where t1 = 2x with lower 32 bits cleared, t2 = 2x-t1, + * y1= y with lower 32 bits chopped, y2 = y-y1. + * + * NOTE: scaling may be necessary if some argument is too + * large or too tiny + * + * Special cases: + * hypot(x,y) is INF if x or y is +INF or -INF; else + * hypot(x,y) is NAN if x or y is NAN. + * + * Accuracy: + * hypot(x,y) returns sqrt(x^2+y^2) with error less + * than 1 ulps (units in the last place) + */ + +#include "math.h" +#include "math_private.h" + +#ifdef __STDC__ + long double __ieee754_hypotl(long double x, long double y) +#else + long double __ieee754_hypotl(x,y) + long double x, y; +#endif +{ + long double a,b,t1,t2,y1,y2,w; + u_int32_t j,k,ea,eb; + + GET_LDOUBLE_EXP(ea,x); + ea &= 0x7fff; + GET_LDOUBLE_EXP(eb,y); + eb &= 0x7fff; + if(eb > ea) {a=y;b=x;j=ea; ea=eb;eb=j;} else {a=x;b=y;} + SET_LDOUBLE_EXP(a,ea); /* a <- |a| */ + SET_LDOUBLE_EXP(b,eb); /* b <- |b| */ + if((ea-eb)>0x46) {return a+b;} /* x/y > 2**70 */ + k=0; + if(ea > 0x5f3f) { /* a>2**8000 */ + if(ea == 0x7fff) { /* Inf or NaN */ + u_int32_t exp,high,low; + w = a+b; /* for sNaN */ + GET_LDOUBLE_WORDS(exp,high,low,a); + if(((high&0x7fffffff)|low)==0) w = a; + GET_LDOUBLE_WORDS(exp,high,low,b); + if(((eb^0x7fff)|(high&0x7fffffff)|low)==0) w = b; + return w; + } + /* scale a and b by 2**-9600 */ + ea -= 0x2580; eb -= 0x2580; k += 9600; + SET_LDOUBLE_EXP(a,ea); + SET_LDOUBLE_EXP(b,eb); + } + if(eb < 0x20bf) { /* b < 2**-8000 */ + if(eb == 0) { /* subnormal b or 0 */ + u_int32_t exp,high,low; + GET_LDOUBLE_WORDS(exp,high,low,b); + if((high|low)==0) return a; + SET_LDOUBLE_WORDS(t1, 0x7ffd, 0, 0); /* t1=2^16382 */ + b *= t1; + a *= t1; + k -= 16382; + } else { /* scale a and b by 2^9600 */ + ea += 0x2580; /* a *= 2^9600 */ + eb += 0x2580; /* b *= 2^9600 */ + k -= 9600; + SET_LDOUBLE_EXP(a,ea); + SET_LDOUBLE_EXP(b,eb); + } + } + /* medium size a and b */ + w = a-b; + if (w>b) { + u_int32_t high; + GET_LDOUBLE_MSW(high,a); + SET_LDOUBLE_WORDS(t1,ea,high,0); + t2 = a-t1; + w = __ieee754_sqrtl(t1*t1-(b*(-b)-t2*(a+t1))); + } else { + u_int32_t high; + GET_LDOUBLE_MSW(high,b); + a = a+a; + SET_LDOUBLE_WORDS(y1,eb,high,0); + y2 = b - y1; + GET_LDOUBLE_MSW(high,a); + SET_LDOUBLE_WORDS(t1,ea+1,high,0); + t2 = a - t1; + w = __ieee754_sqrtl(t1*y1-(w*(-w)-(t1*y2+t2*b))); + } + if(k!=0) { + u_int32_t exp; + t1 = 1.0; + GET_LDOUBLE_EXP(exp,t1); + SET_LDOUBLE_EXP(t1,exp+k); + return t1*w; + } else return w; +} Added: haiku/trunk/src/system/libroot/posix/glibc/arch/generic/e_sinhl.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/generic/e_sinhl.c 2008-09-05 20:58:03 UTC (rev 27338) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/generic/e_sinhl.c 2008-09-05 23:21:33 UTC (rev 27339) @@ -0,0 +1,91 @@ +/* e_asinhl.c -- long double version of e_asinh.c. + * Conversion to long double by Ulrich Drepper, + * Cygnus Support, drepper at cygnus.com. + */ + +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#if defined(LIBM_SCCS) && !defined(lint) +static char rcsid[] = "$NetBSD: $"; +#endif + +/* __ieee754_sinhl(x) + * Method : + * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2 + * 1. Replace x by |x| (sinhl(-x) = -sinhl(x)). + * 2. + * E + E/(E+1) + * 0 <= x <= 25 : sinhl(x) := --------------, E=expm1l(x) + * 2 + * + * 25 <= x <= lnovft : sinhl(x) := expl(x)/2 + * lnovft <= x <= ln2ovft: sinhl(x) := expl(x/2)/2 * expl(x/2) + * ln2ovft < x : sinhl(x) := x*shuge (overflow) + * + * Special cases: + * sinhl(x) is |x| if x is +INF, -INF, or NaN. + * only sinhl(0)=0 is exact for finite x. + */ + +#include "math.h" +#include "math_private.h" + +#ifdef __STDC__ +static const long double one = 1.0, shuge = 1.0e4931L; +#else +static long double one = 1.0, shuge = 1.0e4931L; +#endif + +#ifdef __STDC__ + long double __ieee754_sinhl(long double x) +#else + long double __ieee754_sinhl(x) + long double x; +#endif +{ + long double t,w,h; + u_int32_t jx,ix,i0,i1; + + /* Words of |x|. */ + GET_LDOUBLE_WORDS(jx,i0,i1,x); + ix = jx&0x7fff; + + /* x is INF or NaN */ + if(ix==0x7fff) return x+x; + + h = 0.5; + if (jx & 0x8000) h = -h; + /* |x| in [0,25], return sign(x)*0.5*(E+E/(E+1))) */ + if (ix < 0x4003 || (ix == 0x4003 && i0 <= 0xc8000000)) { /* |x|<25 */ + if (ix<0x3fdf) /* |x|<2**-32 */ + if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */ + t = __expm1l(fabsl(x)); + if(ix<0x3fff) return h*(2.0*t-t*t/(t+one)); + return h*(t+t/(t+one)); + } + + /* |x| in [25, log(maxdouble)] return 0.5*exp(|x|) */ + if (ix < 0x400c || (ix == 0x400c && i0 < 0xb17217f7)) + return h*__ieee754_expl(fabsl(x)); + + /* |x| in [log(maxdouble), overflowthreshold] */ + if (ix<0x400c || (ix == 0x400c && (i0 < 0xb174ddc0 + || (i0 == 0xb174ddc0 + && i1 <= 0x31aec0ea)))) { + w = __ieee754_expl(0.5*fabsl(x)); + t = h*w; + return t*w; + } + + /* |x| > overflowthreshold, sinhl(x) overflow */ + return x*shuge; +} Modified: haiku/trunk/src/system/libroot/posix/glibc/arch/x86/Jamfile =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/x86/Jamfile 2008-09-05 20:58:03 UTC (rev 27338) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/x86/Jamfile 2008-09-05 23:21:33 UTC (rev 27339) @@ -24,12 +24,14 @@ memrchr.c mpn2dbl.c mpn2flt.c mpn2ldbl.c mul.c mul_n.c - e_cosh.c e_coshf.c # e_coshl.c - e_sinh.c e_sinhf.c # e_sinhl.c + e_cosh.c e_coshf.c e_coshl.c + e_sinh.c e_sinhf.c e_sinhl.c + e_asinl.c e_gamma_r.c e_gammaf_r.c e_gammal_r.c e_j0.c e_j0f.c e_j1.c e_j1f.c e_jn.c e_jnf.c + e_hypotl.c e_lgamma_r.c e_lgammaf_r.c e_lgammal_r.c k_cos.c k_cosf.c k_sin.c k_sinf.c @@ -66,31 +68,31 @@ s_signgam.c s_tanh.c s_tanhf.c - w_acos.c w_acosf.c # w_acosl.c - w_acosh.c w_acoshf.c # w_acoshl.c - w_asin.c w_asinf.c # w_asinl.c - w_atan2.c w_atan2f.c # w_atan2l.c - w_atanh.c w_atanhf.c # w_atanhl.c - w_cosh.c w_coshf.c # w_coshl.c - w_drem.c w_dremf.c # w_dreml.c - w_exp.c w_expf.c # w_expl.c - w_exp10.c w_exp10f.c # w_exp10l.c - w_exp2.c w_exp2f.c # w_exp2l.c - w_fmod.c w_fmodf.c # w_fmodl.c - w_hypot.c w_hypotf.c # w_hypotl.c + w_acos.c w_acosf.c w_acosl.c + w_acosh.c w_acoshf.c w_acoshl.c + w_asin.c w_asinf.c w_asinl.c + w_atan2.c w_atan2f.c w_atan2l.c + w_atanh.c w_atanhf.c w_atanhl.c + w_cosh.c w_coshf.c w_coshl.c + w_drem.c w_dremf.c w_dreml.c + w_exp.c w_expf.c w_expl.c + w_exp10.c w_exp10f.c w_exp10l.c + w_exp2.c w_exp2f.c w_exp2l.c + w_fmod.c w_fmodf.c w_fmodl.c + w_hypot.c w_hypotf.c w_hypotl.c w_j0.c w_j0f.c w_j1.c w_j1f.c w_jn.c w_jnf.c w_lgamma.c w_lgammaf.c w_lgamma_r.c w_lgammaf_r.c - w_log.c w_logf.c # w_logl.c - w_log10.c w_log10f.c # w_log10l.c - w_log2.c w_log2f.c # w_log2l.c - w_pow.c w_powf.c # w_powl.c - w_remainder.c w_remainderf.c # w_remainderl.c - w_scalb.c w_scalbf.c # w_scalbl.c - w_sinh.c w_sinhf.c # w_sinhl.c - w_sqrt.c w_sqrtf.c # w_sqrtl.c + w_log.c w_logf.c w_logl.c + w_log10.c w_log10f.c w_log10l.c + w_log2.c w_log2f.c w_log2l.c + w_pow.c w_powf.c w_powl.c + w_remainder.c w_remainderf.c w_remainderl.c + w_scalb.c w_scalbf.c w_scalbl.c + w_sinh.c w_sinhf.c w_sinhl.c + w_sqrt.c w_sqrtf.c w_sqrtl.c w_tgamma.c w_tgammaf.c w_tgammal.c ; From anevilyak at mail.berlios.de Sat Sep 6 01:34:17 2008 From: anevilyak at mail.berlios.de (anevilyak at BerliOS) Date: Sat, 6 Sep 2008 01:34:17 +0200 Subject: [Haiku-commits] r27340 - haiku/trunk/src/build/libroot Message-ID: <200809052334.m85NYHJ8025112@sheep.berlios.de> Author: anevilyak Date: 2008-09-06 01:34:16 +0200 (Sat, 06 Sep 2008) New Revision: 27340 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27340&view=rev Modified: haiku/trunk/src/build/libroot/fs_attr_generic.cpp Log: Set native eol-style (CR/LF issues). Modified: haiku/trunk/src/build/libroot/fs_attr_generic.cpp =================================================================== --- haiku/trunk/src/build/libroot/fs_attr_generic.cpp 2008-09-05 23:21:33 UTC (rev 27339) +++ haiku/trunk/src/build/libroot/fs_attr_generic.cpp 2008-09-05 23:34:16 UTC (rev 27340) @@ -1,612 +1,612 @@ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -#include "fs_impl.h" -#include "fs_descriptors.h" - - -using namespace std; -using namespace BPrivate; - -static const char *sAttributeDirBasePath = HAIKU_BUILD_ATTRIBUTES_DIR; - - -// init_attribute_dir_base_dir -static status_t -init_attribute_dir_base_dir() -{ - static bool initialized = false; - static status_t initError; - - if (initialized) - return initError; - - // stat the dir - struct stat st; - initError = B_OK; - if (lstat(sAttributeDirBasePath, &st) == 0) { - if (!S_ISDIR(st.st_mode)) { - // the attribute dir base dir is no directory - fprintf(stderr, "init_attribute_dir_base_dir(): The Attribute " - "directory base directory exists, but is no directory!\n"); - initError = B_FILE_ERROR; - } - - } else { - // doesn't exist yet: create it - if (mkdir(sAttributeDirBasePath, S_IRWXU | S_IRWXG | S_IRWXO) < 0) - initError = errno; - } - - initialized = true; - return initError; -} - -// escape_attr_name -static string -escape_attr_name(const char *name) -{ - string escapedName("_"); - while (*name != '\0') { - // we replace '/' with "_s" and '_' with "__" - if (*name == '/') - escapedName += "_s"; - else if (*name == '_') - escapedName += "__"; - else - escapedName += *name; - - name++; - } - - return escapedName; -} - -// deescape_attr_name -static string -deescape_attr_name(const char *name) -{ - if (name[0] != '_') { - debugger("deescape_attr_name(): name doesn't start with '_'!\n"); - return "___"; - } - name++; - - string deescapedName; - while (*name != '\0') { - if (*name == '_') { - name++; - if (*name == 's') { - deescapedName += '/'; - } else if (*name == '_') { - deescapedName += '_'; - } else { - debugger("deescape_attr_name(): name contains invalid escaped " - "sequence!\n"); - name--; - } - } else - deescapedName += *name; - - name++; - } - - return deescapedName; -} - -// get_attribute_dir_path -static string -get_attribute_dir_path(NodeRef ref) -{ - string attrDirPath(sAttributeDirBasePath); - char buffer[32]; - sprintf(buffer, "/%lld", (int64)ref.node); - attrDirPath += buffer; - return attrDirPath; -} - -// ensure_attribute_dir_exists -static status_t -ensure_attribute_dir_exists(NodeRef ref, const char *path, int fd) -{ - // init the base directory here - status_t error = init_attribute_dir_base_dir(); - if (error != B_OK) - return error; - - // stat the dir - string attrDirPath(get_attribute_dir_path(ref)); - struct stat st; - if (lstat(attrDirPath.c_str(), &st) == 0) { - if (!S_ISDIR(st.st_mode)) { - // the attribute dir is no directory - fprintf(stderr, "ensure_attribute_dir_exists(): Attribute " - "directory for node %lld exists, but is no directory!\n", - ref.node); - return B_FILE_ERROR; - } - - return B_OK; - } - - // doesn't exist yet: create it - if (mkdir(attrDirPath.c_str(), S_IRWXU | S_IRWXG | S_IRWXO) < 0) - return errno; - - return B_OK; -} - -// open_attr_dir -static DIR * -open_attr_dir(NodeRef ref, const char *path, int fd) -{ - // make sure the directory exists - status_t error = ensure_attribute_dir_exists(ref, path, fd); - if (error != B_OK) { - errno = error; - return NULL; - } - - // open it - string dirPath(get_attribute_dir_path(ref)); - return opendir(dirPath.c_str()); -} - -// get_attribute_path -static status_t -get_attribute_path(NodeRef ref, const char *path, int fd, - const char *attribute, string &attrPath, string &typePath) -{ - if (!attribute || strlen(attribute) == 0) - return B_BAD_VALUE; - - // make sure the attribute dir for the node exits - status_t error = ensure_attribute_dir_exists(ref, path, fd); - if (error != B_OK) { - errno = error; - return -1; - } - - // construct the attribute path - attrPath = get_attribute_dir_path(ref) + '/'; - string attrName(escape_attr_name(attribute)); - typePath = attrPath + "t" + attrName; - attrPath += attrName; - - return B_OK; -} - - -// get_attribute_path_virtual_fd -static status_t -get_attribute_path_virtual_fd(int fd, const char *attribute, string &attrPath, - string &typePath) -{ - // stat the file to get a NodeRef - struct stat st; - status_t error = _kern_read_stat(fd, NULL, false, &st, sizeof(st)); - if (error != B_OK) - return error; - NodeRef ref(st); - - // Try to get a path. If we can't get a path, this is must be a "real" - // (i.e. system) file descriptor, which is just as well. - string path; - bool pathValid = (get_path(fd, NULL, path) == B_OK); - - // get the attribute path - return get_attribute_path(ref, (pathValid ? path.c_str() : NULL), - (pathValid ? -1 : fd), attribute, attrPath, typePath); -} - - -// get_attribute_path -static status_t -get_attribute_path(int fd, const char *attribute, string &attrPath, - string &typePath) -{ - if (get_descriptor(fd)) { - // This is a virtual file descriptor -- we have a special function - // for handling it. - return get_attribute_path_virtual_fd(fd, attribute, attrPath, - typePath); - } else { - // This is a real (i.e. system) file descriptor -- fstat() it and - // build the path. - - // stat the file to get a NodeRef - struct stat st; - if (fstat(fd, &st) < 0) - return errno; - NodeRef ref(st); - - return get_attribute_path(ref, NULL, fd, attribute, attrPath, typePath); - } -} - - -// # pragma mark - Public API - - -// fs_open_attr_dir -DIR * -fs_open_attr_dir(const char *path) -{ - struct stat st; - if (lstat(path, &st)) - return NULL; - - return open_attr_dir(NodeRef(st), path, -1); -} - -// fs_fopen_attr_dir -DIR * -fs_fopen_attr_dir(int fd) -{ - struct stat st; - - status_t error = _kern_read_stat(fd, NULL, false, &st, - sizeof(struct stat)); - if (error != B_OK) { - errno = error; - return NULL; - } - - // Try to get a path. If we can't get a path, this is must be a "real" - // (i.e. system) file descriptor, which is just as well. - string path; - bool pathValid = (get_path(fd, NULL, path) == B_OK); - - // get the attribute path - return open_attr_dir(NodeRef(st), (pathValid ? path.c_str() : NULL), - (pathValid ? -1 : fd)); -} - -// fs_close_attr_dir -int -fs_close_attr_dir(DIR *dir) -{ - return closedir(dir); -} - -// fs_read_attr_dir -struct dirent * -fs_read_attr_dir(DIR *dir) -{ - struct dirent *entry = NULL; - while (true) { - // read the next entry - entry = readdir(dir); - if (!entry) - return NULL; - - // ignore administrative entries; the - if (entry->d_name[0] == '_') { - string attrName = deescape_attr_name(entry->d_name); - strcpy(entry->d_name, attrName.c_str()); - return entry; - } - } -} - -// fs_rewind_attr_dir -void -fs_rewind_attr_dir(DIR *dir) -{ - rewinddir(dir); -} - -// fs_open_attr -int -fs_open_attr(int fd, const char *attribute, uint32 type, int openMode) -{ - if (!attribute) { - errno = B_BAD_VALUE; - return -1; - } - - // get the attribute path - string attrPath; - string typePath; - status_t error = get_attribute_path(fd, attribute, attrPath, typePath); - if (error != B_OK) { - errno = error; - return -1; - } - - // check, if the attribute already exists - struct stat st; - bool exists = (lstat(attrPath.c_str(), &st) == 0); - - // open the attribute - int attrFD = open(attrPath.c_str(), openMode, S_IRWXU | S_IRWXG | S_IRWXO); - if (attrFD < 0) - return -1; - - // set the type, if the attribute didn't exist yet - if (!exists) { - // create a file prefixed "t" - int typeFD = creat(typePath.c_str(), S_IRWXU | S_IRWXG | S_IRWXO); - if (typeFD >= 0) { - // write the type into the file - if (write(typeFD, &type, sizeof(type)) < 0) - error = errno; - - close(typeFD); - - } else - error = errno; - - // remove type and attribute file, if something went wrong - if (error != B_OK) { - if (typeFD > 0) { - unlink(typePath.c_str()); - } - - close(attrFD); - unlink(attrPath.c_str()); - - errno = error; - return -1; - } - } - - return attrFD; -} - -// fs_close_attr -int -fs_close_attr(int fd) -{ - return close(fd); -} - -// fs_read_attr -ssize_t -fs_read_attr(int fd, const char *attribute, uint32 type, off_t pos, - void *buffer, size_t readBytes) -{ - // open the attribute - int attrFD = fs_open_attr(fd, attribute, type, O_RDONLY); - if (attrFD < 0) - return attrFD; - - // read - ssize_t bytesRead = read_pos(attrFD, pos, buffer, readBytes); - status_t error = errno; - - // close the attribute - fs_close_attr(attrFD); - - if (bytesRead < 0) { - errno = error; - return -1; - } - - return bytesRead; -} - -// fs_write_attr -ssize_t -fs_write_attr(int fd, const char *attribute, uint32 type, off_t pos, - const void *buffer, size_t readBytes) -{ - // open the attribute - int attrFD = fs_open_attr(fd, attribute, type, - O_WRONLY | O_CREAT | O_TRUNC); - if (attrFD < 0) - return attrFD; - - // read - ssize_t bytesWritten = write_pos(attrFD, pos, buffer, readBytes); - status_t error = errno; - - // close the attribute - fs_close_attr(attrFD); - - if (bytesWritten < 0) { - errno = error; - return -1; - } - - return bytesWritten; -} - -// fs_remove_attr -int -fs_remove_attr(int fd, const char *attribute) -{ - if (!attribute) { - errno = B_BAD_VALUE; - return -1; - } - - // get the attribute path - string attrPath; - string typePath; - status_t error = get_attribute_path(fd, attribute, attrPath, typePath); - if (error != B_OK) { - errno = error; - return -1; - } - - // remove the attribute - if (unlink(attrPath.c_str()) < 0) - return -1; - - unlink(typePath.c_str()); - - return B_OK; -} - -// fs_stat_attr -int -fs_stat_attr(int fd, const char *attribute, struct attr_info *attrInfo) -{ - if (!attribute || !attrInfo) { - errno = B_BAD_VALUE; - return -1; - } - - // get the attribute path - string attrPath; - string typePath; - status_t error = get_attribute_path(fd, attribute, attrPath, typePath); - if (error != B_OK) { - errno = error; - return -1; - } - - // stat the attribute file to get the size of the attribute - struct stat st; - if (lstat(attrPath.c_str(), &st) < 0) - return -1; - - attrInfo->size = st.st_size; - - // now open the attribute type file and read the attribute's type - int typeFD = open(typePath.c_str(), O_RDONLY); - if (typeFD < 0) - return -1; - - ssize_t bytesRead = read(typeFD, &attrInfo->type, sizeof(attrInfo->type)); - if (bytesRead < 0) - error = errno; - else if (bytesRead < (ssize_t)sizeof(attrInfo->type)) - error = B_FILE_ERROR; - - close(typeFD); - - // fail on error - if (error != B_OK) { - errno = error; - return -1; - } - - return 0; -} - - -// #pragma mark - Private Syscalls - - -// _kern_open_attr_dir -int -_kern_open_attr_dir(int fd, const char *path) -{ - // get node ref for the node - struct stat st; - status_t error = _kern_read_stat(fd, path, false, &st, - sizeof(struct stat)); - if (error != B_OK) { - errno = error; - return -1; - } - NodeRef ref(st); - - // If a path was given, get a usable path. - string realPath; - if (path) { - error = get_path(fd, path, realPath); - if (error != B_OK) - return error; - } - - // open the attr dir - DIR *dir = open_attr_dir(ref, (path ? realPath.c_str() : NULL), - (path ? -1 : fd)); - if (!dir) - return errno; - - // create descriptor - AttrDirDescriptor *descriptor = new AttrDirDescriptor(dir, ref); - return add_descriptor(descriptor); -} - -// _kern_rename_attr -status_t -_kern_rename_attr(int fromFile, const char *fromName, int toFile, - const char *toName) -{ - if (!fromName || !toName) - return B_BAD_VALUE; - - // get the attribute paths - string fromAttrPath; - string fromTypePath; - status_t error = get_attribute_path_virtual_fd(fromFile, fromName, - fromAttrPath, fromTypePath); - if (error != B_OK) - return error; - - string toAttrPath; - string toTypePath; - error = get_attribute_path_virtual_fd(toFile, toName, toAttrPath, - toTypePath); - if (error != B_OK) - return error; - - // rename the attribute and type files - if (rename(fromAttrPath.c_str(), toAttrPath.c_str()) < 0) - return errno; - - if (rename(fromTypePath.c_str(), toTypePath.c_str()) < 0) { - // renaming the type file failed: try to rename back the attribute file - error = errno; - - rename(toAttrPath.c_str(), fromAttrPath.c_str()); - - return error; - } - - return B_OK; -} - -// _kern_remove_attr -status_t -_kern_remove_attr(int fd, const char *name) -{ - if (!name) - return B_BAD_VALUE; - - // get the attribute path - string attrPath; - string typePath; - status_t error = get_attribute_path_virtual_fd(fd, name, attrPath, - typePath); - if (error != B_OK) - return error; - - // remove the attribute - if (unlink(attrPath.c_str()) < 0) - return errno; - - unlink(typePath.c_str()); - - return B_OK; -} - - -// __get_attribute_dir_path -extern "C" bool __get_attribute_dir_path(const struct stat* st, char* buffer); -bool -__get_attribute_dir_path(const struct stat* st, char* buffer) -{ - NodeRef ref(*st); - string path = get_attribute_dir_path(ref); - strcpy(buffer, path.c_str()); - return true; -} + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include "fs_impl.h" +#include "fs_descriptors.h" + + +using namespace std; +using namespace BPrivate; + +static const char *sAttributeDirBasePath = HAIKU_BUILD_ATTRIBUTES_DIR; + + +// init_attribute_dir_base_dir +static status_t +init_attribute_dir_base_dir() +{ + static bool initialized = false; + static status_t initError; + + if (initialized) + return initError; + + // stat the dir + struct stat st; + initError = B_OK; + if (lstat(sAttributeDirBasePath, &st) == 0) { + if (!S_ISDIR(st.st_mode)) { + // the attribute dir base dir is no directory + fprintf(stderr, "init_attribute_dir_base_dir(): The Attribute " + "directory base directory exists, but is no directory!\n"); + initError = B_FILE_ERROR; + } + + } else { + // doesn't exist yet: create it + if (mkdir(sAttributeDirBasePath, S_IRWXU | S_IRWXG | S_IRWXO) < 0) + initError = errno; + } + + initialized = true; + return initError; +} + +// escape_attr_name +static string +escape_attr_name(const char *name) +{ + string escapedName("_"); + while (*name != '\0') { + // we replace '/' with "_s" and '_' with "__" + if (*name == '/') + escapedName += "_s"; + else if (*name == '_') + escapedName += "__"; + else + escapedName += *name; + + name++; + } + + return escapedName; +} + +// deescape_attr_name +static string +deescape_attr_name(const char *name) +{ + if (name[0] != '_') { + debugger("deescape_attr_name(): name doesn't start with '_'!\n"); + return "___"; + } + name++; + + string deescapedName; + while (*name != '\0') { + if (*name == '_') { + name++; + if (*name == 's') { + deescapedName += '/'; + } else if (*name == '_') { + deescapedName += '_'; + } else { + debugger("deescape_attr_name(): name contains invalid escaped " + "sequence!\n"); + name--; + } + } else + deescapedName += *name; + + name++; + } + + return deescapedName; +} + +// get_attribute_dir_path +static string +get_attribute_dir_path(NodeRef ref) +{ + string attrDirPath(sAttributeDirBasePath); + char buffer[32]; + sprintf(buffer, "/%lld", (int64)ref.node); + attrDirPath += buffer; + return attrDirPath; +} + +// ensure_attribute_dir_exists +static status_t +ensure_attribute_dir_exists(NodeRef ref, const char *path, int fd) +{ + // init the base directory here + status_t error = init_attribute_dir_base_dir(); + if (error != B_OK) + return error; + + // stat the dir + string attrDirPath(get_attribute_dir_path(ref)); + struct stat st; + if (lstat(attrDirPath.c_str(), &st) == 0) { + if (!S_ISDIR(st.st_mode)) { + // the attribute dir is no directory + fprintf(stderr, "ensure_attribute_dir_exists(): Attribute " + "directory for node %lld exists, but is no directory!\n", + ref.node); + return B_FILE_ERROR; + } + + return B_OK; + } + + // doesn't exist yet: create it + if (mkdir(attrDirPath.c_str(), S_IRWXU | S_IRWXG | S_IRWXO) < 0) + return errno; + + return B_OK; +} + +// open_attr_dir +static DIR * +open_attr_dir(NodeRef ref, const char *path, int fd) +{ + // make sure the directory exists + status_t error = ensure_attribute_dir_exists(ref, path, fd); + if (error != B_OK) { + errno = error; + return NULL; + } + + // open it + string dirPath(get_attribute_dir_path(ref)); + return opendir(dirPath.c_str()); +} + +// get_attribute_path +static status_t +get_attribute_path(NodeRef ref, const char *path, int fd, + const char *attribute, string &attrPath, string &typePath) +{ + if (!attribute || strlen(attribute) == 0) + return B_BAD_VALUE; + + // make sure the attribute dir for the node exits + status_t error = ensure_attribute_dir_exists(ref, path, fd); + if (error != B_OK) { + errno = error; + return -1; + } + + // construct the attribute path + attrPath = get_attribute_dir_path(ref) + '/'; + string attrName(escape_attr_name(attribute)); + typePath = attrPath + "t" + attrName; + attrPath += attrName; + + return B_OK; +} + + +// get_attribute_path_virtual_fd +static status_t +get_attribute_path_virtual_fd(int fd, const char *attribute, string &attrPath, + string &typePath) +{ + // stat the file to get a NodeRef + struct stat st; + status_t error = _kern_read_stat(fd, NULL, false, &st, sizeof(st)); + if (error != B_OK) + return error; + NodeRef ref(st); + + // Try to get a path. If we can't get a path, this is must be a "real" + // (i.e. system) file descriptor, which is just as well. + string path; + bool pathValid = (get_path(fd, NULL, path) == B_OK); + + // get the attribute path + return get_attribute_path(ref, (pathValid ? path.c_str() : NULL), + (pathValid ? -1 : fd), attribute, attrPath, typePath); +} + + +// get_attribute_path +static status_t +get_attribute_path(int fd, const char *attribute, string &attrPath, + string &typePath) +{ + if (get_descriptor(fd)) { + // This is a virtual file descriptor -- we have a special function + // for handling it. + return get_attribute_path_virtual_fd(fd, attribute, attrPath, + typePath); + } else { + // This is a real (i.e. system) file descriptor -- fstat() it and + // build the path. + + // stat the file to get a NodeRef + struct stat st; + if (fstat(fd, &st) < 0) + return errno; + NodeRef ref(st); + + return get_attribute_path(ref, NULL, fd, attribute, attrPath, typePath); + } +} + + +// # pragma mark - Public API + + +// fs_open_attr_dir +DIR * +fs_open_attr_dir(const char *path) +{ + struct stat st; + if (lstat(path, &st)) + return NULL; + + return open_attr_dir(NodeRef(st), path, -1); +} + +// fs_fopen_attr_dir +DIR * +fs_fopen_attr_dir(int fd) +{ + struct stat st; + + status_t error = _kern_read_stat(fd, NULL, false, &st, + sizeof(struct stat)); + if (error != B_OK) { + errno = error; + return NULL; + } + + // Try to get a path. If we can't get a path, this is must be a "real" + // (i.e. system) file descriptor, which is just as well. + string path; + bool pathValid = (get_path(fd, NULL, path) == B_OK); + + // get the attribute path + return open_attr_dir(NodeRef(st), (pathValid ? path.c_str() : NULL), + (pathValid ? -1 : fd)); +} + +// fs_close_attr_dir +int +fs_close_attr_dir(DIR *dir) +{ + return closedir(dir); +} + +// fs_read_attr_dir +struct dirent * +fs_read_attr_dir(DIR *dir) +{ + struct dirent *entry = NULL; + while (true) { + // read the next entry + entry = readdir(dir); + if (!entry) + return NULL; + + // ignore administrative entries; the + if (entry->d_name[0] == '_') { + string attrName = deescape_attr_name(entry->d_name); + strcpy(entry->d_name, attrName.c_str()); + return entry; + } + } +} + +// fs_rewind_attr_dir +void +fs_rewind_attr_dir(DIR *dir) +{ + rewinddir(dir); +} + +// fs_open_attr +int +fs_open_attr(int fd, const char *attribute, uint32 type, int openMode) +{ + if (!attribute) { + errno = B_BAD_VALUE; + return -1; + } + + // get the attribute path + string attrPath; + string typePath; + status_t error = get_attribute_path(fd, attribute, attrPath, typePath); + if (error != B_OK) { + errno = error; + return -1; + } + + // check, if the attribute already exists + struct stat st; + bool exists = (lstat(attrPath.c_str(), &st) == 0); + + // open the attribute + int attrFD = open(attrPath.c_str(), openMode, S_IRWXU | S_IRWXG | S_IRWXO); + if (attrFD < 0) + return -1; + + // set the type, if the attribute didn't exist yet + if (!exists) { + // create a file prefixed "t" + int typeFD = creat(typePath.c_str(), S_IRWXU | S_IRWXG | S_IRWXO); + if (typeFD >= 0) { + // write the type into the file + if (write(typeFD, &type, sizeof(type)) < 0) + error = errno; + + close(typeFD); + + } else + error = errno; + + // remove type and attribute file, if something went wrong + if (error != B_OK) { + if (typeFD > 0) { + unlink(typePath.c_str()); + } + + close(attrFD); + unlink(attrPath.c_str()); + + errno = error; + return -1; + } + } + + return attrFD; +} + +// fs_close_attr +int +fs_close_attr(int fd) +{ + return close(fd); +} + +// fs_read_attr +ssize_t +fs_read_attr(int fd, const char *attribute, uint32 type, off_t pos, + void *buffer, size_t readBytes) +{ + // open the attribute + int attrFD = fs_open_attr(fd, attribute, type, O_RDONLY); [... truncated: 236 lines follow ...] From mmu_man at mail.berlios.de Sat Sep 6 02:57:26 2008 From: mmu_man at mail.berlios.de (mmu_man at mail.berlios.de) Date: Sat, 6 Sep 2008 02:57:26 +0200 Subject: [Haiku-commits] r27341 - haiku/trunk/src/system/kernel Message-ID: <200809060057.m860vQea032513@sheep.berlios.de> Author: mmu_man Date: 2008-09-06 02:57:24 +0200 (Sat, 06 Sep 2008) New Revision: 27341 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27341&view=rev Modified: haiku/trunk/src/system/kernel/module.cpp Log: No need to report an error on modules that aren't modules... Modified: haiku/trunk/src/system/kernel/module.cpp =================================================================== --- haiku/trunk/src/system/kernel/module.cpp 2008-09-05 23:34:16 UTC (rev 27340) +++ haiku/trunk/src/system/kernel/module.cpp 2008-09-06 00:57:24 UTC (rev 27341) @@ -1806,7 +1806,7 @@ for (image = args->preloaded_images; image != NULL; image = image->next) { status_t status = register_preloaded_module_image(image); - if (status != B_OK) { + if (status != B_OK && image->is_module) { dprintf("Could not register image \"%s\": %s\n", image->name, strerror(status)); } From laplace at mail.berlios.de Sat Sep 6 09:37:14 2008 From: laplace at mail.berlios.de (laplace at mail.berlios.de) Date: Sat, 6 Sep 2008 09:37:14 +0200 Subject: [Haiku-commits] r27342 - haiku/trunk/src/kits/interface Message-ID: <200809060737.m867bE1o022312@sheep.berlios.de> Author: laplace Date: 2008-09-06 09:37:12 +0200 (Sat, 06 Sep 2008) New Revision: 27342 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27342&view=rev Modified: haiku/trunk/src/kits/interface/ColorControl.cpp Log: Obviously the else block was missing. Modified: haiku/trunk/src/kits/interface/ColorControl.cpp =================================================================== --- haiku/trunk/src/kits/interface/ColorControl.cpp 2008-09-06 00:57:24 UTC (rev 27341) +++ haiku/trunk/src/kits/interface/ColorControl.cpp 2008-09-06 07:37:12 UTC (rev 27342) @@ -398,9 +398,10 @@ fBitmap->Unlock(); _DrawSelectors(this); - } else + } else { _DrawColorArea(this, updateRect); _DrawSelectors(this); + } } From stippi at mail.berlios.de Sat Sep 6 10:03:00 2008 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Sat, 6 Sep 2008 10:03:00 +0200 Subject: [Haiku-commits] r27343 - haiku/trunk/src/kits/tracker Message-ID: <200809060803.m86830el023604@sheep.berlios.de> Author: stippi Date: 2008-09-06 10:02:59 +0200 (Sat, 06 Sep 2008) New Revision: 27343 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27343&view=rev Modified: haiku/trunk/src/kits/tracker/AutoMounter.cpp haiku/trunk/src/kits/tracker/AutoMounter.h Log: Improve the Read-Only mounting suggestion for additional volumes. * Following a suggestion by BGA, even non-boot Haiku volumes will get the read-only popup, although with less emphasis in the wording. * BPartition does inherit the read-only flag from it's parent device when not yet mounted. This is now checked and at least prevents the read-only popup for volumes on read-only media. If I understood everything correctly, there is no easy way to tell if a file system supports writing. * Updated indentation style in the header. Modified: haiku/trunk/src/kits/tracker/AutoMounter.cpp =================================================================== --- haiku/trunk/src/kits/tracker/AutoMounter.cpp 2008-09-06 07:37:12 UTC (rev 27342) +++ haiku/trunk/src/kits/tracker/AutoMounter.cpp 2008-09-06 08:02:59 UTC (rev 27343) @@ -182,32 +182,42 @@ } -void -AutoMounter::_MountVolume(BMessage *message) +bool +AutoMounter::_SuggestMountFlags(const BPartition* partition, + uint32* _flags) const { - int32 id; - if (message->FindInt32("id", &id) != B_OK) - return; + uint32 mountFlags = 0; - BDiskDeviceRoster roster; - BPartition *partition; - BDiskDevice device; - if (roster.GetPartitionWithID(id, &device, &partition) != B_OK) - return; + bool askReadOnly = true; + bool isBFS = false; - uint32 mountFlags = 0; - if (partition->ContentType() == NULL - || strcmp(partition->ContentType(), kPartitionTypeBFS) != 0) { - // not a BFS volume, suggest to the user to mount read-only - // until Haiku is more mature. + if (partition->ContentType() != NULL + && strcmp(partition->ContentType(), kPartitionTypeBFS) == 0) { +#if 0 + askReadOnly = false; +#endif + isBFS = true; + } + + if (partition->IsReadOnly()) + askReadOnly = false; + + if (askReadOnly) { + // Suggest to the user to mount read-only until Haiku is more mature. // TODO: would be nice to skip this for file systems which don't have // support for writing anyways. BString string; // TODO: Use distro name instead of "Haiku"... - string << "The file system on this volume is not the Haiku file " - "system. It is strongly suggested to mount it in read-only mode." - "This will prevent unintentional data loss because of errors " - "in Haiku."; + if (!isBFS) { + string << "The file system on this volume is not the Haiku file " + "system. It is strongly suggested to mount it in read-only " + "mode. "; + } else { + string << "It is suggested to mount all additional Haiku volumes " + "in read-only mode. "; + } + string << "This will prevent unintentional data loss because of " + "errors in Haiku."; BAlert* alert = new BAlert("Mount Warning", string.String(), "Mount Read/Write", "Cancel", "Mount Read-only", B_WIDTH_FROM_WIDEST, B_WARNING_ALERT); @@ -216,13 +226,35 @@ case 0: break; case 1: - return; + return false; case 2: mountFlags |= B_MOUNT_READ_ONLY; break; } } + *_flags = mountFlags; + return true; +} + + +void +AutoMounter::_MountVolume(const BMessage* message) +{ + int32 id; + if (message->FindInt32("id", &id) != B_OK) + return; + + BDiskDeviceRoster roster; + BPartition *partition; + BDiskDevice device; + if (roster.GetPartitionWithID(id, &device, &partition) != B_OK) + return; + + uint32 mountFlags; + if (!_SuggestMountFlags(partition, &mountFlags)) + return; + status_t status = partition->Mount(NULL, mountFlags); if (status < B_OK) { BString string; @@ -237,7 +269,7 @@ { BString text; text << "Could not unmount disk \"" << name << "\":\n\t" << strerror(error); - text << "\n\nShould I force unmounting the disk?\n\n" + text << "\n\nShould unmounting be forced?\n\n" "Note: if an application is currently writing to the volume, unmounting" " it now might result in loss of data.\n"; @@ -510,7 +542,7 @@ void -AutoMounter::MessageReceived(BMessage *message) +AutoMounter::MessageReceived(BMessage* message) { switch (message->what) { case kMsgInitialScan: Modified: haiku/trunk/src/kits/tracker/AutoMounter.h =================================================================== --- haiku/trunk/src/kits/tracker/AutoMounter.h 2008-09-06 07:37:12 UTC (rev 27342) +++ haiku/trunk/src/kits/tracker/AutoMounter.h 2008-09-06 08:02:59 UTC (rev 27343) @@ -57,49 +57,56 @@ // #pragma mark - Haiku Disk Device API class AutoMounter : public BLooper { - public: - AutoMounter(); - virtual ~AutoMounter(); +public: + AutoMounter(); + virtual ~AutoMounter(); - virtual bool QuitRequested(); + virtual bool QuitRequested(); - void GetSettings(BMessage* message); + void GetSettings(BMessage* message); - private: - enum mount_mode { - kNoVolumes, - kOnlyBFSVolumes, - kAllVolumes, - kRestorePreviousVolumes - }; +private: + enum mount_mode { + kNoVolumes, + kOnlyBFSVolumes, + kAllVolumes, + kRestorePreviousVolumes + }; - void _MountVolumes(mount_mode normal, mount_mode removable, - bool initialRescan); - void _MountVolume(BMessage* message); - bool _SuggestForceUnmount(const char* name, status_t error); - void _ReportUnmountError(const char* name, status_t error); - void _UnmountAndEjectVolume(BPartition* partition, BPath& mountPoint, - const char* name); - void _UnmountAndEjectVolume(BMessage* message); + bool _SuggestMountFlags(const BPartition* partition, + uint32* _flags) const; + void _MountVolumes(mount_mode normal, + mount_mode removable, bool initialRescan); + void _MountVolume(const BMessage* message); + bool _SuggestForceUnmount(const char* name, + status_t error); + void _ReportUnmountError(const char* name, + status_t error); + void _UnmountAndEjectVolume(BPartition* partition, + BPath& mountPoint, const char* name); + void _UnmountAndEjectVolume(BMessage* message); - void _FromMode(mount_mode mode, bool& all, bool& bfs, bool& restore); - mount_mode _ToMode(bool all, bool bfs, bool restore = false); - void _UpdateSettingsFromMessage(BMessage* message); - void _ReadSettings(); - void _WriteSettings(); + void _FromMode(mount_mode mode, bool& all, + bool& bfs, bool& restore); + mount_mode _ToMode(bool all, bool bfs, + bool restore = false); - virtual void MessageReceived(BMessage* message); + void _UpdateSettingsFromMessage(BMessage* message); + void _ReadSettings(); + void _WriteSettings(); - private: - mount_mode fNormalMode; - mount_mode fRemovableMode; + virtual void MessageReceived(BMessage* message); - BFile fPrefsFile; - BMessage fSettings; +private: + mount_mode fNormalMode; + mount_mode fRemovableMode; + + BFile fPrefsFile; + BMessage fSettings; }; #else // !__HAIKU__ -// #pragma mark - R5 DeviceMap API +// #pragma mark - R5 DeviceMap API const uint32 kSuspendAutomounter = 'amsp'; const uint32 kResumeAutomounter = 'amsr'; From laplace at mail.berlios.de Sat Sep 6 11:13:18 2008 From: laplace at mail.berlios.de (laplace at mail.berlios.de) Date: Sat, 6 Sep 2008 11:13:18 +0200 Subject: [Haiku-commits] r27344 - haiku/trunk/src/preferences/appearance Message-ID: <200809060913.m869DIuC032708@sheep.berlios.de> Author: laplace Date: 2008-09-06 11:13:16 +0200 (Sat, 06 Sep 2008) New Revision: 27344 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27344&view=rev Modified: haiku/trunk/src/preferences/appearance/APRView.cpp haiku/trunk/src/preferences/appearance/ColorWell.cpp haiku/trunk/src/preferences/appearance/ColorWell.h Log: * Always draw entire ColorWell to avoid flickering * Moved ColorWell infront of ColorPicker. It was hidden behinde the attribute list. * Made ColorWell and ColorPicker follow its parent frame bottom when resized. * Made attribute list follows its parent frame top and bottom when resized. Modified: haiku/trunk/src/preferences/appearance/APRView.cpp =================================================================== --- haiku/trunk/src/preferences/appearance/APRView.cpp 2008-09-06 08:02:59 UTC (rev 27343) +++ haiku/trunk/src/preferences/appearance/APRView.cpp 2008-09-06 09:13:16 UTC (rev 27344) @@ -122,10 +122,10 @@ rect.right -= B_V_SCROLL_BAR_WIDTH; rect.bottom = rect.top + 75; fAttrList = new BListView(rect,"AttributeList", B_SINGLE_SELECTION_LIST, - B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); + B_FOLLOW_ALL_SIDES); - fScrollView = new BScrollView("ScrollView",fAttrList, B_FOLLOW_LEFT_RIGHT | - B_FOLLOW_TOP, 0, false, true); + fScrollView = new BScrollView("ScrollView",fAttrList, B_FOLLOW_ALL_SIDES, + 0, false, true); AddChild(fScrollView); fScrollView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); @@ -137,23 +137,31 @@ printf("Adding color item for which: %ld\n", sColorConsts[i]); fAttrList->AddItem(new ColorWhichItem((color_which)sColorConsts[i])); } - - BRect wellrect(0,0,50,50); - wellrect.OffsetTo(rect.right + 30, rect.top + - (fScrollView->Bounds().Height() - wellrect.Height())/2 ); - - fColorWell = new ColorWell(wellrect,new BMessage(COLOR_DROPPED),true); - AddChild(fColorWell); - // Center the list and color well - rect = fScrollView->Frame(); - rect.right = wellrect.right; - rect.OffsetTo((Bounds().Width()-rect.Width())/2,rect.top); + BRect wellrect(0, 0, 50, 50); + wellrect.OffsetBy(rect.left, rect.bottom + kBorderSpace); + fColorWell = new ColorWell(wellrect, new BMessage(COLOR_DROPPED), + B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); + AddChild(fColorWell); - fPicker = new BColorControl(BPoint(fScrollView->Frame().left,fScrollView->Frame().bottom+kBorderSpace),B_CELLS_32x8,5.0,"fPicker", - new BMessage(UPDATE_COLOR)); + fPicker = new BColorControl(BPoint(wellrect.right + kBorderSpace, wellrect.top), + B_CELLS_32x8, 5.0, "fPicker", new BMessage(UPDATE_COLOR)); + fPicker->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); AddChild(fPicker); + + // bottom align ColorWell and ColorPicker + float bottom = Bounds().bottom - kBorderSpace; + float colorWellBottom = fColorWell->Frame().bottom; + float pickerBottom = fPicker->Frame().bottom; + float delta = bottom - max_c(colorWellBottom, pickerBottom); + fColorWell->MoveBy(0, delta); + fPicker->MoveBy(0, delta); + fScrollView->ResizeBy(0, delta); + // TODO fix BView::ResizeBy(...): + // the child views should resize with its parent view (fScrollView) + fScrollView->ScrollBar(B_VERTICAL)->ResizeBy(0, delta); + fAttrList->ResizeBy(0, delta); } APRView::~APRView(void) Modified: haiku/trunk/src/preferences/appearance/ColorWell.cpp =================================================================== --- haiku/trunk/src/preferences/appearance/ColorWell.cpp 2008-09-06 08:02:59 UTC (rev 27343) +++ haiku/trunk/src/preferences/appearance/ColorWell.cpp 2008-09-06 09:13:16 UTC (rev 27344) @@ -7,10 +7,10 @@ */ #include "ColorWell.h" -ColorWell::ColorWell(BRect frame, BMessage *msg, bool is_rectangle) - : BView(frame,"ColorWell", B_FOLLOW_LEFT|B_FOLLOW_TOP, B_WILL_DRAW) +ColorWell::ColorWell(BRect frame, BMessage *msg, uint32 resizingMode, uint32 flags) + : BView(frame,"ColorWell", resizingMode, flags | B_WILL_DRAW) { - SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + SetViewColor(B_TRANSPARENT_COLOR); SetLowColor(0,0,0); invoker=new BInvoker(msg,this); disabledcol.red=128; @@ -18,7 +18,7 @@ disabledcol.blue=128; disabledcol.alpha=255; is_enabled=true; - is_rect=is_rectangle; + is_rect = true; } ColorWell::~ColorWell(void) @@ -84,20 +84,20 @@ void ColorWell::Draw(BRect update) { - if(is_enabled) - SetHighColor(currentcol); + rgb_color color; + if (is_enabled) + color = currentcol; else - SetHighColor(disabledcol); - + color = disabledcol; + if(is_rect) { - FillRect(Bounds()); if(is_enabled) { BRect r(Bounds()); SetHighColor(184,184,184); StrokeRect(r); SetHighColor(255,255,255); - StrokeLine(BPoint(r.right,r.top+1), r.RightBottom()); + StrokeLine(BPoint(r.right, r.top+1), r.RightBottom()); r.InsetBy(1,1); @@ -107,10 +107,21 @@ SetHighColor(96,96,96); StrokeLine(r.LeftTop(), r.RightTop()); StrokeLine(r.LeftTop(), r.LeftBottom()); - + + r.InsetBy(1, 1); + SetHighColor(color); + FillRect(r); + } else { + SetHighColor(color); + FillRect(Bounds()); } } else { + // fill background + SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + FillRect(update); + + SetHighColor(color); FillEllipse(Bounds()); if(is_enabled) StrokeEllipse(Bounds(),B_SOLID_LOW); Modified: haiku/trunk/src/preferences/appearance/ColorWell.h =================================================================== --- haiku/trunk/src/preferences/appearance/ColorWell.h 2008-09-06 08:02:59 UTC (rev 27343) +++ haiku/trunk/src/preferences/appearance/ColorWell.h 2008-09-06 09:13:16 UTC (rev 27344) @@ -15,7 +15,9 @@ class ColorWell : public BView { public: - ColorWell(BRect frame, BMessage *msg, bool is_rectangle=false); + ColorWell(BRect frame, BMessage *msg, + uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, + uint32 flags = B_WILL_DRAW); ~ColorWell(void); void SetColor(rgb_color col); rgb_color Color(void) const; From michael.w.pfeiffer at gmail.com Sat Sep 6 11:24:23 2008 From: michael.w.pfeiffer at gmail.com (Michael Pfeiffer) Date: Sat, 6 Sep 2008 11:24:23 +0200 Subject: [Haiku-commits] r27344 - haiku/trunk/src/preferences/appearance In-Reply-To: <200809060913.m869DIuC032708@sheep.berlios.de> References: <200809060913.m869DIuC032708@sheep.berlios.de> Message-ID: Am 06.09.2008 um 11:13 schrieb laplace at mail.berlios.de: > * Moved ColorWell infront of ColorPicker. It was hidden behinde the > attribute list. While fixing that I discovered two more bugs (will file bug reports on request): * The children of a BScrollView do not resize with its parent when ResizeBy is called. However they do when the users resizes the window containing the BScrollView (resizingMode is B_FOLLOW_ALL for the scroll view and its target view). * The Appearance preflet does not remember color changes. For example you change the color of one attribute then select another attribute and then select the first attribute. Its color seems to be reset to its initial value. - Michael From superstippi at gmx.de Sat Sep 6 12:04:43 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Sat, 06 Sep 2008 12:04:43 +0200 Subject: [Haiku-commits] r27344 - haiku/trunk/src/preferences/appearance In-Reply-To: References: <200809060913.m869DIuC032708@sheep.berlios.de> Message-ID: <20080906120443.22773.2@bepc.1220691719.fake> Hi, On 2008-09-06 at 11:51:23 [+0200], Michael Pfeiffer wrote: > While fixing that I discovered two more bugs (will file bug reports on > request): > * The children of a BScrollView do not resize with its parent when > ResizeBy is called. > However they do when the users resizes the window containing the > BScrollView (resizingMode is B_FOLLOW_ALL for the scroll view and > its target view). This behavior is also the BeOS behavior when the views are not yet attached to the window. Since you are creating and adding them in a BView constructor, the parent BView is not yet attached. The expected behavior only works when everything is attached and running. Some apps will rely on this difference. From your own code, you can see that if we simply fixed it, your code would be broken and needed to be changed. BTW, since the Appearance preflet is Haiku only, I would much prefer to "port" it to use the layout management instead. ;-) Best regards, -Stephan From michael.w.pfeiffer at gmail.com Sat Sep 6 13:05:03 2008 From: michael.w.pfeiffer at gmail.com (Michael Pfeiffer) Date: Sat, 6 Sep 2008 13:05:03 +0200 Subject: [Haiku-commits] r27344 - haiku/trunk/src/preferences/appearance In-Reply-To: <20080906120443.22773.2@bepc.1220691719.fake> References: <200809060913.m869DIuC032708@sheep.berlios.de> <20080906120443.22773.2@bepc.1220691719.fake> Message-ID: <3A9E4340-CECC-45D8-9A16-31C7CF661BF8@gmail.com> Am 06.09.2008 um 12:04 schrieb Stephan Assmus: > Hi, > > On 2008-09-06 at 11:51:23 [+0200], Michael Pfeiffer > wrote: >> While fixing that I discovered two more bugs (will file bug reports >> on >> request): >> * The children of a BScrollView do not resize with its parent when >> ResizeBy is called. >> However they do when the users resizes the window containing the >> BScrollView (resizingMode is B_FOLLOW_ALL for the scroll view and >> its target view). > > This behavior is also the BeOS behavior when the views are not yet > attached > to the window. Since you are creating and adding them in a BView > constructor, the parent BView is not yet attached. The expected > behavior > only works when everything is attached and running. Some apps will > rely on > this difference. From your own code, you can see that if we simply > fixed > it, your code would be broken and needed to be changed. Thanks for the clarification. > BTW, since the Appearance preflet is Haiku only, I would much prefer > to > "port" it to use the layout management instead. ;-) +1 ;) - Michael From laplace at mail.berlios.de Sat Sep 6 13:08:58 2008 From: laplace at mail.berlios.de (laplace at mail.berlios.de) Date: Sat, 6 Sep 2008 13:08:58 +0200 Subject: [Haiku-commits] r27345 - haiku/trunk/src/preferences/appearance Message-ID: <200809061108.m86B8wcB027056@sheep.berlios.de> Author: laplace Date: 2008-09-06 13:08:55 +0200 (Sat, 06 Sep 2008) New Revision: 27345 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27345&view=rev Modified: haiku/trunk/src/preferences/appearance/APRView.cpp Log: Removed wrong TODO. Modified: haiku/trunk/src/preferences/appearance/APRView.cpp =================================================================== --- haiku/trunk/src/preferences/appearance/APRView.cpp 2008-09-06 09:13:16 UTC (rev 27344) +++ haiku/trunk/src/preferences/appearance/APRView.cpp 2008-09-06 11:08:55 UTC (rev 27345) @@ -158,8 +158,8 @@ fColorWell->MoveBy(0, delta); fPicker->MoveBy(0, delta); fScrollView->ResizeBy(0, delta); - // TODO fix BView::ResizeBy(...): - // the child views should resize with its parent view (fScrollView) + // since this view is not attached to a window yet, + // we have to resize the fScrollView children too fScrollView->ScrollBar(B_VERTICAL)->ResizeBy(0, delta); fAttrList->ResizeBy(0, delta); } From korli at mail.berlios.de Sat Sep 6 15:00:20 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Sat, 6 Sep 2008 15:00:20 +0200 Subject: [Haiku-commits] r27346 - haiku/trunk/src/bin Message-ID: <200809061300.m86D0K4E006283@sheep.berlios.de> Author: korli Date: 2008-09-06 15:00:19 +0200 (Sat, 06 Sep 2008) New Revision: 27346 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27346&view=rev Modified: haiku/trunk/src/bin/sysinfo.c Log: print out unknown cpu types Modified: haiku/trunk/src/bin/sysinfo.c =================================================================== --- haiku/trunk/src/bin/sysinfo.c 2008-09-06 11:08:55 UTC (rev 27345) +++ haiku/trunk/src/bin/sysinfo.c 2008-09-06 13:00:19 UTC (rev 27346) @@ -495,10 +495,15 @@ { const char *vendor = get_cpu_vendor_string(info->cpu_type); const char *model = get_cpu_model_string(info); + char modelString[32]; int32 cpu; if (model == NULL && vendor == NULL) model = "(Unknown)"; + else if (model == NULL) { + model = modelString; + snprintf(modelString, 32, "(Unknown %x)", info->cpu_type); + } printf("%ld %s%s%s, revision %04lx running at %LdMHz (ID: 0x%08lx 0x%08lx)\n\n", info->cpu_count, From laplace at mail.berlios.de Sat Sep 6 15:57:21 2008 From: laplace at mail.berlios.de (laplace at mail.berlios.de) Date: Sat, 6 Sep 2008 15:57:21 +0200 Subject: [Haiku-commits] r27347 - haiku/trunk/src/preferences/appearance Message-ID: <200809061357.m86DvLDx009710@sheep.berlios.de> Author: laplace Date: 2008-09-06 15:57:17 +0200 (Sat, 06 Sep 2008) New Revision: 27347 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27347&view=rev Modified: haiku/trunk/src/preferences/appearance/APRView.cpp haiku/trunk/src/preferences/appearance/APRView.h haiku/trunk/src/preferences/appearance/ColorSet.cpp haiku/trunk/src/preferences/appearance/ColorSet.h haiku/trunk/src/preferences/appearance/ColorWhichItem.cpp haiku/trunk/src/preferences/appearance/ColorWhichItem.h Log: * Remember changing the color of an ui_color. * Simplified code a lot when doing that and removed lots of unused code. Modified: haiku/trunk/src/preferences/appearance/APRView.cpp =================================================================== --- haiku/trunk/src/preferences/appearance/APRView.cpp 2008-09-06 13:00:19 UTC (rev 27346) +++ haiku/trunk/src/preferences/appearance/APRView.cpp 2008-09-06 13:57:17 UTC (rev 27347) @@ -24,47 +24,10 @@ #include "ColorWhichItem.h" #include "ColorSet.h" -//#define DEBUG_APRVIEW -#ifdef DEBUG_APRVIEW - #define STRACE(a) printf a -#else - #define STRACE(A) /* nothing */ -#endif - #define COLOR_DROPPED 'cldp' #define DECORATOR_CHANGED 'dcch' -int32 sColorConsts[] = { - B_PANEL_BACKGROUND_COLOR, - B_PANEL_TEXT_COLOR, - B_DOCUMENT_BACKGROUND_COLOR, - B_DOCUMENT_TEXT_COLOR, - B_CONTROL_BACKGROUND_COLOR, - B_CONTROL_TEXT_COLOR, - B_CONTROL_BORDER_COLOR, - B_CONTROL_HIGHLIGHT_COLOR, - B_NAVIGATION_BASE_COLOR, - B_NAVIGATION_PULSE_COLOR, - B_SHINE_COLOR, - B_SHADOW_COLOR, - B_MENU_BACKGROUND_COLOR, - B_MENU_SELECTED_BACKGROUND_COLOR, - B_MENU_ITEM_TEXT_COLOR, - B_MENU_SELECTED_ITEM_TEXT_COLOR, - B_MENU_SELECTED_BORDER_COLOR, - B_TOOLTIP_BACKGROUND_COLOR, - B_TOOLTIP_TEXT_COLOR, - B_SUCCESS_COLOR, - B_FAILURE_COLOR, - B_WINDOW_TAB_COLOR, - B_WINDOW_TEXT_COLOR, - B_WINDOW_INACTIVE_TAB_COLOR, - B_WINDOW_INACTIVE_TEXT_COLOR, -}; - -const uint32 sColorCount = sizeof(sColorConsts) / sizeof(int32); - namespace BPrivate { int32 count_decorators(void); @@ -76,6 +39,7 @@ APRView::APRView(const BRect &frame, const char *name, int32 resize, int32 flags) : BView(frame,name,resize,flags), + fDefaultSet(ColorSet::DefaultColorSet()), fDecorMenu(NULL) { SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); @@ -131,11 +95,11 @@ fAttrList->SetSelectionMessage(new BMessage(ATTRIBUTE_CHOSEN)); - printf("Color count: %lu\n", sColorCount); - - for (uint32 i = 0; i < sColorCount; i++) { - printf("Adding color item for which: %ld\n", sColorConsts[i]); - fAttrList->AddItem(new ColorWhichItem((color_which)sColorConsts[i])); + for (int32 i = 0; i < color_description_count(); i++) { + const ColorDescription& description = *get_color_description(i); + const char* text = description.text; + color_which which = description.which; + fAttrList->AddItem(new ColorWhichItem(text, which)); } rect = fScrollView->Frame(); @@ -166,7 +130,6 @@ APRView::~APRView(void) { - ColorSet::SaveColorSet("/boot/home/config/settings/app_server/system_colors",fCurrentSet); } void @@ -176,8 +139,6 @@ fAttrList->SetTarget(this); fColorWell->SetTarget(this); - fPicker->SetValue(fCurrentSet.StringToColor(fAttrString.String())); - if (fDecorMenu) fDecorMenu->SetTargetForItems(BMessenger(this)); @@ -189,14 +150,11 @@ APRView::MessageReceived(BMessage *msg) { if (msg->WasDropped()) { - rgb_color *col; + rgb_color *color; ssize_t size; - if (msg->FindData("RGBColor",(type_code)'RGBC',(const void**)&col,&size)==B_OK) { - fPicker->SetValue(*col); - fColorWell->SetColor(*col); - fColorWell->Invalidate(); - UpdateCurrentColor(); + if (msg->FindData("RGBColor", (type_code)'RGBC', (const void**)&color, &size) == B_OK) { + SetCurrentColor(*color); } } @@ -211,15 +169,8 @@ } case UPDATE_COLOR: { // Received from the color fPicker when its color changes - - rgb_color col=fPicker->ValueAsColor(); - - fColorWell->SetColor(col); - fColorWell->Invalidate(); - - // Update current fAttribute in the settings - fCurrentSet.SetColor(fAttribute, col); - UpdateCurrentColor(); + rgb_color color = fPicker->ValueAsColor(); + SetCurrentColor(color); Window()->PostMessage(kMsgUpdate); break; @@ -227,21 +178,23 @@ case ATTRIBUTE_CHOSEN: { // Received when the user chooses a GUI fAttribute from the list - ColorWhichItem *whichitem = (ColorWhichItem*) + ColorWhichItem *item = (ColorWhichItem*) fAttrList->ItemAt(fAttrList->CurrentSelection()); - if (!whichitem) + if (item == NULL) break; - fAttrString=whichitem->Text(); - UpdateControlsFromAttr(whichitem->Text()); + fWhich = item->ColorWhich(); + rgb_color color = fCurrentSet.GetColor(fWhich); + SetCurrentColor(color); Window()->PostMessage(kMsgUpdate); break; } case REVERT_SETTINGS: { - fCurrentSet=fPrevSet; - UpdateControlsFromAttr(fAttrString.String()); + fCurrentSet = fPrevSet; + + UpdateControls(); UpdateAllColors(); Window()->PostMessage(kMsgUpdate); @@ -250,7 +203,7 @@ case DEFAULT_SETTINGS: { fCurrentSet = ColorSet::DefaultColorSet(); - UpdateControlsFromAttr(fAttrString.String()); + UpdateControls(); UpdateAllColors(); BMenuItem *item = fDecorMenu->FindItem("Default"); @@ -272,43 +225,43 @@ void APRView::LoadSettings(void) { - printf("Max colors: %lu\n", sColorCount); - for (uint32 i = 0; i < sColorCount; i++) { - printf("getting ui_color for index %lu, constant: %ld\n", i, sColorConsts[i]); - fCurrentSet.SetColor((color_which)sColorConsts[i], ui_color((color_which)sColorConsts[i])); + for (int32 i = 0; i < color_description_count(); i++) { + color_which which = get_color_description(i)->which; + fCurrentSet.SetColor(which, ui_color(which)); } - fCurrentSet.PrintToStream(); - fPrevSet = fCurrentSet; } bool APRView::IsDefaultable(void) { - return fCurrentSet.IsDefaultable(); + return fCurrentSet != fDefaultSet; } void APRView::UpdateAllColors(void) { - for (uint32 i = 0; i < sColorCount; i++) - set_ui_color((color_which)sColorConsts[i], - fCurrentSet.AttributeToColor((color_which)sColorConsts[i])); + for (int32 i = 0; i < color_description_count(); i++) { + color_which which = get_color_description(i)->which; + rgb_color color = fCurrentSet.GetColor(which); + set_ui_color(which, color); + } } -void APRView::UpdateCurrentColor(void) + +void +APRView::SetCurrentColor(rgb_color color) { - rgb_color col=fPicker->ValueAsColor(); - ColorWhichItem *whichitem = (ColorWhichItem *)fAttrList->ItemAt(fAttrList->CurrentSelection()); - set_ui_color(whichitem->GetAttribute(), col); + fCurrentSet.SetColor(fWhich, color); + set_ui_color(fWhich, color); + UpdateControls(); } -void APRView::UpdateControlsFromAttr(const char *string) -{ - if (!string) - return; - STRACE(("Update color for %s\n",string)); - fPicker->SetValue(fCurrentSet.StringToColor(string)); - fColorWell->SetColor(fPicker->ValueAsColor()); +void +APRView::UpdateControls() +{ + rgb_color color = fCurrentSet.GetColor(fWhich); + fPicker->SetValue(color); + fColorWell->SetColor(color); fColorWell->Invalidate(); } Modified: haiku/trunk/src/preferences/appearance/APRView.h =================================================================== --- haiku/trunk/src/preferences/appearance/APRView.h 2008-09-06 13:00:19 UTC (rev 27346) +++ haiku/trunk/src/preferences/appearance/APRView.h 2008-09-06 13:57:17 UTC (rev 27347) @@ -44,24 +44,23 @@ protected: - void UpdateControlsFromAttr(const char *string); - void UpdateCurrentColor(); + void SetCurrentColor(rgb_color color); + void UpdateControls(); void UpdateAllColors(); BColorControl *fPicker; BListView *fAttrList; - color_which fAttribute; + color_which fWhich; - BString fAttrString; - BScrollView *fScrollView; ColorWell *fColorWell; ColorSet fCurrentSet; ColorSet fPrevSet; + ColorSet fDefaultSet; BMenu *fDecorMenu; }; Modified: haiku/trunk/src/preferences/appearance/ColorSet.cpp =================================================================== --- haiku/trunk/src/preferences/appearance/ColorSet.cpp 2008-09-06 13:00:19 UTC (rev 27346) +++ haiku/trunk/src/preferences/appearance/ColorSet.cpp 2008-09-06 13:57:17 UTC (rev 27347) @@ -17,17 +17,51 @@ #include #include "ColorSet.h" -static ColorSet sDefaults = ColorSet::DefaultColorSet(); -static std::map sColorNames = ColorSet::DefaultColorNames(); -bool -match_rgb_color(rgb_color& color, uint8 red, uint8 green, uint8 blue) +static ColorDescription sColorDescriptionTable[] = { - return color.red == red - && color.green == green - && color.blue == blue; + { B_PANEL_BACKGROUND_COLOR, "Panel Background" }, + { B_PANEL_TEXT_COLOR, "Panel Text" }, + { B_DOCUMENT_BACKGROUND_COLOR, "Document Background" }, + { B_DOCUMENT_TEXT_COLOR, "Document Text" }, + { B_CONTROL_BACKGROUND_COLOR, "Control Background" }, + { B_CONTROL_TEXT_COLOR, "Control Text" }, + { B_CONTROL_BORDER_COLOR, "Control Border" }, + { B_CONTROL_HIGHLIGHT_COLOR, "Control Highlight" }, + { B_NAVIGATION_BASE_COLOR, "Navigation Base" }, + { B_NAVIGATION_PULSE_COLOR, "Navigation Pulse" }, + { B_SHINE_COLOR, "Shine" }, + { B_SHADOW_COLOR, "Shadow" }, + { B_MENU_BACKGROUND_COLOR, "Menu Background" }, + { B_MENU_SELECTED_BACKGROUND_COLOR, "Selected Menu Item Background" }, + { B_MENU_ITEM_TEXT_COLOR, "Menu Item Text" }, + { B_MENU_SELECTED_ITEM_TEXT_COLOR, "Selected Menu Item Text" }, + { B_MENU_SELECTED_BORDER_COLOR, "Selected Menu Item Border" }, + { B_TOOLTIP_BACKGROUND_COLOR, "Tooltip Background" }, + { B_TOOLTIP_TEXT_COLOR, "Tooltip Text" }, + { B_SUCCESS_COLOR, "Success" }, + { B_FAILURE_COLOR, "Failure" }, + { B_WINDOW_TAB_COLOR, "Window Tab" }, + { B_WINDOW_TEXT_COLOR, "Window Tab Text" }, + { B_WINDOW_INACTIVE_TAB_COLOR, "Inactive Window Tab" }, + { B_WINDOW_INACTIVE_TEXT_COLOR, "Inactive Window Tab Text" } +}; + +const int32 sColorDescriptionCount = sizeof(sColorDescriptionTable) / sizeof(ColorDescription); + +const ColorDescription* +get_color_description(int32 index) +{ + if (index < 0 || index >= sColorDescriptionCount) + return NULL; + return &sColorDescriptionTable[index]; } +int32 +color_description_count(void) +{ + return sColorDescriptionCount; +} // #pragma mark - @@ -42,7 +76,7 @@ */ ColorSet::ColorSet(const ColorSet &cs) { - SetColors(cs); + *this = cs; } /*! @@ -53,32 +87,11 @@ ColorSet & ColorSet::operator=(const ColorSet &cs) { - SetColors(cs); + fColors = cs.fColors; return *this; } -/*! - \brief Copy function which handles assignments, - and, yes, *IT EVEN MAKES french fries!!* - \param cs Color set to copy from -*/ -void -ColorSet::SetColors(const ColorSet &cs) -{ - fColors = cs.fColors; -} -//! Prints all color set elements to stdout -void -ColorSet::PrintToStream(void) const -{ - for (std::map::const_iterator it = sColorNames.begin(); it != sColorNames.end(); ++it) { - printf("%s ", it->second.String()); - PrintMember(it->first); - printf("\n"); - } -} - /*! \brief Assigns the default system colors to the passed ColorSet object \param set The ColorSet object to set to defaults @@ -86,9 +99,6 @@ ColorSet ColorSet::DefaultColorSet(void) { -#ifdef DEBUG_COLORSET -printf("Initializing color settings to defaults\n"); -#endif ColorSet set; set.fColors[B_PANEL_BACKGROUND_COLOR] = make_color(216, 216, 216); set.fColors[B_PANEL_TEXT_COLOR] = make_color(0, 0, 0); @@ -119,205 +129,23 @@ return set; } - -/*! - \brief Checks if the ColorSet can be set to defaults. -*/ -bool -ColorSet::IsDefaultable() -{ - return (*this == sDefaults); -} - -/*! - \brief Attaches the color set's members as data to the given BMessage - \param msg The message to receive the attributes -*/ -bool -ColorSet::ConvertToMessage(BMessage *msg) const -{ - if(!msg) - return false; - - msg->MakeEmpty(); - rgb_color color; - - for (std::map::const_iterator it = sColorNames.begin(); it != sColorNames.end(); ++it) { - std::map::const_iterator cit = fColors.find(it->first); - if (cit != fColors.end()) - msg->AddData(it->second.String(), (type_code)'RGBC', &(cit->second), sizeof(rgb_color)); - else - msg->AddData(it->second.String(), (type_code)'RGBC', &color, sizeof(rgb_color)); - } - - return true; -} - -/*! - \brief Assigns values to the color set's members based on values in the BMessage - \param msg The message containing the data for the color set's colors -*/ - -bool -ColorSet::ConvertFromMessage(const BMessage *msg) -{ - if(!msg) - return false; - - rgb_color *col; - ssize_t size; - BString str; - - for (std::map::const_iterator it = sColorNames.begin(); - it != sColorNames.end(); ++it) { - if (msg->FindData(it->second.String(),(type_code)'RGBC',(const void**)&col,&size)==B_OK) - fColors[it->first] = *col; - } - return true; -} - -std::map -ColorSet::DefaultColorNames(void) -{ - std::map names; - - names[B_PANEL_BACKGROUND_COLOR] = "Panel Background"; - names[B_PANEL_TEXT_COLOR] = "Panel Text"; - names[B_DOCUMENT_BACKGROUND_COLOR] = "Document Background"; - names[B_DOCUMENT_TEXT_COLOR] = "Document Text"; - names[B_CONTROL_BACKGROUND_COLOR] = "Control Background"; - names[B_CONTROL_TEXT_COLOR] = "Control Text"; - names[B_CONTROL_BORDER_COLOR] = "Control Border"; - names[B_CONTROL_HIGHLIGHT_COLOR] = "Control Highlight"; - names[B_NAVIGATION_BASE_COLOR] = "Navigation Base"; - names[B_NAVIGATION_PULSE_COLOR] = "Navigation Pulse"; - names[B_SHINE_COLOR] = "Shine"; - names[B_SHADOW_COLOR] = "Shadow"; - names[B_MENU_BACKGROUND_COLOR] = "Menu Background"; - names[B_MENU_SELECTED_BACKGROUND_COLOR] = "Selected Menu Item Background"; - names[B_MENU_ITEM_TEXT_COLOR] = "Menu Item Text"; - names[B_MENU_SELECTED_ITEM_TEXT_COLOR] = "Selected Menu Item Text"; - names[B_MENU_SELECTED_BORDER_COLOR] = "Selected Menu Item Border"; - names[B_TOOLTIP_BACKGROUND_COLOR] = "Tooltip Background"; - names[B_TOOLTIP_TEXT_COLOR] = "Tooltip Text"; - names[B_SUCCESS_COLOR] = "Success"; - names[B_FAILURE_COLOR] = "Failure"; - names[B_WINDOW_TAB_COLOR] = "Window Tab"; - names[B_WINDOW_TEXT_COLOR] = "Window Tab Text"; - names[B_WINDOW_INACTIVE_TAB_COLOR] = "Inactive Window Tab"; - names[B_WINDOW_INACTIVE_TEXT_COLOR] = "Inactive Window Tab Text"; - - return names; -} - /*! \brief Assigns a value to a named color member \param string name of the color to receive the value \param value An rgb_color which is the new value of the member */ -status_t +void ColorSet::SetColor(color_which which, rgb_color value) { fColors[which] = value; - return B_OK; } -/*! - \brief Obtains the set's color member based on a specified string - \param string name of the color member to obtain - \return An RGBColor pointer or NULL if not found -*/ rgb_color -ColorSet::StringToColor(const char *string) const +ColorSet::GetColor(int32 which) { - rgb_color color; - color.set_to(0,0,0); - - if (!string) - return color; - - color_which which = StringToWhich(string); - if (which != -1) { - std::map::const_iterator it = fColors.find(which); - if (it != fColors.end()) - return it->second; - } - - return color; -} - -color_which -ColorSet::StringToWhich(const char *string) const -{ - if(!string) - return (color_which)-1; - - for (std::map::const_iterator it = sColorNames.begin(); it != sColorNames.end(); ++it) - if (it->second == string) - return it->first; - - return (color_which)-1; - -} - -rgb_color -ColorSet::AttributeToColor(int32 which) -{ return fColors[(color_which)which]; } -void -ColorSet::PrintMember(color_which which) const -{ - std::map::const_iterator it = fColors.find(which); - if (it != fColors.end()) - printf("rgb_color(%d, %d, %d, %d)", it->second.red,it->second.green,it->second.blue, - it->second.alpha); - else - printf("color (%d) not found\n", which); -} - -/*! - \brief Loads the saved system colors into a ColorSet - \param set the set to receive the system colors - \return B_OK if successful. See BFile for other error codes -*/ -status_t -ColorSet::LoadColorSet(const char *path, ColorSet *set) -{ - BFile file(path,B_READ_ONLY); - if (file.InitCheck()!=B_OK) - return file.InitCheck(); - - BMessage msg; - status_t status = msg.Unflatten(&file); - if (status != B_OK) - return status; - - set->ConvertFromMessage(&msg); - return B_OK; -} - - -/*! - \brief Saves the saved system colors into a flattened BMessage - \param set ColorSet containing the colors to save - \return B_OK if successful. See BFile for other error codes -*/ -status_t -ColorSet::SaveColorSet(const char *path, const ColorSet &set) -{ - BFile file(path, B_READ_WRITE | B_ERASE_FILE | B_CREATE_FILE); - status_t status = file.InitCheck(); - if (status != B_OK) - return status; - - BMessage msg; - set.ConvertToMessage(&msg); - - return msg.Flatten(&file); -} - Modified: haiku/trunk/src/preferences/appearance/ColorSet.h =================================================================== --- haiku/trunk/src/preferences/appearance/ColorSet.h 2008-09-06 13:00:19 UTC (rev 27346) +++ haiku/trunk/src/preferences/appearance/ColorSet.h 2008-09-06 13:57:17 UTC (rev 27347) @@ -17,6 +17,16 @@ #include +typedef struct +{ + color_which which; + const char* text; +} ColorDescription; + +const ColorDescription* get_color_description(int32 index); +int32 color_description_count(void); + + /*! \class ColorSet ColorSet.h \brief Encapsulates GUI system colors @@ -27,33 +37,22 @@ ColorSet(const ColorSet &cs); ColorSet & operator=(const ColorSet &cs); - void SetColors(const ColorSet &cs); - void PrintToStream(void) const; - - bool ConvertToMessage(BMessage *msg) const; - bool ConvertFromMessage(const BMessage *msg); - - bool IsDefaultable(void); - - rgb_color StringToColor(const char *string) const; - rgb_color AttributeToColor(int32 which); - - status_t SetColor(color_which which, rgb_color value); - - static status_t LoadColorSet(const char *path, ColorSet *set); - static status_t SaveColorSet(const char *path, const ColorSet &set); + rgb_color GetColor(int32 which); + void SetColor(color_which which, rgb_color value); static ColorSet DefaultColorSet(void); - static std::map DefaultColorNames(void); inline bool operator==(const ColorSet &other) { - return (fColors == other.fColors); + return fColors == other.fColors; } + inline bool operator!=(const ColorSet &other) + { + return fColors != other.fColors; + } + private: - color_which StringToWhich(const char *string) const; - void PrintMember(color_which which) const; std::map fColors; }; Modified: haiku/trunk/src/preferences/appearance/ColorWhichItem.cpp =================================================================== --- haiku/trunk/src/preferences/appearance/ColorWhichItem.cpp 2008-09-06 13:00:19 UTC (rev 27346) +++ haiku/trunk/src/preferences/appearance/ColorWhichItem.cpp 2008-09-06 13:57:17 UTC (rev 27347) @@ -9,160 +9,15 @@ #include "ColorWhichItem.h" #include -ColorWhichItem::ColorWhichItem(color_which which) - : BStringItem(NULL,0,false) +ColorWhichItem::ColorWhichItem(const char* text, color_which which) + : BStringItem(text, 0, false) + , colorWhich(which) { - SetAttribute(which); } -ColorWhichItem::~ColorWhichItem(void) -{ - // Empty, but exists for just-in-case -} - -void -ColorWhichItem::SetAttribute(color_which which) -{ - switch(which) { - // cases not existing in R5 which exist in OpenBeOS - case B_PANEL_BACKGROUND_COLOR: { - attribute=which; - SetText("Panel Background"); - break; - } - case B_PANEL_TEXT_COLOR: { - attribute=which; - SetText("Panel Text"); - break; - } - case B_DOCUMENT_BACKGROUND_COLOR: { - attribute=which; - SetText("Document Background"); - break; - } - case B_DOCUMENT_TEXT_COLOR: { - attribute=which; - SetText("Document Text"); - break; - } - case B_CONTROL_BACKGROUND_COLOR: { - attribute=which; - SetText("Control Background"); - break; - } - case B_CONTROL_TEXT_COLOR: { - attribute=which; - SetText("Control Text"); - break; - } - case B_CONTROL_BORDER_COLOR: { - attribute=which; - SetText("Control Border"); - break; - } - case B_CONTROL_HIGHLIGHT_COLOR: { - attribute=which; - SetText("Control Highlight"); - break; - } - case B_TOOLTIP_BACKGROUND_COLOR: { - attribute=which; - SetText("Tooltip Background"); - break; - } - case B_TOOLTIP_TEXT_COLOR: { - attribute=which; - SetText("Tooltip Text"); - break; - } - case B_MENU_BACKGROUND_COLOR: { - attribute=which; - SetText("Menu Background"); - break; - } - case B_MENU_SELECTION_BACKGROUND_COLOR: { - attribute=which; - SetText("Selected Menu Item Background"); - break; - } - case B_MENU_ITEM_TEXT_COLOR: { - attribute=which; - SetText("Menu Item Text"); - break; - } - case B_MENU_SELECTED_ITEM_TEXT_COLOR: { - attribute=which; - SetText("Selected Menu Item Text"); - break; - } - case B_MENU_SELECTED_BORDER_COLOR: { - attribute=which; - SetText("Selected Menu Item Border"); - break; - } - case B_NAVIGATION_BASE_COLOR: { - attribute=which; - SetText("Navigation Base"); - break; - } - case B_NAVIGATION_PULSE_COLOR: { - attribute=which; - SetText("Navigation Pulse"); - break; - } - case B_SUCCESS_COLOR: { - attribute=which; - SetText("Success"); - break; - } - case B_FAILURE_COLOR: { - attribute=which; - SetText("Failure"); - break; - } - case B_SHINE_COLOR: { - attribute=which; - SetText("Shine"); - break; - } - case B_SHADOW_COLOR: { - attribute=which; - SetText("Shadow"); - break; - } - case B_WINDOW_TAB_COLOR: { - attribute=which; - SetText("Window Tab"); - break; - } - case B_WINDOW_TEXT_COLOR: { - attribute=which; - SetText("Window Text"); - break; - } - case B_WINDOW_INACTIVE_TAB_COLOR: { - attribute=which; - SetText("Inactive Window Tab"); - break; - } - case B_WINDOW_INACTIVE_TEXT_COLOR: { - attribute=which; - SetText("Inactive Window Tab Text"); - break; - } - default: { - printf("unknown code '%c%c%c%c'\n",(char)((which & 0xFF000000) >> 24), - (char)((which & 0x00FF0000) >> 16), - (char)((which & 0x0000FF00) >> 8), - (char)((which & 0x000000FF)) ); - break; - } - } -} - color_which -ColorWhichItem::GetAttribute(void) +ColorWhichItem::ColorWhich(void) { - return attribute; + return colorWhich; } Modified: haiku/trunk/src/preferences/appearance/ColorWhichItem.h =================================================================== --- haiku/trunk/src/preferences/appearance/ColorWhichItem.h 2008-09-06 13:00:19 UTC (rev 27346) +++ haiku/trunk/src/preferences/appearance/ColorWhichItem.h 2008-09-06 13:57:17 UTC (rev 27347) @@ -15,12 +15,12 @@ class ColorWhichItem : public BStringItem { public: - ColorWhichItem(color_which which); - ~ColorWhichItem(void); - void SetAttribute(color_which which); - color_which GetAttribute(void); + ColorWhichItem(const char* text, color_which which); + + color_which ColorWhich(void); + private: - color_which attribute; + color_which colorWhich; }; #endif From michael.w.pfeiffer at gmail.com Sat Sep 6 16:02:09 2008 From: michael.w.pfeiffer at gmail.com (Michael Pfeiffer) Date: Sat, 6 Sep 2008 16:02:09 +0200 Subject: [Haiku-commits] r27344 - haiku/trunk/src/preferences/appearance In-Reply-To: References: <200809060913.m869DIuC032708@sheep.berlios.de> Message-ID: <98A5B194-D6E8-4617-8E5F-84176C6B589A@gmail.com> Am 06.09.2008 um 11:24 schrieb Michael Pfeiffer: > > Am 06.09.2008 um 11:13 schrieb laplace at mail.berlios.de: > >> * Moved ColorWell infront of ColorPicker. It was hidden behinde the >> attribute list. > > While fixing that I discovered two more bugs (will file bug reports > on request): > * The Appearance preflet does not remember color changes. > For example you change the color of one attribute then select another > attribute and then select the first attribute. > Its color seems to be reset to its initial value. Fixed in r27347. - Michael From korli at mail.berlios.de Sat Sep 6 16:31:31 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Sat, 6 Sep 2008 16:31:31 +0200 Subject: [Haiku-commits] r27348 - in haiku/trunk: headers/posix src/system/libroot/posix/glibc/arch/generic src/system/libroot/posix/glibc/arch/m68k src/system/libroot/posix/glibc/arch/ppc src/system/libroot/posix/glibc/arch/x86 src/system/libroot/posix/glibc/include/arch/m68k/bits Message-ID: <200809061431.m86EVV2o012775@sheep.berlios.de> Author: korli Date: 2008-09-06 16:31:28 +0200 (Sat, 06 Sep 2008) New Revision: 27348 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27348&view=rev Added: haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_nextafterf.c haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_remquo.c haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_remquof.c haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_remquol.c haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_nearbyint.c haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_nearbyintf.c haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_nearbyintl.c haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_nextafterl.c haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_remquo.c haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_remquof.c haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_remquol.c haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_scalbln.c haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_scalblnf.c haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_scalblnl.c haiku/trunk/src/system/libroot/posix/glibc/arch/ppc/s_nearbyint.c haiku/trunk/src/system/libroot/posix/glibc/arch/ppc/s_nearbyintf.c haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_nearbyint.S haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_nearbyintf.S haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_nearbyintl.S haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_nextafterl.c haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_remquo.S haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_remquof.S haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_remquol.S haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_scalblnl.c Removed: haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_nextafterf.c Modified: haiku/trunk/headers/posix/math.h haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/Jamfile haiku/trunk/src/system/libroot/posix/glibc/arch/ppc/Jamfile haiku/trunk/src/system/libroot/posix/glibc/arch/x86/Jamfile haiku/trunk/src/system/libroot/posix/glibc/include/arch/m68k/bits/mathdef.h Log: added more posix functions Modified: haiku/trunk/headers/posix/math.h =================================================================== --- haiku/trunk/headers/posix/math.h 2008-09-06 13:57:17 UTC (rev 27347) +++ haiku/trunk/headers/posix/math.h 2008-09-06 14:31:28 UTC (rev 27348) @@ -106,7 +106,9 @@ extern float logf(float x); extern long lroundf(float x); extern float modff(float x, float *y); +extern float nearbyintf(float x); extern float powf(float x, float y); +extern float remquof(float x, float y, int *quo); extern float roundf(float x); extern float sinf(float x); extern float sinhf(float x); @@ -137,7 +139,9 @@ extern double log10(double x); extern long lround(double x); extern double modf(double x, double *y); +extern double nearbyint(double x); extern double pow(double x, double y); +extern double remquo(double x, double y, int *quo); extern double round(double x); extern double sin(double x); extern double sinh(double x); @@ -154,8 +158,10 @@ extern long double atanhl(long double x); extern long double atan2l(long double y, long double x); extern long double lgammal(long double x); +extern long double nearbyintl(long double x); extern long double roundl(long double x); extern long lroundl(long double x); +extern long double remquol(long double x, long double y, int *quo); /* some BSD non-ANSI or POSIX math functions */ extern double cbrt(double x); @@ -189,6 +195,7 @@ extern int isnanf(float value); extern double significand(double x); extern double copysign(double x, double y); +extern double scalbln(double x, long n); extern double scalbn(double x, int y); extern double drem(double x, double y); extern int isnan(double x); @@ -211,7 +218,9 @@ extern float scalbnf(float x, int n); extern int ilogbf(float x); -extern long double remainderl(long double x, long double y); +extern long double remainderl(long double x, long double y); +extern long double scalbnl(long double x, int n); +extern long double scalblnl(long double x, long n); /* prototypes for functions used in the macros below */ extern int __fpclassifyf(float value); Copied: haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_nextafterf.c (from rev 27345, haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_nextafterf.c) Added: haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_remquo.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_remquo.c 2008-09-06 13:57:17 UTC (rev 27347) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_remquo.c 2008-09-06 14:31:28 UTC (rev 27348) @@ -0,0 +1,113 @@ +/* Compute remainder and a congruent to the quotient. + Copyright (C) 1997 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper , 1997. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include + +#include "math_private.h" + + +static const double zero = 0.0; + + +double +__remquo (double x, double y, int *quo) +{ + int32_t hx,hy; + u_int32_t sx,lx,ly; + int cquo, qs; + + EXTRACT_WORDS (hx, lx, x); + EXTRACT_WORDS (hy, ly, y); + sx = hx & 0x80000000; + qs = sx ^ (hy & 0x80000000); + hy &= 0x7fffffff; + hx &= 0x7fffffff; + + /* Purge off exception values. */ + if ((hy | ly) == 0) + return (x * y) / (x * y); /* y = 0 */ + if ((hx >= 0x7ff00000) /* x not finite */ + || ((hy >= 0x7ff00000) /* p is NaN */ + && (((hy - 0x7ff00000) | ly) != 0))) + return (x * y) / (x * y); + + if (hy <= 0x7fbfffff) + x = __ieee754_fmod (x, 8 * y); /* now x < 8y */ + + if (((hx - hy) | (lx - ly)) == 0) + { + *quo = qs ? -1 : 1; + return zero * x; + } + + x = fabs (x); + y = fabs (y); + cquo = 0; + + if (x >= 4 * y) + { + x -= 4 * y; + cquo += 4; + } + if (x >= 2 * y) + { + x -= 2 * y; + cquo += 2; + } + + if (hy < 0x00200000) + { + if (x + x > y) + { + x -= y; + ++cquo; + if (x + x >= y) + { + x -= y; + ++cquo; + } + } + } + else + { + double y_half = 0.5 * y; + if (x > y_half) + { + x -= y; + ++cquo; + if (x >= y_half) + { + x -= y; + ++cquo; + } + } + } + + *quo = qs ? -cquo : cquo; + + if (sx) + x = -x; + return x; +} +weak_alias (__remquo, remquo) +#ifdef NO_LONG_DOUBLE +strong_alias (__remquo, __remquol) +weak_alias (__remquo, remquol) +#endif Added: haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_remquof.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_remquof.c 2008-09-06 13:57:17 UTC (rev 27347) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_remquof.c 2008-09-06 14:31:28 UTC (rev 27348) @@ -0,0 +1,108 @@ +/* Compute remainder and a congruent to the quotient. + Copyright (C) 1997 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper , 1997. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include + +#include "math_private.h" + + +static const float zero = 0.0; + + +float +__remquof (float x, float y, int *quo) +{ + int32_t hx,hy; + u_int32_t sx; + int cquo, qs; + + GET_FLOAT_WORD (hx, x); + GET_FLOAT_WORD (hy, y); + sx = hx & 0x80000000; + qs = sx ^ (hy & 0x80000000); + hy &= 0x7fffffff; + hx &= 0x7fffffff; + + /* Purge off exception values. */ + if (hy == 0) + return (x * y) / (x * y); /* y = 0 */ + if ((hx >= 0x7f800000) /* x not finite */ + || (hy > 0x7f800000)) /* y is NaN */ + return (x * y) / (x * y); + + if (hy <= 0x7dffffff) + x = __ieee754_fmodf (x, 8 * y); /* now x < 8y */ + + if ((hx - hy) == 0) + { + *quo = qs ? -1 : 1; + return zero * x; + } + + x = fabsf (x); + y = fabsf (y); + cquo = 0; + + if (x >= 4 * y) + { + x -= 4 * y; + cquo += 4; + } + if (x >= 2 * y) + { + x -= 2 * y; + cquo += 2; + } + + if (hy < 0x01000000) + { + if (x + x > y) + { + x -= y; + ++cquo; + if (x + x >= y) + { + x -= y; + ++cquo; + } + } + } + else + { + float y_half = 0.5 * y; + if (x > y_half) + { + x -= y; + ++cquo; + if (x >= y_half) + { + x -= y; + ++cquo; + } + } + } + + *quo = qs ? -cquo : cquo; + + if (sx) + x = -x; + return x; +} +weak_alias (__remquof, remquof) Added: haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_remquol.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_remquol.c 2008-09-06 13:57:17 UTC (rev 27347) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_remquol.c 2008-09-06 14:31:28 UTC (rev 27348) @@ -0,0 +1,109 @@ +/* Compute remainder and a congruent to the quotient. + Copyright (C) 1997 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper , 1997. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include + +#include "math_private.h" + + +static const long double zero = 0.0; + + +long double +__remquol (long double x, long double p, int *quo) +{ + int32_t ex,ep,hx,hp; + u_int32_t sx,lx,lp; + int cquo,qs; + + GET_LDOUBLE_WORDS (ex, hx, lx, x); + GET_LDOUBLE_WORDS (ep, hp, lp, p); + sx = ex & 0x8000; + qs = (sx ^ (ep & 0x8000)) >> 15; + ep &= 0x7fff; + ex &= 0x7fff; + + /* Purge off exception values. */ + if ((ep | hp | lp) == 0) + return (x * p) / (x * p); /* p = 0 */ + if ((ex == 0x7fff) /* x not finite */ + || ((ep == 0x7fff) /* p is NaN */ + && ((hp | lp) != 0))) + return (x * p) / (x * p); + + if (ep <= 0x7ffb) + x = __ieee754_fmodl (x, 8 * p); /* now x < 8p */ + + if (((ex - ep) | (hx - hp) | (lx - lp)) == 0) + { + *quo = qs ? -1 : 1; + return zero * x; + } + + x = fabsl (x); + p = fabsl (p); + cquo = 0; + + if (x >= 4 * p) + { + x -= 4 * p; + cquo += 4; + } + if (x >= 2 * p) + { + x -= 2 * p; + cquo += 2; + } + + if (ep < 0x0002) + { + if (x + x > p) + { + x -= p; + ++cquo; + if (x + x >= p) + { + x -= p; + ++cquo; + } + } + } + else + { + long double p_half = 0.5 * p; + if (x > p_half) + { + x -= p; + ++cquo; + if (x >= p_half) + { + x -= p; + ++cquo; + } + } + } + + *quo = qs ? -cquo : cquo; + + if (sx) + x = -x; + return x; +} +weak_alias (__remquol, remquol) Modified: haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/Jamfile =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/Jamfile 2008-09-06 13:57:17 UTC (rev 27347) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/Jamfile 2008-09-06 14:31:28 UTC (rev 27348) @@ -82,6 +82,7 @@ s_lround.c s_lroundf.c s_modf.c s_modff.c # s_modfl.c s_nan.c s_nanf.c # s_nanl.c + s_nextafter.c s_nextafterf.c # s_nextafterl.c s_round.c s_roundf.c # s_roundl.c s_scalbn.c s_scalbnf.c # s_scalbnl.c s_signbit.c s_signbitf.c # s_signbitl.c @@ -143,7 +144,10 @@ # s_fabs.S s_fabsf.S # s_fabsl.S # s_fpclassifyl.c # s_isnan.c s_isnanf.S + s_nearbyint.c s_nearbyintf.c # s_nearbyintl.c + s_remquo.c s_remquof.c # s_remquol.c s_rint.c s_rintf.c # s_rintl.c + s_scalbln.c s_scalblnf.c # s_scalblnl.c # t_sqrt.c # w_sqrt.c w_sqrtf.c # w_sqrtl.c ; Added: haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_nearbyint.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_nearbyint.c 2008-09-06 13:57:17 UTC (rev 27347) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_nearbyint.c 2008-09-06 14:31:28 UTC (rev 27348) @@ -0,0 +1,2 @@ +#define FUNC nearbyint +#include Added: haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_nearbyintf.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_nearbyintf.c 2008-09-06 13:57:17 UTC (rev 27347) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_nearbyintf.c 2008-09-06 14:31:28 UTC (rev 27348) @@ -0,0 +1,2 @@ +#define FUNC nearbyintf +#include Added: haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_nearbyintl.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_nearbyintl.c 2008-09-06 13:57:17 UTC (rev 27347) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_nearbyintl.c 2008-09-06 14:31:28 UTC (rev 27348) @@ -0,0 +1,2 @@ +#define FUNC nearbyintl +#include Added: haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_nextafterl.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_nextafterl.c 2008-09-06 13:57:17 UTC (rev 27347) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_nextafterl.c 2008-09-06 14:31:28 UTC (rev 27348) @@ -0,0 +1,109 @@ +/* s_nextafterl.c -- long double version of s_nextafter.c. + * Conversion to long double by Ulrich Drepper, + * Cygnus Support, drepper at cygnus.com. + * Fixed for m68k by Andreas Schwab . + */ + +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#if defined(LIBM_SCCS) && !defined(lint) +static char rcsid[] = "$NetBSD: $"; +#endif + +/* IEEE functions + * nextafterl(x,y) + * return the next machine floating-point number of x in the + * direction toward y. + * Special cases: + */ + +#include "math.h" +#include "math_private.h" + +#ifdef __STDC__ + long double __nextafterl(long double x, long double y) +#else + long double __nextafterl(x,y) + long double x,y; +#endif +{ + int32_t ix,iy,esx,esy; + u_int32_t hx,hy,lx,ly; + + GET_LDOUBLE_WORDS(esx,hx,lx,x); + GET_LDOUBLE_WORDS(esy,hy,ly,y); + ix = esx&0x7fff; /* |x| */ + iy = esy&0x7fff; /* |y| */ + + if(((ix==0x7fff)&&((hx&0x7fffffff)|lx)!=0) || /* x is nan */ + ((iy==0x7fff)&&((hy&0x7fffffff)|ly)!=0)) /* y is nan */ + return x+y; + if(x==y) return y; /* x=y, return y */ + if((ix|hx|lx)==0) { /* x == 0 */ + SET_LDOUBLE_WORDS(x,esy&0x8000,0,1);/* return +-minsubnormal */ + y = x*x; + if(y==x) return y; else return x; /* raise underflow flag */ + } + if(esx>=0) { /* x > 0 */ + if(esx>esy||((esx==esy) && (hx>hy||((hx==hy)&&(lx>ly))))) { + /* x > y, x -= ulp */ + if(lx==0) { + if (ix != 0 && hx == 0x80000000) hx = 0; + if (hx==0) esx -= 1; + hx -= 1; + } + lx -= 1; + } else { /* x < y, x += ulp */ + lx += 1; + if(lx==0) { + hx += 1; + if (hx==0) { + hx = 0x80000000; + esx += 1; + } + } + } + } else { /* x < 0 */ + if(esy>=0||esx>esy||((esx==esy) && (hx>hy||((hx==hy)&&(lx>ly))))){ + /* x < y, x -= ulp */ + if(lx==0) { + if (ix != 0 && hx == 0x80000000) hx = 0; + if (hx==0) esx -= 1; + hx -= 1; + } + lx -= 1; + } else { /* x > y, x += ulp */ + lx += 1; + if(lx==0) { + hx += 1; + if (hx==0) { + hx = 0x80000000; + esx += 1; + } + } + } + } + esy = esx&0x7fff; + if(esy==0x7fff) return x+x; /* overflow */ + if(esy==0 && (hx & 0x80000000) == 0) { /* underflow */ + y = x*x; + if(y!=x) { /* raise underflow flag */ + SET_LDOUBLE_WORDS(y,esx,hx,lx); + return y; + } + } + SET_LDOUBLE_WORDS(x,esx,hx,lx); + return x; +} +weak_alias (__nextafterl, nextafterl) +strong_alias (__nextafterl, __nexttowardl) +weak_alias (__nextafterl, nexttowardl) Added: haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_remquo.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_remquo.c 2008-09-06 13:57:17 UTC (rev 27347) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_remquo.c 2008-09-06 14:31:28 UTC (rev 27348) @@ -0,0 +1,48 @@ +/* Compute remainder and a congruent to the quotient. m68k fpu version + Copyright (C) 1997 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Andreas Schwab + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include + +#ifndef SUFF +#define SUFF +#endif +#ifndef float_type +#define float_type double +#endif + +#define CONCATX(a,b) __CONCAT(a,b) +#define s(name) CONCATX(name,SUFF) + +float_type +s(__remquo) (float_type x, float_type y, int *quo) +{ + float_type result; + int cquo, fpsr; + + __asm ("frem%.x %2,%0\n\tfmove%.l %/fpsr,%1" + : "=f" (result), "=dm" (fpsr) : "f" (y), "0" (x)); + cquo = (fpsr >> 16) & 0x7f; + if (fpsr & (1 << 23)) + cquo = -cquo; + *quo = cquo; + return result; +} +#define weak_aliasx(a,b) weak_alias(a,b) +weak_aliasx (s(__remquo), s(remquo)) Added: haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_remquof.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_remquof.c 2008-09-06 13:57:17 UTC (rev 27347) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_remquof.c 2008-09-06 14:31:28 UTC (rev 27348) @@ -0,0 +1,3 @@ +#define SUFF f +#define float_type float +#include Added: haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_remquol.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_remquol.c 2008-09-06 13:57:17 UTC (rev 27347) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_remquol.c 2008-09-06 14:31:28 UTC (rev 27348) @@ -0,0 +1,3 @@ +#define SUFF l +#define float_type long double +#include Added: haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_scalbln.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_scalbln.c 2008-09-06 13:57:17 UTC (rev 27347) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_scalbln.c 2008-09-06 14:31:28 UTC (rev 27348) @@ -0,0 +1,2 @@ +/* Nothing to do. This function is the same as scalbn. So we define an + alias. */ Added: haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_scalblnf.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_scalblnf.c 2008-09-06 13:57:17 UTC (rev 27347) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_scalblnf.c 2008-09-06 14:31:28 UTC (rev 27348) @@ -0,0 +1,2 @@ +/* Nothing to do. This function is the same as scalbnf. So we define an + alias. */ Added: haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_scalblnl.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_scalblnl.c 2008-09-06 13:57:17 UTC (rev 27347) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/s_scalblnl.c 2008-09-06 14:31:28 UTC (rev 27348) @@ -0,0 +1,2 @@ +/* Nothing to do. This function is the same as scalbnl. So we define an + alias. */ Modified: haiku/trunk/src/system/libroot/posix/glibc/arch/ppc/Jamfile =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/ppc/Jamfile 2008-09-06 13:57:17 UTC (rev 27347) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/ppc/Jamfile 2008-09-06 14:31:28 UTC (rev 27348) @@ -112,6 +112,7 @@ w_remainder.c w_remainderf.c # w_remainderl.c w_scalb.c w_scalbf.c # w_scalbl.c w_sinh.c w_sinhf.c # w_sinhl.c + w_tgamma.c w_tgammaf.c w_tgammal.c ; MergeObject posix_gnu_arch_$(TARGET_ARCH)_generic.o : Added: haiku/trunk/src/system/libroot/posix/glibc/arch/ppc/s_nearbyint.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/ppc/s_nearbyint.c 2008-09-06 13:57:17 UTC (rev 27347) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/ppc/s_nearbyint.c 2008-09-06 14:31:28 UTC (rev 27348) @@ -0,0 +1,98 @@ +/* Adapted for use as nearbyint by Ulrich Drepper . */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#if defined(LIBM_SCCS) && !defined(lint) +static char rcsid[] = "$NetBSD: s_rint.c,v 1.8 1995/05/10 20:48:04 jtc Exp $"; +#endif + +/* + * rint(x) + * Return x rounded to integral value according to the prevailing + * rounding mode. + * Method: + * Using floating addition. + * Exception: + * Inexact flag raised if x not equal to rint(x). + */ + +#include +#include "math.h" +#include "math_private.h" + +#ifdef __STDC__ +static const double +#else +static double +#endif +TWO52[2]={ + 4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */ + -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */ +}; + +#ifdef __STDC__ + double __nearbyint(double x) +#else + double __nearbyint(x) + double x; +#endif +{ + fenv_t env; + int32_t i0,j0,sx; + u_int32_t i,i1; + double w,t; + EXTRACT_WORDS(i0,i1,x); + sx = (i0>>31)&1; + j0 = ((i0>>20)&0x7ff)-0x3ff; + if(j0<20) { + if(j0<0) { + if(((i0&0x7fffffff)|i1)==0) return x; + i1 |= (i0&0x0fffff); + i0 &= 0xfffe0000; + i0 |= ((i1|-i1)>>12)&0x80000; + SET_HIGH_WORD(x,i0); + feholdexcept (&env); + w = TWO52[sx]+x; + t = w-TWO52[sx]; + fesetenv (&env); + GET_HIGH_WORD(i0,t); + SET_HIGH_WORD(t,(i0&0x7fffffff)|(sx<<31)); + return t; + } else { + i = (0x000fffff)>>j0; + if(((i0&i)|i1)==0) return x; /* x is integral */ + i>>=1; + if(((i0&i)|i1)!=0) { + if(j0==19) i1 = 0x40000000; else + i0 = (i0&(~i))|((0x20000)>>j0); + } + } + } else if (j0>51) { + if(j0==0x400) return x+x; /* inf or NaN */ + else return x; /* x is integral */ + } else { + i = ((u_int32_t)(0xffffffff))>>(j0-20); + if((i1&i)==0) return x; /* x is integral */ + i>>=1; + if((i1&i)!=0) i1 = (i1&(~i))|((0x40000000)>>(j0-20)); + } + INSERT_WORDS(x,i0,i1); + feholdexcept (&env); + w = TWO52[sx]+x; + t = w-TWO52[sx]; + fesetenv (&env); + return t; +} +weak_alias (__nearbyint, nearbyint) +#ifdef NO_LONG_DOUBLE +strong_alias (__nearbyint, __nearbyintl) +weak_alias (__nearbyint, nearbyintl) +#endif Added: haiku/trunk/src/system/libroot/posix/glibc/arch/ppc/s_nearbyintf.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/ppc/s_nearbyintf.c 2008-09-06 13:57:17 UTC (rev 27347) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/ppc/s_nearbyintf.c 2008-09-06 14:31:28 UTC (rev 27348) @@ -0,0 +1,77 @@ +/* s_rintf.c -- float version of s_rint.c. + * Conversion to float by Ian Lance Taylor, Cygnus Support, ian at cygnus.com. + */ +/* Adapted for use as nearbyint by Ulrich Drepper . */ + +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + + +#include +#include "math.h" +#include "math_private.h" + +#ifdef __STDC__ +static const float +#else +static float +#endif +TWO23[2]={ + 8.3886080000e+06, /* 0x4b000000 */ + -8.3886080000e+06, /* 0xcb000000 */ +}; + +#ifdef __STDC__ + float __nearbyintf(float x) +#else + float __nearbyintf(x) + float x; +#endif +{ + fenv_t env; + int32_t i0,j0,sx; + u_int32_t i,i1; + float w,t; + GET_FLOAT_WORD(i0,x); + sx = (i0>>31)&1; + j0 = ((i0>>23)&0xff)-0x7f; + if(j0<23) { + if(j0<0) { + if((i0&0x7fffffff)==0) return x; + i1 = (i0&0x07fffff); + i0 &= 0xfff00000; + i0 |= ((i1|-i1)>>9)&0x400000; + SET_FLOAT_WORD(x,i0); + feholdexcept (&env); + w = TWO23[sx]+x; + t = w-TWO23[sx]; + fesetenv (&env); + GET_FLOAT_WORD(i0,t); + SET_FLOAT_WORD(t,(i0&0x7fffffff)|(sx<<31)); + return t; + } else { + i = (0x007fffff)>>j0; + if((i0&i)==0) return x; /* x is integral */ + i>>=1; + if((i0&i)!=0) i0 = (i0&(~i))|((0x100000)>>j0); + } + } else { + if(j0==0x80) return x+x; /* inf or NaN */ + else return x; /* x is integral */ + } + SET_FLOAT_WORD(x,i0); + feholdexcept (&env); + w = TWO23[sx]+x; + t = w-TWO23[sx]; + fesetenv (&env); + return t; +} +weak_alias (__nearbyintf, nearbyintf) Modified: haiku/trunk/src/system/libroot/posix/glibc/arch/x86/Jamfile =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/x86/Jamfile 2008-09-06 13:57:17 UTC (rev 27347) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/x86/Jamfile 2008-09-06 14:31:28 UTC (rev 27348) @@ -62,7 +62,7 @@ s_matherr.c s_modf.c s_modff.c # s_modfl.c s_nan.c s_nanf.c - s_nextafter.c + s_nextafter.c s_nextafterf.c s_signbit.c s_signbitf.c s_signbitl.c s_round.c s_roundf.c s_roundl.c s_signgam.c @@ -156,8 +156,11 @@ s_log1p.S s_log1pf.S s_log1pl.S s_logb.S s_logbf.S s_logbl.c s_lrint.S s_lrintf.S s_lrintl.S - s_nextafterf.c + s_nearbyint.S s_nearbyintf.S s_nearbyintl.S + s_nextafterl.c + s_remquo.S s_remquof.S s_remquol.S s_rint.S s_rintf.S s_rintl.c + s_scalbln.c s_scalblnf.c s_scalblnl.c s_scalbn.S s_scalbnf.S s_scalbnl.S s_significand.S s_significandf.S s_sin.S s_sinf.S s_sinl.S Added: haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_nearbyint.S =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_nearbyint.S 2008-09-06 13:57:17 UTC (rev 27347) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_nearbyint.S 2008-09-06 14:31:28 UTC (rev 27348) @@ -0,0 +1,25 @@ +/* + * Written by J.T. Conklin . + * Public domain. + */ +/* Adapted for use as nearbyint by Ulrich Drepper . */ + +#include + +ENTRY(__nearbyint) + fldl 4(%esp) + pushl %eax + pushl %ecx + fnstcw (%esp) + movl (%esp), %eax + orl $0x20, %eax + movl %eax, 4(%esp) + fldcw 4(%esp) + frndint + fclex + fldcw (%esp) + popl %ecx + popl %eax + ret +END (__nearbyint) +weak_alias (__nearbyint, nearbyint) Added: haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_nearbyintf.S =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_nearbyintf.S 2008-09-06 13:57:17 UTC (rev 27347) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_nearbyintf.S 2008-09-06 14:31:28 UTC (rev 27348) @@ -0,0 +1,25 @@ +/* + * Written by J.T. Conklin . + * Public domain. + */ +/* Adapted for use as nearbyint by Ulrich Drepper . */ + +#include + +ENTRY(__nearbyintf) + flds 4(%esp) + pushl %eax + pushl %ecx + fnstcw (%esp) + movl (%esp), %eax + orl $0x20, %eax + movl %eax, 4(%esp) + fldcw 4(%esp) + frndint + fclex + fldcw (%esp) + popl %ecx + popl %eax + ret +END (__nearbyintf) +weak_alias (__nearbyintf, nearbyintf) Added: haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_nearbyintl.S =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_nearbyintl.S 2008-09-06 13:57:17 UTC (rev 27347) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_nearbyintl.S 2008-09-06 14:31:28 UTC (rev 27348) @@ -0,0 +1,25 @@ +/* + * Written by J.T. Conklin . + * Public domain. + */ +/* Adapted for use as nearbyint by Ulrich Drepper . */ + +#include + +ENTRY(__nearbyintl) + fldt 4(%esp) + pushl %eax + pushl %ecx + fnstcw (%esp) + movl (%esp), %eax + orl $0x20, %eax + movl %eax, 4(%esp) + fldcw 4(%esp) + frndint + fclex + fldcw (%esp) + popl %ecx + popl %eax + ret +END (__nearbyintl) +weak_alias (__nearbyintl, nearbyintl) Deleted: haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_nextafterf.c Added: haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_nextafterl.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_nextafterl.c 2008-09-06 13:57:17 UTC (rev 27347) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_nextafterl.c 2008-09-06 14:31:28 UTC (rev 27348) @@ -0,0 +1,124 @@ +/* s_nextafterl.c -- long double version of s_nextafter.c. + * Special version for i387. + * Conversion to long double by Ulrich Drepper, + * Cygnus Support, drepper at cygnus.com. + */ + +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. [... truncated: 307 lines follow ...] From revol at free.fr Sat Sep 6 16:38:28 2008 From: revol at free.fr (=?windows-1252?q?Fran=E7ois?= Revol) Date: Sat, 06 Sep 2008 16:38:28 +0200 CEST Subject: [Haiku-commits] =?windows-1252?q?r27348_-_in_haiku/trunk=3A_heade?= =?windows-1252?q?rs/posix_src/system/libroot/posix/glibc/arch/generic_src?= =?windows-1252?q?/system/libroot/posix/glibc/arch/m68k_src/system/libroot?= =?windows-1252?q?/posix/glibc/arch/ppc_src/system/libroot/posix/glibc/arc?= =?windows-1252?q?h/x86_src/system/libroot/posix/glibc/include/arch/m68k/b?= =?windows-1252?q?its?= In-Reply-To: <200809061431.m86EVV2o012775@sheep.berlios.de> Message-ID: <749658620-BeMail@laptop> > Modified: > haiku/trunk/headers/posix/math.h > haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/Jamfile > haiku/trunk/src/system/libroot/posix/glibc/arch/ppc/Jamfile > haiku/trunk/src/system/libroot/posix/glibc/arch/x86/Jamfile > haiku/trunk/src/system/libroot/posix/glibc/include/arch/m68k/bits/ > mathdef.h > Log: > added more posix functions > Cool, no idea what they do but thanks for caring about ppc & m68k :) Fran?ois. From korli at mail.berlios.de Sat Sep 6 17:00:33 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Sat, 6 Sep 2008 17:00:33 +0200 Subject: [Haiku-commits] r27349 - in haiku/trunk: headers/posix src/system/libroot/posix/glibc/arch/generic src/system/libroot/posix/glibc/arch/m68k src/system/libroot/posix/glibc/arch/ppc src/system/libroot/posix/glibc/arch/x86 Message-ID: <200809061500.m86F0Xgr014289@sheep.berlios.de> Author: korli Date: 2008-09-06 17:00:33 +0200 (Sat, 06 Sep 2008) New Revision: 27349 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27349&view=rev Added: haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_nexttoward.c haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_nexttowardf.c haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_nexttowardl.c haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_nexttoward.c haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_nexttowardf.c Modified: haiku/trunk/headers/posix/math.h haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/Jamfile haiku/trunk/src/system/libroot/posix/glibc/arch/ppc/Jamfile haiku/trunk/src/system/libroot/posix/glibc/arch/x86/Jamfile Log: added nexttoward() Modified: haiku/trunk/headers/posix/math.h =================================================================== --- haiku/trunk/headers/posix/math.h 2008-09-06 14:31:28 UTC (rev 27348) +++ haiku/trunk/headers/posix/math.h 2008-09-06 15:00:33 UTC (rev 27349) @@ -178,6 +178,7 @@ extern double log1p(double x); extern double logb(double x); extern double nextafter(double x, double y); +extern double nexttoward(double x, long double y); extern double remainder(double x, double y); extern double rint(double x); extern double scalb (double x, double y); @@ -213,12 +214,16 @@ extern float lgammaf_r(float x, int *y); extern float rintf(float x); extern float nextafterf(float x, float y); +extern float nexttowardf(float x, long double y); extern float remainderf(float x, float y); extern float scalbf(float x, float n); extern float scalbnf(float x, int n); extern int ilogbf(float x); +extern long double nextafterl(long double x, long double y); +extern long double nexttowardl(long double x, long double y); extern long double remainderl(long double x, long double y); +extern long double rintl(long double x); extern long double scalbnl(long double x, int n); extern long double scalblnl(long double x, long n); Added: haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_nexttoward.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_nexttoward.c 2008-09-06 14:31:28 UTC (rev 27348) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_nexttoward.c 2008-09-06 15:00:33 UTC (rev 27349) @@ -0,0 +1 @@ +/* This function is the same as nextafter so we use an alias there. */ Added: haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_nexttowardf.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_nexttowardf.c 2008-09-06 14:31:28 UTC (rev 27348) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_nexttowardf.c 2008-09-06 15:00:33 UTC (rev 27349) @@ -0,0 +1,78 @@ +/* s_nexttowardf.c -- float version of s_nextafter.c. + * Conversion to float by Ian Lance Taylor, Cygnus Support, ian at cygnus.com. + */ + +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#if defined(LIBM_SCCS) && !defined(lint) +static char rcsid[] = "$NetBSD: $"; +#endif + +#include "math.h" +#include "math_private.h" + +#ifdef __STDC__ + float __nexttowardf(float x, long double y) +#else + float __nexttowardf(x,y) + float x; + long double y; +#endif +{ + int32_t hx,ix,iy; + u_int32_t hy,ly,esy; + + GET_FLOAT_WORD(hx,x); + GET_LDOUBLE_WORDS(esy,hy,ly,y); + ix = hx&0x7fffffff; /* |x| */ + iy = esy&0x7fff; /* |y| */ + + if((ix>0x7f800000) || /* x is nan */ + (iy>=0x7fff&&((hy|ly)!=0))) /* y is nan */ + return x+y; + if((long double) x==y) return y; /* x=y, return y */ + if(ix==0) { /* x == 0 */ + float x2; + SET_FLOAT_WORD(x,((esy&0x8000)<<16)|1);/* return +-minsub*/ + x2 = x*x; + if(x2==x) return x2; else return x; /* raise underflow flag */ + } + if(hx>=0) { /* x > 0 */ + if(esy>=0x8000||((ix>>23)&0xff)>iy-0x3f80 + || (((ix>>23)&0xff)==iy-0x3f80 + && ((ix&0x7fffff)<<8)>(hy&0x7fffffff))) {/* x > y, x -= ulp */ + hx -= 1; + } else { /* x < y, x += ulp */ + hx += 1; + } + } else { /* x < 0 */ + if(esy<0x8000||((ix>>23)&0xff)>iy-0x3f80 + || (((ix>>23)&0xff)==iy-0x3f80 + && ((ix&0x7fffff)<<8)>(hy&0x7fffffff))) {/* x < y, x -= ulp */ + hx -= 1; + } else { /* x > y, x += ulp */ + hx += 1; + } + } + hy = hx&0x7f800000; + if(hy>=0x7f800000) return x+x; /* overflow */ + if(hy<0x00800000) { /* underflow */ + float x2 = x*x; + if(x2!=x) { /* raise underflow flag */ + SET_FLOAT_WORD(x2,hx); + return x2; + } + } + SET_FLOAT_WORD(x,hx); + return x; +} +weak_alias (__nexttowardf, nexttowardf) Added: haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_nexttowardl.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_nexttowardl.c 2008-09-06 14:31:28 UTC (rev 27348) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/generic/s_nexttowardl.c 2008-09-06 15:00:33 UTC (rev 27349) @@ -0,0 +1 @@ +/* This function is the same as nextafterl so we use an alias there. */ Modified: haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/Jamfile =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/Jamfile 2008-09-06 14:31:28 UTC (rev 27348) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/m68k/Jamfile 2008-09-06 15:00:33 UTC (rev 27349) @@ -83,6 +83,7 @@ s_modf.c s_modff.c # s_modfl.c s_nan.c s_nanf.c # s_nanl.c s_nextafter.c s_nextafterf.c # s_nextafterl.c + s_nexttoward.c # s_nexttowardf.c s_nexttowardl.c s_round.c s_roundf.c # s_roundl.c s_scalbn.c s_scalbnf.c # s_scalbnl.c s_signbit.c s_signbitf.c # s_signbitl.c Modified: haiku/trunk/src/system/libroot/posix/glibc/arch/ppc/Jamfile =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/ppc/Jamfile 2008-09-06 14:31:28 UTC (rev 27348) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/ppc/Jamfile 2008-09-06 15:00:33 UTC (rev 27349) @@ -80,6 +80,7 @@ s_lround.c s_lroundf.c s_modf.c s_modff.c # s_modfl.c s_nan.c s_nanf.c # s_nanl.c + # s_nexttoward.c s_nexttowardf.c s_nexttowardl.c s_round.c s_roundf.c # s_roundl.c s_scalbn.c s_scalbnf.c # s_scalbnl.c s_signbit.c s_signbitf.c # s_signbitl.c Modified: haiku/trunk/src/system/libroot/posix/glibc/arch/x86/Jamfile =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/x86/Jamfile 2008-09-06 14:31:28 UTC (rev 27348) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/x86/Jamfile 2008-09-06 15:00:33 UTC (rev 27349) @@ -63,6 +63,7 @@ s_modf.c s_modff.c # s_modfl.c s_nan.c s_nanf.c s_nextafter.c s_nextafterf.c + s_nexttowardl.c s_signbit.c s_signbitf.c s_signbitl.c s_round.c s_roundf.c s_roundl.c s_signgam.c @@ -158,6 +159,7 @@ s_lrint.S s_lrintf.S s_lrintl.S s_nearbyint.S s_nearbyintf.S s_nearbyintl.S s_nextafterl.c + s_nexttoward.c s_nexttowardf.c s_remquo.S s_remquof.S s_remquol.S s_rint.S s_rintf.S s_rintl.c s_scalbln.c s_scalblnf.c s_scalblnl.c Added: haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_nexttoward.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_nexttoward.c 2008-09-06 14:31:28 UTC (rev 27348) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_nexttoward.c 2008-09-06 15:00:33 UTC (rev 27349) @@ -0,0 +1,106 @@ +/* s_nexttoward.c + * Special i387 version + * Conversion from s_nextafter.c by Ulrich Drepper, Cygnus Support, + * drepper at cygnus.com. + */ + +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#if defined(LIBM_SCCS) && !defined(lint) +static char rcsid[] = "$NetBSD: $"; +#endif + +/* IEEE functions + * nexttoward(x,y) + * return the next machine floating-point number of x in the + * direction toward y. + * Special cases: + */ + +#include "math.h" +#include "math_private.h" + +#ifdef __STDC__ + double __nexttoward(double x, long double y) +#else + double __nexttoward(x,y) + double x; + long double y; +#endif +{ + int32_t hx,ix,iy; + u_int32_t lx,hy,ly,esy; + + EXTRACT_WORDS(hx,lx,x); + GET_LDOUBLE_WORDS(esy,hy,ly,y); + ix = hx&0x7fffffff; /* |x| */ + iy = esy&0x7fff; /* |y| */ + + /* Intel's extended format has the normally implicit 1 explicit + present. Sigh! */ + if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) || /* x is nan */ + ((iy>=0x7fff)&&((hy&0x7fffffff)|ly)!=0)) /* y is nan */ + return x+y; + if((long double) x==y) return y; /* x=y, return y */ + if((ix|lx)==0) { /* x == 0 */ + double x2; + INSERT_WORDS(x,(esy&0x8000)<<16,1); /* return +-minsub */ + x2 = x*x; + if(x2==x) return x2; else return x; /* raise underflow flag */ + } + if(hx>=0) { /* x > 0 */ + if (esy>=0x8000||((ix>>20)&0x7ff)>iy-0x3c00 + || (((ix>>20)&0x7ff)==iy-0x3c00 + && (((hx<<11)|(lx>>21))>(hy&0x7fffffff) + || (((hx<<11)|(lx>>21))==(hy&0x7fffffff) + && (lx<<11)>ly)))) { /* x > y, x -= ulp */ + if(lx==0) hx -= 1; + lx -= 1; + } else { /* x < y, x += ulp */ + lx += 1; + if(lx==0) hx += 1; + } + } else { /* x < 0 */ + if (esy<0x8000||((ix>>20)&0x7ff)>iy-0x3c00 + || (((ix>>20)&0x7ff)==iy-0x3c00 + && (((hx<<11)|(lx>>21))>(hy&0x7fffffff) + || (((hx<<11)|(lx>>21))==(hy&0x7fffffff) + && (lx<<11)>ly)))) {/* x < y, x -= ulp */ + if(lx==0) hx -= 1; + lx -= 1; + } else { /* x > y, x += ulp */ + lx += 1; + if(lx==0) hx += 1; + } + } + hy = hx&0x7ff00000; + if(hy>=0x7ff00000) { + x = x+x; /* overflow */ + /* Force conversion to double. */ + asm ("" : "=m"(x) : "m"(x)); + return x; + } + if(hy<0x00100000) { /* underflow */ + double x2 = x*x; + if(x2!=x) { /* raise underflow flag */ + INSERT_WORDS(x2,hx,lx); + return x2; + } + } + INSERT_WORDS(x,hx,lx); + return x; +} +weak_alias (__nexttoward, nexttoward) +#ifdef NO_LONG_DOUBLE +strong_alias (__nexttoward, __nexttowardl) +weak_alias (__nexttoward, nexttowardl) +#endif Added: haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_nexttowardf.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_nexttowardf.c 2008-09-06 14:31:28 UTC (rev 27348) +++ haiku/trunk/src/system/libroot/posix/glibc/arch/x86/s_nexttowardf.c 2008-09-06 15:00:33 UTC (rev 27349) @@ -0,0 +1,86 @@ +/* s_nexttowardf.c -- float version of s_nextafter.c. + * Special i387 version. + * Conversion to float by Ian Lance Taylor, Cygnus Support, ian at cygnus.com. + */ + +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#if defined(LIBM_SCCS) && !defined(lint) +static char rcsid[] = "$NetBSD: $"; +#endif + +#include "math.h" +#include "math_private.h" + +#ifdef __STDC__ + float __nexttowardf(float x, long double y) +#else + float __nexttowardf(x,y) + float x; + long double y; +#endif +{ + int32_t hx,ix,iy; + u_int32_t hy,ly,esy; + + GET_FLOAT_WORD(hx,x); + GET_LDOUBLE_WORDS(esy,hy,ly,y); + ix = hx&0x7fffffff; /* |x| */ + iy = esy&0x7fff; /* |y| */ + + /* Intel's extended format has the normally implicit 1 explicit + present. Sigh! */ + if((ix>0x7f800000) || /* x is nan */ + (iy>=0x7fff&&(((hy&0x7fffffff)|ly)!=0))) /* y is nan */ + return x+y; + if((long double) x==y) return y; /* x=y, return y */ + if(ix==0) { /* x == 0 */ + float x2; + SET_FLOAT_WORD(x,((esy&0x8000)<<16)|1);/* return +-minsub*/ + x2 = x*x; + if(x2==x) return x2; else return x; /* raise underflow flag */ + } + if(hx>=0) { /* x > 0 */ + if(esy>=0x8000||((ix>>23)&0xff)>iy-0x3f80 + || (((ix>>23)&0xff)==iy-0x3f80 + && ((ix&0x7fffff)<<8)>(hy&0x7fffffff))) {/* x > y, x -= ulp */ + hx -= 1; + } else { /* x < y, x += ulp */ + hx += 1; + } + } else { /* x < 0 */ + if(esy<0x8000||((ix>>23)&0xff)>iy-0x3f80 + || (((ix>>23)&0xff)==iy-0x3f80 + && ((ix&0x7fffff)<<8)>(hy&0x7fffffff))) {/* x < y, x -= ulp */ + hx -= 1; + } else { /* x > y, x += ulp */ + hx += 1; + } + } + hy = hx&0x7f800000; + if(hy>=0x7f800000) { + x = x+x; /* overflow */ + /* Force conversion to float. */ + asm ("" : "=m"(x) : "m"(x)); + return x; + } + if(hy<0x00800000) { /* underflow */ + float x2 = x*x; + if(x2!=x) { /* raise underflow flag */ + SET_FLOAT_WORD(x2,hx); + return x2; + } + } + SET_FLOAT_WORD(x,hx); + return x; +} +weak_alias (__nexttowardf, nexttowardf) From bonefish at mail.berlios.de Sun Sep 7 01:47:00 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sun, 7 Sep 2008 01:47:00 +0200 Subject: [Haiku-commits] r27350 - haiku/trunk/src/build/libroot Message-ID: <200809062347.m86Nl078003731@sheep.berlios.de> Author: bonefish Date: 2008-09-07 01:46:59 +0200 (Sun, 07 Sep 2008) New Revision: 27350 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27350&view=rev Added: haiku/trunk/src/build/libroot/fs_attr_extattr.h haiku/trunk/src/build/libroot/fs_attr_untyped.cpp haiku/trunk/src/build/libroot/fs_attr_xattr.h Removed: haiku/trunk/src/build/libroot/fs_attr_xattr.cpp Modified: haiku/trunk/src/build/libroot/fs_attr.cpp Log: Refactored the BeOS attribute emulation using xattr a bit: * Renamed fs_attr_xattr.cpp to libroot/fs_attr_untyped.cpp. * Pulled the xattr specifics into a separate fs_attr_xattr.h. * Added fs_attr_extattr.h, interfacing with FreeBSD's extattr support. Totally untested yet. Might not even compile. Modified: haiku/trunk/src/build/libroot/fs_attr.cpp =================================================================== --- haiku/trunk/src/build/libroot/fs_attr.cpp 2008-09-06 15:00:33 UTC (rev 27349) +++ haiku/trunk/src/build/libroot/fs_attr.cpp 2008-09-06 23:46:59 UTC (rev 27350) @@ -1,5 +1,5 @@ #ifdef HAIKU_HOST_USE_XATTR -# include "fs_attr_xattr.cpp" +# include "fs_attr_untyped.cpp" #else # include "fs_attr_generic.cpp" #endif Added: haiku/trunk/src/build/libroot/fs_attr_extattr.h =================================================================== --- haiku/trunk/src/build/libroot/fs_attr_extattr.h 2008-09-06 15:00:33 UTC (rev 27349) +++ haiku/trunk/src/build/libroot/fs_attr_extattr.h 2008-09-06 23:46:59 UTC (rev 27350) @@ -0,0 +1,89 @@ +/* + * Copyright 2008, Ingo Weinhold, ingo_weinhold at gmx.de. + * Distributed under the terms of the MIT License. + */ +#ifndef FS_ATTR_EXTATTR_H +#define FS_ATTR_EXTATTR_H + +/*! Included by fs_attr_untyped.cpp. Interfaces with FreeBSD extattr support. +*/ + + +#include +#include + + +// the namespace all attributes live in +static const char* kAttributeNamespace = "haiku."; +static const int kAttributeNamespaceLen = 6; + + +static ssize_t +list_attributes(int fd, const char* path, char* buffer, size_t bufferSize) +{ + ssize_t bytesRead; + if (fd >= 0) { + bytesRead = extattr_list_fd(fd, EXTATTR_NAMESPACE_USER, buffer, + bufferSize); + } else { + bytesRead = extattr_list_link(path, EXTATTR_NAMESPACE_USER, buffer, + bufferSize); + } + + if (bytesRead <= 0) + return bytesRead; + + // The listing is in a different format than expected by the caller. Here + // we get a sequence of (, ) pairs, but expected + // is a sequence of null-terminated names. Let's convert it. + int index = *buffer; + memmove(buffer, buffer + 1, bytesRead - 1); + + while (index < bytesRead - 1) { + int len = buffer[index]; + buffer[index] = '\0'; + index += len + 1; + } + + buffer[bytesRead - 1] = '\0'; + + return bytesRead; +} + + +static ssize_t +get_attribute(int fd, const char* path, const char* attribute, void* buffer, + size_t bufferSize) +{ + if (fd >= 0) { + return extattr_get_fd(fd, EXTATTR_NAMESPACE_USER, attribute, buffer, + bufferSize); + } + return extattr_get_link(path, EXTATTR_NAMESPACE_USER, attribute, buffer, + bufferSize); +} + + +static int +set_attribute(int fd, const char* path, const char* attribute, + const void* buffer, size_t bufferSize) +{ + if (fd >= 0) { + return extattr_set_fd(fd, EXTATTR_NAMESPACE_USER, attribute, buffer, + bufferSize); + } + return extattr_set_link(path, EXTATTR_NAMESPACE_USER, attribute, buffer, + bufferSize); +} + + +static int +remove_attribute(int fd, const char* path, const char* attribute) +{ + if (fd >= 0) + return extattr_delete_fd(fd, EXTATTR_NAMESPACE_USER, attribute); + return extattr_delete_link(path, EXTATTR_NAMESPACE_USER, attribute); +} + + +#endif // FS_ATTR_EXTATTR_H Copied: haiku/trunk/src/build/libroot/fs_attr_untyped.cpp (from rev 27306, haiku/trunk/src/build/libroot/fs_attr_xattr.cpp) =================================================================== --- haiku/trunk/src/build/libroot/fs_attr_xattr.cpp 2008-09-03 15:15:19 UTC (rev 27306) +++ haiku/trunk/src/build/libroot/fs_attr_untyped.cpp 2008-09-06 23:46:59 UTC (rev 27350) @@ -0,0 +1,735 @@ +/* + * Copyright 2005-2008, Ingo Weinhold, ingo_weinhold at gmx.de. + * Distributed under the terms of the MIT License. + */ + +/*! Emulation BeOS-style attributes by mapping them to untyped attributes of + the host platform (xattr on Linux, extattr on FreeBSD). +*/ + + +#ifdef BUILDING_FS_SHELL +# include "compat.h" +# define B_OK 0 +# define B_BAD_VALUE EINVAL +# define B_FILE_ERROR EBADF +# define B_ERROR EINVAL +# define B_ENTRY_NOT_FOUND ENOENT +# define B_NO_MEMORY ENOMEM +#else +# include +# include + +# include "fs_impl.h" +# include "fs_descriptors.h" +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + + +// Include the interface to the host platform attributes support. +#if defined(HAIKU_HOST_PLATFORM_LINUX) +# include "fs_attr_xattr.h" +#elif defined(HAIKU_HOST_PLATFORM_FREEBSD) +# include "fs_attr_extattr.h" +#else +# error No attribute support for this host platform! +#endif + + +namespace BPrivate {} +using namespace BPrivate; +using std::map; +using std::string; + +// the maximum length of an attribute listing we support +static const int kMaxAttributeListingLength = 10240; + +// the maximum attribute length we support +static const int kMaxAttributeLength = 10240 * 4; + + +// mangle_attribute_name +static string +mangle_attribute_name(const char* name) +{ + // prepend our xattr namespace and translate: + // '/' -> "%\" + // '%' -> "%%" + + string mangledName = kAttributeNamespace; + for (int i = 0; name[i] != '\0'; i++) { + char c = name[i]; + switch (c) { + case '/': + mangledName += "%\\"; + break; + case '%': + mangledName += "%%"; + break; + default: + mangledName += c; + break; + } + } + return mangledName; +} + + +// demangle_attribute_name +static bool +demangle_attribute_name(const char* name, string& demangledName) +{ + // chop of our xattr namespace and translate: + // "%\" -> '/' + // "%%" -> '%' + + if (strncmp(name, kAttributeNamespace, kAttributeNamespaceLen) != 0) + return false; + + name += kAttributeNamespaceLen; + + demangledName = ""; + + for (int i = 0; name[i] != '\0'; i++) { + char c = name[i]; + if (c == '%') { + c = name[++i]; + if (c == '%') + demangledName += c; + else if (c == '\\') + demangledName += '/'; + else + return false; + } else + demangledName += c; + } + + return true; +} + + +namespace { + +class AttributeDirectory; + +typedef map AttrDirMap; +static AttrDirMap sAttributeDirectories; + +// LongDirent +struct LongDirent : dirent { + char name[B_FILE_NAME_LENGTH]; +}; + +// AttributeHeader +struct AttributeHeader { + uint32 type; +}; + +// AttributeDirectory +class AttributeDirectory { +public: + AttributeDirectory() + : fFileFD(-1), + fFakeDir(NULL), + fListing(NULL), + fListingLength(-1), + fListingIndex(0) + { + } + + ~AttributeDirectory() + { + if (fFileFD >= 0) + close(fFileFD); + + if (fFakeDir) { + AttrDirMap::iterator it = sAttributeDirectories.find(fFakeDir); + if (it != sAttributeDirectories.end()) + sAttributeDirectories.erase(it); + + closedir(fFakeDir); + } + + free(fListing); + } + + static AttributeDirectory* Get(DIR* dir) + { + AttrDirMap::iterator it = sAttributeDirectories.find(dir); + if (it == sAttributeDirectories.end()) + return NULL; + return it->second; + } + + status_t Init(const char* path, int fileFD) + { + // open a fake DIR + if (!fFakeDir) { + fFakeDir = opendir("."); + if (!fFakeDir) + return B_ERROR; + + sAttributeDirectories[fFakeDir] = this; + } + + string tempPath; + if (!path) { + // We've got no path. If the file descriptor is one of our own and + // not a system FD, we need to get a path for it. + Descriptor* descriptor = get_descriptor(fileFD); + if (descriptor && !descriptor->IsSystemFD()) { + status_t error = descriptor->GetPath(tempPath); + if (error != B_OK) + return error; + path = tempPath.c_str(); + fileFD = -1; + } + } + + if (path) { + // A path was given -- check, if it's a symlink. If so we need to + // keep the path, otherwise we open a FD. + struct stat st; + if (lstat(path, &st)) + return B_ENTRY_NOT_FOUND; + + if (S_ISLNK(st.st_mode)) { + fFileFD = -1; + fPath = path; + } else { + fFileFD = open(path, O_RDONLY); + if (fFileFD < 0) + return errno; + fPath = ""; + } + } else { + // FD was given -- dup it. + fFileFD = dup(fileFD); + if (fFileFD < 0) + return errno; + fPath = ""; + } + + fListingLength = -1; + fListingIndex = 0; + + return B_OK; + } + + DIR* FakeDir() const { return fFakeDir; } + + status_t ReadDir(struct dirent** _entry) + { + // make sure we have a current listing + status_t error = _CheckListing(); + if (error != B_OK) + return error; + + // keep going until we find an entry or hit the end of dir + while (fListingIndex < fListingLength) { + // get next entry name + const char* name = fListing + fListingIndex; + int nameLen = strlen(name); + fListingIndex += nameLen + 1; + + // check the attribute namespace + string demangledName; + if (!demangle_attribute_name(name, demangledName)) + continue; + name = demangledName.c_str(); + nameLen = demangledName.length(); + + if (nameLen == 0) { + // Uh, weird attribute. + return B_ERROR; + } + + // prepare the dirent + strcpy(fDirent.d_name, name); + fDirent.d_ino = 0; +// TODO: We need the node ID! + + *_entry = &fDirent; + return B_OK; + } + + // end of dir + *_entry = NULL; + return B_OK; + } + + void RewindDir() + { + fListingIndex = 0; + } + +private: + status_t _CheckListing() + { + if (fListing && fListingLength >= 0) + return B_OK; + + char listing[kMaxAttributeListingLength]; + + // get the listing + ssize_t length = list_attributes(fFileFD, fPath.c_str(), listing, + kMaxAttributeListingLength); + if (length < 0) + return errno; + + // clone the on-stack listing + char* newListing = (char*)realloc(fListing, length); + if (!newListing) + return B_NO_MEMORY; + memcpy(newListing, listing, length); + + fListing = newListing; + fListingLength = length; + fListingIndex = 0; + + return B_OK; + } + +private: + int fFileFD; + string fPath; + DIR* fFakeDir; + LongDirent fDirent; + char* fListing; + int fListingLength; + int fListingIndex; +}; + +// LocalFD +class LocalFD { +public: + LocalFD() + { + } + + ~LocalFD() + { + } + + status_t Init(int fd) + { +#ifndef BUILDING_FS_SHELL + Descriptor* descriptor = get_descriptor(fd); + if (descriptor && !descriptor->IsSystemFD()) { + // we need to get a path + fFD = -1; + return descriptor->GetPath(fPath); + } +#endif + + fFD = fd; + fPath = ""; + return B_OK; + } + + int FD() const + { + return fFD; + } + + const char* Path() const + { + return (fFD < 0 ? fPath.c_str() : NULL); + } + + bool IsSymlink() const + { + struct stat st; + int result; + if (Path()) + result = lstat(Path(), &st); + else + result = fstat(fFD, &st); + + return (result == 0 && S_ISLNK(st.st_mode)); + } + +private: + string fPath; + int fFD; +}; + +} // unnamed namspace + + +// # pragma mark - Public API + + +// fs_open_attr_dir +DIR * +fs_open_attr_dir(const char *path) +{ + AttributeDirectory* attrDir = new AttributeDirectory; + + status_t error = attrDir->Init(path, -1); + if (error != B_OK) { + errno = error; + delete attrDir; + return NULL; + } + + return attrDir->FakeDir(); +} + +// fs_fopen_attr_dir +DIR * +fs_fopen_attr_dir(int fd) +{ + AttributeDirectory* attrDir = new AttributeDirectory; + + status_t error = attrDir->Init(NULL, fd); + if (error != B_OK) { + errno = error; + delete attrDir; + return NULL; + } + + return attrDir->FakeDir(); +} + +// fs_close_attr_dir +int +fs_close_attr_dir(DIR *dir) +{ + AttributeDirectory* attrDir = AttributeDirectory::Get(dir); + if (!attrDir) { + errno = B_BAD_VALUE; + return -1; + } + + delete attrDir; + return 0; +} + +// fs_read_attr_dir +struct dirent * +fs_read_attr_dir(DIR *dir) +{ + // get attr dir + AttributeDirectory* attrDir = AttributeDirectory::Get(dir); + if (!attrDir) { + errno = B_BAD_VALUE; + return NULL; + } + + // read attr dir + dirent* entry = NULL; + status_t error = attrDir->ReadDir(&entry); + if (error != B_OK) { + errno = error; + return NULL; + } + + return entry; +} + +// fs_rewind_attr_dir +void +fs_rewind_attr_dir(DIR *dir) +{ + // get attr dir + AttributeDirectory* attrDir = AttributeDirectory::Get(dir); + if (attrDir) + attrDir->RewindDir(); +} + +// fs_open_attr +int +fs_open_attr(int fd, const char *attribute, uint32 type, int openMode) +{ + // not supported ATM + errno = B_BAD_VALUE; + return -1; +} + +// fs_close_attr +int +fs_close_attr(int fd) +{ + // not supported ATM + errno = B_BAD_VALUE; + return -1; +} + +// fs_read_attr +ssize_t +fs_read_attr(int fd, const char *_attribute, uint32 type, off_t pos, + void *buffer, size_t readBytes) +{ + // check params + if (pos < 0 || pos + readBytes > kMaxAttributeLength + || !_attribute || !buffer) { + errno = B_BAD_VALUE; + return -1; + } + + // resolve FD + LocalFD localFD; + status_t error = localFD.Init(fd); + if (error != B_OK) { + errno = error; + return -1; + } + + // mangle the attribute name + string attribute = mangle_attribute_name(_attribute); + + // read the attribute + char attributeBuffer[sizeof(AttributeHeader) + kMaxAttributeLength]; + ssize_t bytesRead = min_c((size_t)kMaxAttributeLength, readBytes) + + sizeof(AttributeHeader); + if (localFD.Path()) { + bytesRead = get_attribute(-1, localFD.Path(), attribute.c_str(), + attributeBuffer, bytesRead); + } else { + bytesRead = get_attribute(localFD.FD(), NULL, attribute.c_str(), + attributeBuffer, bytesRead); + } + if (bytesRead < 0) { + // Make sure, the error code is B_ENTRY_NOT_FOUND, if the attribute + // doesn't exist. + if (errno == ENOATTR || errno == ENODATA) + errno = B_ENTRY_NOT_FOUND; + return -1; + } + + // check length for sanity + if ((size_t)bytesRead < sizeof(AttributeHeader)) { + fprintf(stderr, "fs_read_attr(): attribute \"%s\" is shorter than the " + "AttributeHeader!\n", attribute.c_str()); + errno = B_ERROR; + return -1; + } + + // copy the result into the provided buffer + bytesRead -= sizeof(AttributeHeader); + if (bytesRead > pos) { + memcpy(buffer, attributeBuffer + sizeof(AttributeHeader) + pos, + bytesRead - pos); + } else + bytesRead = 0; + + return bytesRead; +} + +// fs_write_attr +ssize_t +fs_write_attr(int fd, const char *_attribute, uint32 type, off_t pos, + const void *buffer, size_t writeBytes) +{ + // check params + if (pos < 0 || pos + writeBytes > kMaxAttributeLength + || !_attribute || !buffer) { + errno = B_BAD_VALUE; + return -1; + } + + // resolve FD + LocalFD localFD; + status_t error = localFD.Init(fd); + if (error != B_OK) { + errno = error; + return -1; + } + + // mangle the attribute name + string attribute = mangle_attribute_name(_attribute); + + // prepare an attribute buffer + char attributeBuffer[sizeof(AttributeHeader) + kMaxAttributeLength]; + AttributeHeader* header = (AttributeHeader*)attributeBuffer; + header->type = type; + memset(attributeBuffer + sizeof(AttributeHeader), 0, pos); + memcpy(attributeBuffer + sizeof(AttributeHeader) + pos, buffer, writeBytes); + + // write the attribute + ssize_t toWrite = sizeof(AttributeHeader) + pos + writeBytes; + int result; + if (localFD.Path()) { + result = set_attribute(-1, localFD.Path(), attribute.c_str(), + attributeBuffer, toWrite); + } else { + result = set_attribute(localFD.FD(), NULL, attribute.c_str(), + attributeBuffer, toWrite); + } + if (result < 0) { + // Setting user attributes on symlinks is not allowed (xattr). So, if + // this is a symlink and we're only supposed to write a "BEOS:TYPE" + // attribute we silently pretend to have succeeded. + if (localFD.IsSymlink() && strcmp(_attribute, "BEOS:TYPE") == 0) + return writeBytes; + return -1; + } + + return writeBytes; +} + +// fs_remove_attr +int +fs_remove_attr(int fd, const char *_attribute) +{ + // check params + if (!_attribute) { + errno = B_BAD_VALUE; + return -1; + } + + // resolve FD + LocalFD localFD; + status_t error = localFD.Init(fd); + if (error != B_OK) { + errno = error; + return -1; + } + + // mangle the attribute name + string attribute = mangle_attribute_name(_attribute); + + // remove attribute + int result; + if (localFD.Path()) + result = remove_attribute(-1, localFD.Path(), attribute.c_str()); + else + result = remove_attribute(localFD.FD(), NULL, attribute.c_str()); + + if (result < 0) { + // Make sure, the error code is B_ENTRY_NOT_FOUND, if the attribute + // doesn't exist. + if (errno == ENOATTR || errno == ENODATA) + errno = B_ENTRY_NOT_FOUND; + return -1; + } + return 0; +} + +// fs_stat_attr +int +fs_stat_attr(int fd, const char *_attribute, struct attr_info *attrInfo) +{ + if (!_attribute || !attrInfo) { + errno = B_BAD_VALUE; + return -1; + } + + // resolve FD + LocalFD localFD; + status_t error = localFD.Init(fd); + if (error != B_OK) { + errno = error; + return -1; + } + + // mangle the attribute name + string attribute = mangle_attribute_name(_attribute); + + // read the attribute + char attributeBuffer[sizeof(AttributeHeader) + kMaxAttributeLength]; + ssize_t bytesRead = sizeof(AttributeHeader) + kMaxAttributeLength; + if (localFD.Path()) { + bytesRead = get_attribute(-1, localFD.Path(), attribute.c_str(), + attributeBuffer, bytesRead); + } else { + bytesRead = get_attribute(localFD.FD(), NULL, attribute.c_str(), + attributeBuffer, bytesRead); + } + if (bytesRead < 0) { + // Make sure, the error code is B_ENTRY_NOT_FOUND, if the attribute + // doesn't exist. + if (errno == ENOATTR || errno == ENODATA) + errno = B_ENTRY_NOT_FOUND; + return -1; + } + + // check length for sanity + if ((size_t)bytesRead < sizeof(AttributeHeader)) { + fprintf(stderr, "fs_stat_attr(): attribute \"%s\" is shorter than the " + "AttributeHeader!\n", attribute.c_str()); + errno = B_ERROR; + return -1; + } + + attrInfo->size = bytesRead - sizeof(AttributeHeader); + attrInfo->type = ((AttributeHeader*)attributeBuffer)->type; + + return 0; +} + + +// #pragma mark - Private Syscalls + + +#ifndef BUILDING_FS_SHELL + +// _kern_open_attr_dir +int +_kern_open_attr_dir(int fd, const char *path) +{ + // get node ref for the node + struct stat st; + status_t error = _kern_read_stat(fd, path, false, &st, + sizeof(struct stat)); + if (error != B_OK) { + errno = error; + return -1; + } + NodeRef ref(st); + + DIR* dir; + if (path) { + // If a path was given, get a usable path. + string realPath; + status_t error = get_path(fd, path, realPath); + if (error != B_OK) + return error; + + dir = fs_open_attr_dir(realPath.c_str()); + } else + dir = fs_fopen_attr_dir(fd); + + if (!dir) + return errno; + + // create descriptor + AttrDirDescriptor *descriptor = new AttrDirDescriptor(dir, ref); + return add_descriptor(descriptor); +} + +// _kern_rename_attr +status_t +_kern_rename_attr(int fromFile, const char *fromName, int toFile, + const char *toName) +{ + // not supported ATM + return B_BAD_VALUE; +} + +// _kern_remove_attr +status_t +_kern_remove_attr(int fd, const char *name) +{ + if (!name) + return B_BAD_VALUE; + + if (fs_remove_attr(fd, name) < 0) + return errno; + return B_OK; +} + +#endif // ! BUILDING_FS_SHELL Deleted: haiku/trunk/src/build/libroot/fs_attr_xattr.cpp Added: haiku/trunk/src/build/libroot/fs_attr_xattr.h =================================================================== --- haiku/trunk/src/build/libroot/fs_attr_xattr.h 2008-09-06 15:00:33 UTC (rev 27349) +++ haiku/trunk/src/build/libroot/fs_attr_xattr.h 2008-09-06 23:46:59 UTC (rev 27350) @@ -0,0 +1,58 @@ +/* + * Copyright 2008, Ingo Weinhold, ingo_weinhold at gmx.de. + * Distributed under the terms of the MIT License. + */ +#ifndef FS_ATTR_XATTR_H +#define FS_ATTR_XATTR_H + +/*! Included by fs_attr_untyped.cpp. Interfaces with Linux xattr support. +*/ + + +#include + + +// the namespace all attributes live in +static const char* kAttributeNamespace = "user.haiku."; +static const int kAttributeNamespaceLen = 11; + + +static ssize_t +list_attributes(int fd, const char* path, char* buffer, size_t bufferSize) +{ + if (fd >= 0) + return flistxattr(fd, buffer, bufferSize); + return llistxattr(path, buffer, bufferSize); +} + + +static ssize_t +get_attribute(int fd, const char* path, const char* attribute, void* buffer, + size_t bufferSize) +{ + if (fd >= 0) + return fgetxattr(fd, attribute, buffer, bufferSize); + return lgetxattr(path, attribute, buffer, bufferSize); +} + + +static int +set_attribute(int fd, const char* path, const char* attribute, + const void* buffer, size_t bufferSize) +{ + if (fd >= 0) + return fsetxattr(fd, attribute, buffer, bufferSize, 0); + return lsetxattr(path, attribute, buffer, bufferSize, 0); +} + + +static int +remove_attribute(int fd, const char* path, const char* attribute) +{ + if (fd >= 0) + return fremovexattr(fd, attribute); + return lremovexattr(path, attribute); +} + + +#endif // FS_ATTR_XATTR_H From bonefish at mail.berlios.de Sun Sep 7 03:07:46 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sun, 7 Sep 2008 03:07:46 +0200 Subject: [Haiku-commits] r27351 - haiku/trunk/src/build/libroot Message-ID: <200809070107.m8717kZT016694@sheep.berlios.de> Author: bonefish Date: 2008-09-07 03:07:45 +0200 (Sun, 07 Sep 2008) New Revision: 27351 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27351&view=rev Modified: haiku/trunk/src/build/libroot/errors.cpp Log: Translate ENOATTR properly. That seemed to be all that kept FreeBSD extattr support from working. Modified: haiku/trunk/src/build/libroot/errors.cpp =================================================================== --- haiku/trunk/src/build/libroot/errors.cpp 2008-09-06 23:46:59 UTC (rev 27350) +++ haiku/trunk/src/build/libroot/errors.cpp 2008-09-07 01:07:45 UTC (rev 27351) @@ -123,6 +123,9 @@ ADD_ERROR(ELOOP); ADD_ERROR(ENOEXEC); ADD_ERROR(EPIPE); + #ifdef ENOATTR + ADD_ERROR(ENOATTR); + #endif sErrorMapsInitialized = true; } From bonefish at mail.berlios.de Sun Sep 7 03:08:30 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sun, 7 Sep 2008 03:08:30 +0200 Subject: [Haiku-commits] r27352 - haiku/trunk/src/bin Message-ID: <200809070108.m8718Ui8016742@sheep.berlios.de> Author: bonefish Date: 2008-09-07 03:08:30 +0200 (Sun, 07 Sep 2008) New Revision: 27352 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27352&view=rev Modified: haiku/trunk/src/bin/catattr.cpp Log: is no standard header, use instead. Modified: haiku/trunk/src/bin/catattr.cpp =================================================================== --- haiku/trunk/src/bin/catattr.cpp 2008-09-07 01:07:45 UTC (rev 27351) +++ haiku/trunk/src/bin/catattr.cpp 2008-09-07 01:08:30 UTC (rev 27352) @@ -14,10 +14,10 @@ #include #include -#include -#include #include +#include #include +#include /** Used to present the characters in the raw data view */ @@ -66,7 +66,7 @@ } printf("'\n"); } -} +} static status_t @@ -219,7 +219,7 @@ } else { // Issue usage message fprintf(stderr, "usage: %s [--raw|-r] attr_name file1 [file2...]\n", program); - // Be's original version -only- returned 1 if the + // Be's original version -only- returned 1 if the // amount of parameters was wrong, not if the file // or attribute couldn't be found (!) // In all other cases it returned 0 From korli at users.berlios.de Sun Sep 7 11:50:44 2008 From: korli at users.berlios.de (=?ISO-8859-1?Q?J=E9r=F4me_Duval?=) Date: Sun, 7 Sep 2008 11:50:44 +0200 Subject: [Haiku-commits] r27352 - haiku/trunk/src/bin In-Reply-To: <200809070108.m8718Ui8016742@sheep.berlios.de> References: <200809070108.m8718Ui8016742@sheep.berlios.de> Message-ID: Hi Ingo, 2008/9/7 bonefish at BerliOS > Log: > is no standard header, use instead. > > malloc.h is widely used in our tree. Maybe a bug should it opened to track this. Bye, J?r?me -------------- next part -------------- An HTML attachment was scrubbed... URL: From korli at mail.berlios.de Sun Sep 7 12:43:54 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Sun, 7 Sep 2008 12:43:54 +0200 Subject: [Haiku-commits] r27353 - haiku/trunk/src/apps/aboutsystem Message-ID: <200809071043.m87AhsHX015768@sheep.berlios.de> Author: korli Date: 2008-09-07 12:43:43 +0200 (Sun, 07 Sep 2008) New Revision: 27353 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27353&view=rev Modified: haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp Log: fix typo Modified: haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp =================================================================== --- haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp 2008-09-07 01:08:30 UTC (rev 27352) +++ haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp 2008-09-07 10:43:43 UTC (rev 27353) @@ -450,7 +450,7 @@ "\n"); fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &kHaikuOrange); - fCreditsView->Insert("Website, Marketing & Documention:\n"); + fCreditsView->Insert("Website, Marketing & Documentation:\n"); fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &kDarkGrey); fCreditsView->Insert( From ingo_weinhold at gmx.de Sun Sep 7 13:39:27 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Sun, 07 Sep 2008 13:39:27 +0200 Subject: [Haiku-commits] r27352 - haiku/trunk/src/bin In-Reply-To: References: <200809070108.m8718Ui8016742@sheep.berlios.de> Message-ID: <20080907133927.508.1@knochen-vm.localdomain> On 2008-09-07 at 11:50:44 [+0200], J?r?me Duval wrote: > 2008/9/7 bonefish at BerliOS > > > Log: > > is no standard header, use instead. > > > > > malloc.h is widely used in our tree. Maybe a bug should it opened to track > this. Feel free... CU, Ingo From stippi at mail.berlios.de Sun Sep 7 15:38:12 2008 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Sun, 7 Sep 2008 15:38:12 +0200 Subject: [Haiku-commits] r27354 - haiku/trunk/docs/develop Message-ID: <200809071338.m87DcC6D011342@sheep.berlios.de> Author: stippi Date: 2008-09-07 15:38:12 +0200 (Sun, 07 Sep 2008) New Revision: 27354 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27354&view=rev Removed: haiku/trunk/docs/develop/drivesetup/ Log: * The analysis for how DriveSetup works on BeOS is no longer relevant and Haiku's own DriveSetup works differently. From bonefish at mail.berlios.de Sun Sep 7 15:57:27 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sun, 7 Sep 2008 15:57:27 +0200 Subject: [Haiku-commits] r27355 - in haiku/trunk: headers/private/kernel/util src/system/kernel/util src/system/kernel/vm Message-ID: <200809071357.m87DvRuA013226@sheep.berlios.de> Author: bonefish Date: 2008-09-07 15:57:25 +0200 (Sun, 07 Sep 2008) New Revision: 27355 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27355&view=rev Added: haiku/trunk/headers/private/kernel/util/RadixBitmap.h haiku/trunk/src/system/kernel/util/RadixBitmap.cpp Modified: haiku/trunk/src/system/kernel/util/Jamfile haiku/trunk/src/system/kernel/vm/VMAnonymousCache.cpp Log: Patch by Zhao Shuai: * Imported radix bitmap tree implementation from FreeBSD and adjusted it for Haiku. * Make use of the radix tree in the swap support implementation instead of using simple bitmaps. This will allow for faster swap slot allocations. ATM Haiku doesn't benefit that much, since we always allocate single pages, but that will change eventually. Added: haiku/trunk/headers/private/kernel/util/RadixBitmap.h =================================================================== --- haiku/trunk/headers/private/kernel/util/RadixBitmap.h 2008-09-07 13:38:12 UTC (rev 27354) +++ haiku/trunk/headers/private/kernel/util/RadixBitmap.h 2008-09-07 13:57:25 UTC (rev 27355) @@ -0,0 +1,76 @@ +/*- + * Copyright (c) 1998 Matthew Dillon. All Rights Reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * The radix bitmap structure is ported from FreeBSD and is only used + * in swap system at the time. + */ + + +#ifndef _KERNEL_UTIL_RADIX_BITMAP_H +#define _KERNEL_UTIL_RADIX_BITMAP_H + + +#include + + +typedef uint32 swap_addr_t; +typedef uint32 bitmap_t; + +typedef struct radix_node { + union { + bitmap_t bitmap; // bitmap for the slots if we are a leaf + int32 available; // available slots under us if we are not a leaf + } u; + int32 big_hint; // the biggest continuous slots under us +} radix_node; + +// Bitmap which uses radix tree for hinting. +// The radix tree is stored in an array. +typedef struct radix_bitmap { + swap_addr_t free_slots; // # of free slots + swap_addr_t radix; // coverage radix + swap_addr_t skip; // starting skip + radix_node *root; // root of radix tree, actually it is an array + swap_addr_t root_size; // size of the array(# of nodes in the tree) +} radix_bitmap; + + +#define BITMAP_RADIX (sizeof(swap_addr_t) * 8) +#define NODE_RADIX 16 + +#define SWAP_SLOT_NONE ((swap_addr_t)-1) + + +extern radix_bitmap *radix_bitmap_create(uint32 slots); +extern swap_addr_t radix_bitmap_alloc(radix_bitmap *bmp, uint32 count); +extern void radix_bitmap_dealloc(radix_bitmap *bmp, swap_addr_t slotIndex, + uint32 count); +extern void radix_bitmap_destroy(radix_bitmap *bmp); + +#endif // _KERNEL_UTIL_RADIX_BITMAP_H + Modified: haiku/trunk/src/system/kernel/util/Jamfile =================================================================== --- haiku/trunk/src/system/kernel/util/Jamfile 2008-09-07 13:38:12 UTC (rev 27354) +++ haiku/trunk/src/system/kernel/util/Jamfile 2008-09-07 13:57:25 UTC (rev 27355) @@ -10,6 +10,7 @@ list.c queue.c ring_buffer.cpp + RadixBitmap.cpp : $(TARGET_KERNEL_PIC_CCFLAGS) -DUSING_LIBGCC ; Added: haiku/trunk/src/system/kernel/util/RadixBitmap.cpp =================================================================== --- haiku/trunk/src/system/kernel/util/RadixBitmap.cpp 2008-09-07 13:38:12 UTC (rev 27354) +++ haiku/trunk/src/system/kernel/util/RadixBitmap.cpp 2008-09-07 13:57:25 UTC (rev 27355) @@ -0,0 +1,330 @@ +/*- + * Copyright (c) 1998 Matthew Dillon. All Rights Reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * BLIST.C - Bitmap allocator/deallocator, using a radix tree with hinting + * + * This module implements a general bitmap allocator/deallocator. The + * allocator eats around 2 bits per 'block'. The module does not + * try to interpret the meaning of a 'block' other then to return + * SWAPBLK_NONE on an allocation failure. + * + * A radix tree is used to maintain the bitmap. Two radix constants are + * involved: One for the bitmaps contained in the leaf nodes (typically + * 32), and one for the meta nodes (typically 16). Both meta and leaf + * nodes have a hint field. This field gives us a hint as to the largest + * free contiguous range of blocks under the node. It may contain a + * value that is too high, but will never contain a value that is too + * low. When the radix tree is searched, allocation failures in subtrees + * update the hint. + * + * The radix tree also implements two collapsed states for meta nodes: + * the ALL-ALLOCATED state and the ALL-FREE state. If a meta node is + * in either of these two states, all information contained underneath + * the node is considered stale. These states are used to optimize + * allocation and freeing operations. + * + * The hinting greatly increases code efficiency for allocations while + * the general radix structure optimizes both allocations and frees. The + * radix tree should be able to operate well no matter how much + * fragmentation there is and no matter how large a bitmap is used. + * + * Unlike the rlist code, the blist code wires all necessary memory at + * creation time. Neither allocations nor frees require interaction with + * the memory subsystem. In contrast, the rlist code may allocate memory + * on an rlist_free() call. The non-blocking features of the blist code + * are used to great advantage in the swap code (vm/nswap_pager.c). The + * rlist code uses a little less overall memory then the blist code (but + * due to swap interleaving not all that much less), but the blist code + * scales much, much better. + * + * LAYOUT: The radix tree is layed out recursively using a + * linear array. Each meta node is immediately followed (layed out + * sequentially in memory) by BLIST_META_RADIX lower level nodes. This + * is a recursive structure but one that can be easily scanned through + * a very simple 'skip' calculation. In order to support large radixes, + * portions of the tree may reside outside our memory allocation. We + * handle this with an early-termination optimization (when bighint is + * set to -1) on the scan. The memory allocation is only large enough + * to cover the number of blocks requested at creation time even if it + * must be encompassed in larger root-node radix. + * + * NOTE: the allocator cannot currently allocate more then + * BLIST_BMAP_RADIX blocks per call. It will panic with 'allocation too + * large' if you try. This is an area that could use improvement. The + * radix is large enough that this restriction does not effect the swap + * system, though. Currently only the allocation code is effected by + * this algorithmic unfeature. The freeing code can handle arbitrary + * ranges. + * + * This code can be compiled stand-alone for debugging. + */ + +/* + * NOTE: a few modifications is made in the orginal FreeBSD code: + * 1. change the name of some variables/constants + * 2. discard the code handling ALL_FREE and ALL_ALLOCATED state + * 3. allocate more than 32 slots won't lead to kernel panic + * 4. remove all the code for debugging + * + * Zhao Shuai + * upczhsh at 163.com + */ + + +#include +#include + +#define TERMINATOR -1 + + +static uint32 +radix_bitmap_init(radix_node *node, uint32 radix, uint32 skip, uint32 slots) +{ + uint32 index = 0; + int32 big_hint = radix < slots ? radix : slots; + + // leaf node + if (radix == BITMAP_RADIX) { + if (node) { + node->big_hint = big_hint; + if (big_hint == BITMAP_RADIX) + node->u.bitmap = 0; + else + node->u.bitmap = (bitmap_t)-1 << big_hint; + } + return index; + } + + // not leaf node + if (node) { + node->big_hint = big_hint; + node->u.available = big_hint; + } + + radix /= NODE_RADIX; + uint32 next_skip = skip / NODE_RADIX; + + uint32 i; + for (i = 1; i <= skip; i += next_skip) { + if (slots >= radix) { + index = i + radix_bitmap_init(node ? &node[i] : NULL, + radix, next_skip - 1, radix); + slots -= radix; + } else if (slots > 0) { + index = i + radix_bitmap_init(node ? &node[i] : NULL, + radix, next_skip - 1, slots); + slots = 0; + } else { // add a terminator + if (node) + node[i].big_hint = TERMINATOR; + break; + } + } + + if (index < i) + index = i; + + return index; +} + + +radix_bitmap * +radix_bitmap_create(uint32 slots) +{ + uint32 radix = BITMAP_RADIX; + uint32 skip = 0; + + while (radix < slots) { + radix *= NODE_RADIX; + skip = (skip + 1) * NODE_RADIX; + } + + radix_bitmap *bmp = (radix_bitmap *)malloc(sizeof(radix_bitmap)); + if (bmp == NULL) + return NULL; + + bmp->radix = radix; + bmp->skip = skip; + bmp->free_slots = slots; + bmp->root_size = 1 + radix_bitmap_init(NULL, radix, skip, slots); + + bmp->root = (radix_node *)malloc(bmp->root_size * sizeof(radix_node)); + if (bmp->root == NULL) { + free(bmp); + return NULL; + } + + radix_bitmap_init(bmp->root, radix, skip, slots); + + return bmp; +} + + +void +radix_bitmap_destroy(radix_bitmap *bmp) +{ + free(bmp->root); + free(bmp); +} + + +static swap_addr_t +radix_leaf_alloc(radix_node *leaf, swap_addr_t slotIndex, int32 count) +{ + if (count <= BITMAP_RADIX) { + bitmap_t bitmap = ~leaf->u.bitmap; + uint32 n = BITMAP_RADIX - count; + bitmap_t mask = (bitmap_t)-1 >> n; + for (uint32 j = 0; j <= n; j++) { + if ((bitmap & mask) == mask) { + leaf->u.bitmap |= mask; + return (slotIndex + j); + } + mask <<= 1; + } + } + + // we could not allocate count here, update big_hint + if (leaf->big_hint >= count) + leaf->big_hint = count - 1; + return SWAP_SLOT_NONE; +} + + +static swap_addr_t +radix_node_alloc(radix_node *node, swap_addr_t slotIndex, int32 count, + uint32 radix, uint32 skip) +{ + uint32 next_skip = skip / NODE_RADIX; + radix /= NODE_RADIX; + + for (uint32 i = 1; i <= skip; i += next_skip) { + if (node[i].big_hint == TERMINATOR) // TERMINATOR + break; + + if (count <= node[i].big_hint) { + swap_addr_t addr = SWAP_SLOT_NONE; + if (next_skip == 1) + addr = radix_leaf_alloc(&node[i], slotIndex, count); + else + addr = radix_node_alloc(&node[i], slotIndex, count, radix, + next_skip - 1); + if (addr != SWAP_SLOT_NONE) { + node->u.available -= count; + if (node->big_hint > node->u.available) + node->big_hint = node->u.available; + + return addr; + } + } + slotIndex += radix; + } + + // we could not allocate count in the subtree, update big_hint + if (node->big_hint >= count) + node->big_hint = count - 1; + return SWAP_SLOT_NONE; +} + + +swap_addr_t +radix_bitmap_alloc(radix_bitmap *bmp, uint32 count) +{ + swap_addr_t addr = SWAP_SLOT_NONE; + + if (bmp->radix == BITMAP_RADIX) + addr = radix_leaf_alloc(bmp->root, 0, count); + else + addr = radix_node_alloc(bmp->root, 0, count, bmp->radix, bmp->skip); + + if (addr != SWAP_SLOT_NONE) + bmp->free_slots -= count; + + return addr; +} + + +static void +radix_leaf_dealloc(radix_node *leaf, swap_addr_t slotIndex, uint32 count) +{ + uint32 n = slotIndex & (BITMAP_RADIX - 1); + bitmap_t mask = ((bitmap_t)-1 >> (BITMAP_RADIX - count - n)) + & ((bitmap_t)-1 << n); + leaf->u.bitmap &= ~mask; + + leaf->big_hint = BITMAP_RADIX; +} + + +static void +radix_node_dealloc(radix_node *node, swap_addr_t slotIndex, uint32 count, + uint32 radix, uint32 skip, swap_addr_t index) +{ + node->u.available += count; + + uint32 next_skip = skip / NODE_RADIX; + radix /= NODE_RADIX; + + uint32 i = (slotIndex - index) / radix; + index += i * radix; + i = i * next_skip + 1; + + while (i <= skip && index < slotIndex + count) { + uint32 v = index + radix - slotIndex; + if (v > count) + v = count; + + if (next_skip == 1) + radix_leaf_dealloc(&node[i], slotIndex, v); + else + radix_node_dealloc(&node[i], slotIndex, v, radix, + next_skip - 1, index); + + if (node->big_hint < node[i].big_hint) + node->big_hint = node[i].big_hint; + + count -= v; + slotIndex += v; + index += radix; + i += next_skip; + } +} + + +void +radix_bitmap_dealloc(radix_bitmap *bmp, swap_addr_t slotIndex, uint32 count) +{ + if (bmp->radix == BITMAP_RADIX) + radix_leaf_dealloc(bmp->root, slotIndex, count); + else + radix_node_dealloc(bmp->root, slotIndex, count, bmp->radix, + bmp->skip, 0); + + bmp->free_slots += count; +} + Modified: haiku/trunk/src/system/kernel/vm/VMAnonymousCache.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/VMAnonymousCache.cpp 2008-09-07 13:38:12 UTC (rev 27354) +++ haiku/trunk/src/system/kernel/vm/VMAnonymousCache.cpp 2008-09-07 13:57:25 UTC (rev 27355) @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -61,34 +62,13 @@ #define SWAP_BLOCK_SHIFT 5 /* 1 << SWAP_BLOCK_SHIFT == SWAP_BLOCK_PAGES */ #define SWAP_BLOCK_MASK (SWAP_BLOCK_PAGES - 1) -#define SWAP_SLOT_NONE (~(swap_addr_t)0) - -// bitmap allocation macros -#define NUM_BYTES_PER_WORD 4 -#define NUM_BITS_PER_WORD (8 * NUM_BYTES_PER_WORD) -#define MAP_SHIFT 5 // 1 << MAP_SHIFT == NUM_BITS_PER_WORD - -#define TESTBIT(map, i) \ - (((map)[(i) >> MAP_SHIFT] & (1 << (i) % NUM_BITS_PER_WORD))) -#define SETBIT(map, i) \ - (((map)[(i) >> MAP_SHIFT] |= (1 << (i) % NUM_BITS_PER_WORD))) -#define CLEARBIT(map, i) \ - (((map)[(i) >> MAP_SHIFT] &= ~(1 << (i) % NUM_BITS_PER_WORD))) - -// The stack functionality looks like a good candidate to put into its own -// store. I have not done this because once we have a swap file backing up -// the memory, it would probably not be a good idea to separate this -// anymore. - struct swap_file : DoublyLinkedListLinkImpl { int fd; struct vnode *vnode; void *cookie; swap_addr_t first_slot; swap_addr_t last_slot; - swap_addr_t used; // # of slots used - uint32 *maps; // bitmap for the slots - swap_addr_t hint; // next free slot + radix_bitmap *bmp; }; struct swap_hash_key { @@ -96,7 +76,8 @@ off_t page_index; // page index in the cache }; -// Each swap block contains SWAP_BLOCK_PAGES pages +// Each swap block contains swap address information for +// SWAP_BLOCK_PAGES continuous pages from the same cache struct swap_block : HashTableLink { swap_hash_key key; uint32 used; @@ -222,23 +203,22 @@ #endif - static int dump_swap_info(int argc, char** argv) { swap_addr_t totalSwapPages = 0; - swap_addr_t usedSwapPages = 0; + swap_addr_t freeSwapPages = 0; kprintf("swap files:\n"); for (SwapFileList::Iterator it = sSwapFileList.GetIterator(); swap_file* file = it.Next();) { swap_addr_t total = file->last_slot - file->first_slot; - kprintf(" vnode: %p, pages: total: %lu, used: %lu\n", - file->vnode, total, file->used); + kprintf(" vnode: %p, pages: total: %lu, free: %lu\n", + file->vnode, total, file->bmp->free_slots); totalSwapPages += total; - usedSwapPages += file->used; + freeSwapPages += file->bmp->free_slots; } kprintf("\n"); @@ -247,8 +227,8 @@ kprintf("available: %9llu\n", sAvailSwapSpace / B_PAGE_SIZE); kprintf("reserved: %9llu\n", totalSwapPages - sAvailSwapSpace / B_PAGE_SIZE); - kprintf("used: %9lu\n", usedSwapPages); - kprintf("free: %9lu\n", totalSwapPages - usedSwapPages); + kprintf("used: %9lu\n", totalSwapPages - freeSwapPages); + kprintf("free: %9lu\n", freeSwapPages); return 0; } @@ -265,76 +245,43 @@ return SWAP_SLOT_NONE; } - // compute how many pages are free in all swap files - uint32 freeSwapPages = 0; - for (SwapFileList::Iterator it = sSwapFileList.GetIterator(); - swap_file *file = it.Next();) - freeSwapPages += file->last_slot - file->first_slot - file->used; - - if (freeSwapPages < count) { + // since radix bitmap could not handle more than 32 pages, we return + // SWAP_SLOT_NONE, this forces Write() adjust allocation amount + if (count > BITMAP_RADIX) { mutex_unlock(&sSwapFileListLock); - panic("swap_slot_alloc(): swap space exhausted!\n"); return SWAP_SLOT_NONE; } - swap_addr_t hint = 0; - swap_addr_t j; + swap_addr_t j, addr = SWAP_SLOT_NONE; for (j = 0; j < sSwapFileCount; j++) { if (sSwapFileAlloc == NULL) sSwapFileAlloc = sSwapFileList.First(); - hint = sSwapFileAlloc->hint; - swap_addr_t pageCount = sSwapFileAlloc->last_slot - - sSwapFileAlloc->first_slot; - - swap_addr_t i = 0; - while (i < count && (hint + count) <= pageCount) { - if (TESTBIT(sSwapFileAlloc->maps, hint + i)) { - hint++; - i = 0; - } else - i++; + addr = radix_bitmap_alloc(sSwapFileAlloc->bmp, count); + if (addr != SWAP_SLOT_NONE) { + addr += sSwapFileAlloc->first_slot; + break; } - if (i == count) - break; - // this swap_file is full, find another sSwapFileAlloc = sSwapFileList.GetNext(sSwapFileAlloc); } - // no swap file can alloc so many pages, we return SWAP_SLOT_NONE - // and VMAnonymousCache::Write() will adjust allocation amount if (j == sSwapFileCount) { mutex_unlock(&sSwapFileListLock); + panic("swap_slot_alloc: swap space exhausted!\n"); return SWAP_SLOT_NONE; } - swap_addr_t slotIndex = sSwapFileAlloc->first_slot + hint; - - for (uint32 i = 0; i < count; i++) - SETBIT(sSwapFileAlloc->maps, hint + i); - if (hint == sSwapFileAlloc->hint) { - sSwapFileAlloc->hint += count; - swap_addr_t pageCount = sSwapFileAlloc->last_slot - - sSwapFileAlloc->first_slot; - while (TESTBIT(sSwapFileAlloc->maps, sSwapFileAlloc->hint) - && sSwapFileAlloc->hint < pageCount) { - sSwapFileAlloc->hint++; - } - } - - sSwapFileAlloc->used += count; - - // if this swap file has used more than 90% percent of its slots + // if this swap file has used more than 90% percent of its space // switch to another - if (sSwapFileAlloc->used - > 9 * (sSwapFileAlloc->last_slot - sSwapFileAlloc->first_slot) / 10) + if (sSwapFileAlloc->bmp->free_slots + < (sSwapFileAlloc->last_slot - sSwapFileAlloc->first_slot) / 10) sSwapFileAlloc = sSwapFileList.GetNext(sSwapFileAlloc); mutex_unlock(&sSwapFileListLock); - return slotIndex; + return addr; } @@ -361,16 +308,8 @@ mutex_lock(&sSwapFileListLock); swap_file *swapFile = find_swap_file(slotIndex); - slotIndex -= swapFile->first_slot; - - for (uint32 i = 0; i < count; i++) - CLEARBIT(swapFile->maps, slotIndex + i); - - if (swapFile->hint > slotIndex) - swapFile->hint = slotIndex; - - swapFile->used -= count; + radix_bitmap_dealloc(swapFile->bmp, slotIndex, count); mutex_unlock(&sSwapFileListLock); } @@ -1101,16 +1040,12 @@ swap->cookie = descriptor->cookie; int32 pageCount = st.st_size >> PAGE_SHIFT; - swap->used = 0; - - swap->maps = (uint32 *)malloc((pageCount + 7) / 8); - if (swap->maps == NULL) { + swap->bmp = radix_bitmap_create(pageCount); + if (swap->bmp == NULL) { free(swap); close(fd); return B_NO_MEMORY; } - memset(swap->maps, 0, (pageCount + 7) / 8); - swap->hint = 0; // set slot index and add this file to swap file list mutex_lock(&sSwapFileListLock); @@ -1160,7 +1095,7 @@ // if this file is currently used, we can't delete // TODO: mark this swap file deleting, and remove it after releasing // all the swap space - if (swapFile->used > 0) + if (swapFile->bmp->free_slots < swapFile->last_slot - swapFile->first_slot) return B_ERROR; sSwapFileList.Remove(swapFile); @@ -1172,7 +1107,7 @@ mutex_unlock(&sAvailSwapSpaceLock); close(swapFile->fd); - free(swapFile->maps); + radix_bitmap_destroy(swapFile->bmp); free(swapFile); return B_OK; From bonefish at mail.berlios.de Sun Sep 7 15:58:49 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sun, 7 Sep 2008 15:58:49 +0200 Subject: [Haiku-commits] r27356 - haiku/trunk/docs/develop/kernel Message-ID: <200809071358.m87DwnRW013315@sheep.berlios.de> Author: bonefish Date: 2008-09-07 15:58:49 +0200 (Sun, 07 Sep 2008) New Revision: 27356 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27356&view=rev Modified: haiku/trunk/docs/develop/kernel/swap_file_support Log: Patch by Zhao Shuai: Updated documentation regarding the use of the radix tree. Modified: haiku/trunk/docs/develop/kernel/swap_file_support =================================================================== --- haiku/trunk/docs/develop/kernel/swap_file_support 2008-09-07 13:57:25 UTC (rev 27355) +++ haiku/trunk/docs/develop/kernel/swap_file_support 2008-09-07 13:58:49 UTC (rev 27356) @@ -72,14 +72,12 @@ Because in this way, we can easily tell if two adjacent pages are in a same swap file. (See the code in VMAnonymousCache::Read()). - Each swap file has a linear bitmap, and all pages in the swap file are -associated with a bit in the bitmap. When the page is used, the corresponding -bit is set to 1 and when free, it is set to 0. The linear bitmap is different -from FreeBSD. FreeBSD uses a radix bitmap and it's more efficient than linear -bitmap especially when swap space is fragmented. The reason why I did not use -a radix bitmap is I do not get a total understanding of radix tree structure -currently. But I will replace the linear bitmap with radix bitmap in the -future. + The efficiency of the FreeBSD swap system lies in a special data structure: +radix bitmap(i.e. bitmap using radix tree for hinting.) It can operate well no +matter how much fragmentation there is and no matter how large a bitmap is +used. I have ported the radix bitmap structure to Haiku, so our swap system +will have a good performance. More information on radix bitmap, please look +at the source code. Swap space allocation takes place when we swap anonymous pages out. In order to make the allocation less probable to fail, anonymous cache will From stippi at mail.berlios.de Sun Sep 7 16:18:02 2008 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Sun, 7 Sep 2008 16:18:02 +0200 Subject: [Haiku-commits] r27357 - in haiku/trunk: docs/apps docs/apps/diskusage src/apps src/apps/diskusage Message-ID: <200809071418.m87EI2Vj014773@sheep.berlios.de> Author: stippi Date: 2008-09-07 16:18:01 +0200 (Sun, 07 Sep 2008) New Revision: 27357 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27357&view=rev Added: haiku/trunk/docs/apps/diskusage/ haiku/trunk/docs/apps/diskusage/DiskUsage.html haiku/trunk/docs/apps/diskusage/home.png haiku/trunk/docs/apps/diskusage/icon.png haiku/trunk/src/apps/diskusage/ haiku/trunk/src/apps/diskusage/App.cpp haiku/trunk/src/apps/diskusage/App.h haiku/trunk/src/apps/diskusage/Common.cpp haiku/trunk/src/apps/diskusage/Common.h haiku/trunk/src/apps/diskusage/ControlsView.cpp haiku/trunk/src/apps/diskusage/ControlsView.h haiku/trunk/src/apps/diskusage/DiskUsage.rdef haiku/trunk/src/apps/diskusage/InfoWindow.cpp haiku/trunk/src/apps/diskusage/InfoWindow.h haiku/trunk/src/apps/diskusage/Jamfile haiku/trunk/src/apps/diskusage/MainWindow.cpp haiku/trunk/src/apps/diskusage/MainWindow.h haiku/trunk/src/apps/diskusage/PieView.cpp haiku/trunk/src/apps/diskusage/PieView.h haiku/trunk/src/apps/diskusage/Scanner.cpp haiku/trunk/src/apps/diskusage/Scanner.h haiku/trunk/src/apps/diskusage/Snapshot.cpp haiku/trunk/src/apps/diskusage/Snapshot.h haiku/trunk/src/apps/diskusage/StatusView.cpp haiku/trunk/src/apps/diskusage/StatusView.h haiku/trunk/src/apps/diskusage/TODO Modified: haiku/trunk/src/apps/Jamfile Log: Imported the nice disk usage tool "Guido" into the repo as "DiskUsage". Guido was originally written by Mike Steed. The code was freely available from his website at one point, which I am no longer able to find. I believe the license was a kind of public domain, at least compatible with our MIT/X11 license. The original code was well written with it's own coding style which was not very far from the Haiku coding style. I have hopefully adopted it completely to our coding style. While I did this, I came across several places with comments for a minor bug which I was able to resolve all. I also found ways to simplify certain places and I elliminated all non-necessary "inter-class knowledge" which was used to directly access members of other classes which should have been private. All in all, this should be a nice little addition, a useful tool which I found handy a lot of times. If I should not have added this without first consulting everyone, please voice your disagreement, and it can be removed it again. It is not part of the image yet. Added: haiku/trunk/docs/apps/diskusage/DiskUsage.html =================================================================== --- haiku/trunk/docs/apps/diskusage/DiskUsage.html 2008-09-07 13:58:49 UTC (rev 27356) +++ haiku/trunk/docs/apps/diskusage/DiskUsage.html 2008-09-07 14:18:01 UTC (rev 27357) @@ -0,0 +1,142 @@ + + +DiskUsage + + + + +
+
+

 DiskUsage
+Volume Utilization Visualizer

+ +
+ + +

What is it?

+ +DiskUsage shows a graphical representation of how the space on your +volumes is utilized. It uses concentric circles to represent different levels +in the file system hierarchy. It is useful for answering the question, "Where +has all my disk space gone?" And sometimes it's fun just to look at the +pictures.

+ +Here is a picture of DiskUsage in action, so to speak.

+ +

+ +The circle in the middle represents my /boot/home directory. +Each segment of the ring immediately outside that circle represents a file or +directory within /boot/home. And so on. + + +

Usage

+ +Startup. You can launch DiskUsage from the +Tracker, either directly or by dropping a volume or folder on its +icon; or from the Terminal, optionally passing the names of one +or more files or folders as arguments. If you launch DiskUsage +without specifying a volume, it will wait until you drop one or more volumes +or folders on its window or select a volume from the menu.

+ +While DiskUsage is scanning a volume, it displays a status bar +showing its progress. Multiple volumes are scanned in parallel (each in its +own thread). You can view the progress on a volume by selecting that volume +from the menu.

+ +The main display. When DiskUsage finishes scanning +a volume, it displays a graphical representation of the volume's files and +directories. As you move the mouse over each part of the picture, information +about each file or directory appears in the area at the bottom of the window. +You can resize the window to increase or decrease the number of levels that +DiskUsage displays.

+ +Zooming. You can "zoom" in on a directory by clicking the +primary mouse button on it. The picture is redrawn with that directory in the +center circle. You can zoom out one level by clicking the center circle. At +the outermost level, the center circle represents the volume itself, showing +free and used space as pie slices.

+ +Pop-up menu. Clicking the secondary mouse button on a part +of the picture pops up a menu with Tracker-like options +applicable to that file or directory. For directories, the menu includes an +option to rescan that directory and its subdirectories (not the entire +volume). This is useful since DiskUsage does not monitor changes +to the file system.

+ +Drag-and-drop. You can drag files and directories from +DiskUsage to other applications (or to the desktop, the trash, etc.) +with the primary mouse button. You can drop volumes and folders on +DiskUsage's window to zoom directly to them.

+ +Other controls. The buttons in the top right corner of the +DiskUsage window rescan the selected volume and display the +documentation (this file).

+ +Notes: + +

    + +
  • If the graphical representation of a file or directory comprises less +than about two degrees of a circle, it is excluded from the display. + +
  • The number of files that DiskUsage reports for a directory +includes files in subdirectories too. A directory counts as a file. + +
  • DiskUsage ignores symbolic links. + +
  • If you don't like the colors DiskUsage uses, you can change +them with your favorite resource editor. + +
+ + +

Credits, etc.

+ +Thanks to Steffen Gerlach for creating the Windows +Scanner +utility, from which I took the idea for using concentric circles to represent +disk usage.

+ +Thanks to the Vim development team for +creating the best programmer's editor on the planet, with which +DiskUsage's original code and documentation were lovingly +hand-crafted.

+ +Thanks to the folks at Be for creating such a kick-butt OS. It has made +programming fun again.

+ +Thanks to Mike Steed for doing the programming. All the code is original.

+ +DiskUsage used to be called guido by it's original +author. The name guido originated from GUI + du + -- the command-line disk usage utility. Plus, one of his favorite languages, +Python, was created by a fine programmer +named Guido. + + +

Known problems

+ +
    + +
  • You can drop multiple volumes or folders on the icon, but +DiskUsage sees only one of them. Why? + +
  • Dropping a floppy disk volume on DiskUsage's window works, but +dropping it on the icon does not work (unless you force it by holding the Ctrl +key while you drag). Why?! + +
+ + +

License

+ +DiskUsage is Copyright (c) 1999 Mike Steed. You are free to use +and distribute this software as long as it is accompanied by this documentation +and copyright notice. The software comes with no warranty, etc.

+ +


+ + + Added: haiku/trunk/docs/apps/diskusage/home.png =================================================================== (Binary files differ) Property changes on: haiku/trunk/docs/apps/diskusage/home.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: haiku/trunk/docs/apps/diskusage/icon.png =================================================================== (Binary files differ) Property changes on: haiku/trunk/docs/apps/diskusage/icon.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: haiku/trunk/src/apps/Jamfile =================================================================== --- haiku/trunk/src/apps/Jamfile 2008-09-07 13:58:49 UTC (rev 27356) +++ haiku/trunk/src/apps/Jamfile 2008-09-07 14:18:01 UTC (rev 27357) @@ -13,6 +13,7 @@ SubInclude HAIKU_TOP src apps deskbar ; SubInclude HAIKU_TOP src apps deskcalc ; SubInclude HAIKU_TOP src apps diskprobe ; +SubInclude HAIKU_TOP src apps diskusage ; SubInclude HAIKU_TOP src apps drivesetup ; SubInclude HAIKU_TOP src apps expander ; SubInclude HAIKU_TOP src apps fontdemo ; Added: haiku/trunk/src/apps/diskusage/App.cpp =================================================================== --- haiku/trunk/src/apps/diskusage/App.cpp 2008-09-07 13:58:49 UTC (rev 27356) +++ haiku/trunk/src/apps/diskusage/App.cpp 2008-09-07 14:18:01 UTC (rev 27357) @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2008 Stephan A?mus . All rights reserved. + * Distributed under the terms of the MIT/X11 license. + * + * Copyright (c) 1999 Mike Steed. You are free to use and distribute this software + * as long as it is accompanied by it's documentation and this copyright notice. + * The software comes with no warranty, etc. + */ +#include "App.h" + +#include + +#include +#include +#include +#include + +#include "Common.h" +#include "MainWindow.h" + + +App::App() + : BApplication(kAppSignature), + fResources(read_resources(kAppSignature)), + fMainWindow(NULL) +{ +} + + +App::~App() +{ + delete fResources; +} + + +void +App::ArgvReceived(int32 argc, char** argv) +{ + BMessage refsReceived(B_REFS_RECEIVED); + for (int32 i = 1; i < argc; i++) { + BEntry entry(argv[i], true); + entry_ref ref; + if (entry.GetRef(&ref) == B_OK) + refsReceived.AddRef("refs", &ref); + } + if (refsReceived.HasRef("refs")) + PostMessage(&refsReceived); +} + + +void +App::RefsReceived(BMessage* message) +{ + fMainWindow->PostMessage(message); +} + + +void +App::ReadyToRun() +{ + BRect frame; + + BPath path; + BFile settingsFile; + BMessage settings; + if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK + || path.Append("DiskUsage") != B_OK + || settingsFile.SetTo(path.Path(), B_READ_ONLY) != B_OK + || settings.Unflatten(&settingsFile) != B_OK + || settings.FindRect("window frame", &frame) != B_OK) { + // use default window frame + frame.Set(0, 0, kDefaultPieSize, kDefaultPieSize); + frame.OffsetTo(50, 50); + } + + fMainWindow = new MainWindow(frame); +} + + +bool +App::QuitRequested() +{ + // Save the settings. + BPath path; + BFile settingsFile; + BMessage settings; + if (settings.AddRect("window frame", fMainWindow->Frame()) != B_OK + || find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK + || path.Append("DiskUsage") != B_OK + || settingsFile.SetTo(path.Path(), B_WRITE_ONLY) != B_OK + || settings.Flatten(&settingsFile) != B_OK) { + fprintf(stderr, "Failed to write application settings.\n"); + } + + return BApplication::QuitRequested(); +} + + +// #pragma mark - + + +int +main() +{ + App app; + app.Run(); + return 0; +} + Added: haiku/trunk/src/apps/diskusage/App.h =================================================================== --- haiku/trunk/src/apps/diskusage/App.h 2008-09-07 13:58:49 UTC (rev 27356) +++ haiku/trunk/src/apps/diskusage/App.h 2008-09-07 14:18:01 UTC (rev 27357) @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2008 Stephan A?mus . All rights reserved. + * Distributed under the terms of the MIT/X11 license. + * + * Copyright (c) 1999 Mike Steed. You are free to use and distribute this software + * as long as it is accompanied by it's documentation and this copyright notice. + * The software comes with no warranty, etc. + */ +#ifndef APP_H +#define APP_H + +#include + + +class MainWindow; + +class App: public BApplication { +public: + App(); + virtual ~App(); + + virtual void ArgvReceived(int32 argc, char** argv); + virtual void RefsReceived(BMessage* message); + + virtual void ReadyToRun(); + virtual bool QuitRequested(); + +private: + BResources* fResources; + MainWindow* fMainWindow; +}; + +#endif // APP_H + Added: haiku/trunk/src/apps/diskusage/Common.cpp =================================================================== --- haiku/trunk/src/apps/diskusage/Common.cpp 2008-09-07 13:58:49 UTC (rev 27356) +++ haiku/trunk/src/apps/diskusage/Common.cpp 2008-09-07 14:18:01 UTC (rev 27357) @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2008 Stephan A?mus . All rights reserved. + * Distributed under the terms of the MIT/X11 license. + * + * Copyright (c) 1999 Mike Steed. You are free to use and distribute this software + * as long as it is accompanied by it's documentation and this copyright notice. + * The software comes with no warranty, etc. + */ +#define ASSIGN_RESOURCES +#include "Common.h" + +#include +#include + +#include +#include +#include +#include + + +BResources* +read_resources(const char* appSignature) +{ + status_t ret = be_app->GetAppInfo(&kAppInfo); + if (ret != B_OK) { + fprintf(stderr, "Failed to init application info: %s\n", + strerror(ret)); + exit(1); + } + + BFile file(&kAppInfo.ref, O_RDONLY); + ret = file.InitCheck(); + if (ret != B_OK) { + fprintf(stderr, "Failed to init application file to read resources: " + "%s\n", strerror(ret)); + exit(1); + } + + BResources* r = new BResources(&file); + +#define LoadString(n) (char*)r->LoadResource(B_STRING_TYPE, n, &ignore) +#define LoadColor(n) *(rgb_color*)r->LoadResource(B_RGB_COLOR_TYPE, n, &ignore) +#define LoadUint8(n) *(uint8*)r->LoadResource(B_UINT8_TYPE, n, &ignore) + + size_t ignore; + kVolMenuLabel = LoadString("STR_VM_LABEL"); + kOneFile = LoadString("STR_1_FILE"); + kManyFiles = LoadString("STR_N_FILES"); + kStrRescan = LoadString("STR_RESCAN"); + kStrScanningX = LoadString("STR_SCN_X"); + kStrUnavail = LoadString("STR_UNAVAIL"); + kVolMenuDefault = LoadString("STR_VM_DFLT"); + kVolPrompt = LoadString("STR_VPROMPT"); + kMenuGetInfo = LoadString("STR_M_INFO"); + kMenuOpen = LoadString("STR_M_OPEN"); + kMenuOpenWith = LoadString("STR_M_OPENW"); + kMenuNoApps = LoadString("STR_M_NAPPS"); + kInfoSize = LoadString("STR_SIZE"); + kInfoInFiles = LoadString("STR_INFILES"); + kInfoCreated = LoadString("STR_MADE"); + kInfoModified = LoadString("STR_MOD"); + kInfoTimeFmt = LoadString("STR_TIMEFMT"); + kInfoKind = LoadString("STR_KIND"); + kInfoPath = LoadString("STR_PATH"); + + kWindowColor = ui_color(B_PANEL_BACKGROUND_COLOR); + kOutlineColor = LoadColor("RGB_PIE_OL"); + kPieBGColor = LoadColor("RGB_PIE_BG"); + kEmptySpcColor = LoadColor("RGB_PIE_MT"); + + kBasePieColorCount = LoadUint8("N_PIE_COLORS"); + kBasePieColor = new rgb_color[kBasePieColorCount]; + for (int i = 0; i < kBasePieColorCount; i++) { + char colorName[16] = "RGB_PIE_n"; + colorName[8] = '1' + i; + kBasePieColor[i] = LoadColor(colorName); + } + + // Get a reference to the help file. + BPath path; + if (find_directory(B_BEOS_DOCUMENTATION_DIRECTORY, &path) == B_OK + && path.Append(kHelpFileName) == B_OK) { + printf("help file =? %s\n", path.Path()); + BEntry entry(path.Path()); + kFoundHelpFile = entry.Exists(); + entry.GetRef(&kHelpFileRef); + } else + kFoundHelpFile = false; + + + return r; +} + + +void +size_to_string(off_t byteCount, char* name) +{ + struct { + off_t limit; + float divisor; + char* format; + } scale[] = { + { 0x100000, 1024.0, "%.2f KB" }, + { 0x40000000, 1048576.0, "%.2f MB" }, + { 0x10000000000ull, 1073741824.0, "%.2f GB" }, + { 0x4000000000000ull, 1.09951162778e+12, "%.2f TB" } + }; + + if (byteCount < 1024) { + sprintf(name, "%lld bytes", byteCount); + } else { + int i = 0; + while (byteCount >= scale[i].limit) + i++; + + sprintf(name, scale[i].format, byteCount / scale[i].divisor); + } +} + Added: haiku/trunk/src/apps/diskusage/Common.h =================================================================== --- haiku/trunk/src/apps/diskusage/Common.h 2008-09-07 13:58:49 UTC (rev 27356) +++ haiku/trunk/src/apps/diskusage/Common.h 2008-09-07 14:18:01 UTC (rev 27357) @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2008 Stephan A?mus . All rights reserved. + * Distributed under the terms of the MIT/X11 license. + * + * Copyright (c) 1999 Mike Steed. You are free to use and distribute this software + * as long as it is accompanied by it's documentation and this copyright notice. + * The software comes with no warranty, etc. + */ +#ifndef COMMON_H +#define COMMON_H + +#include +#include +#include +#include + + +#ifdef ASSIGN_RESOURCES +# define EXTERN +# define EQ(x) =x +#else +# define EXTERN extern +# define EQ(x) +#endif + +#define PUBLIC_CONST extern const + + +// Resources +EXTERN char* kStrRescan; +EXTERN char* kStrScanningX; +EXTERN char* kStrUnavail; +EXTERN char* kVolMenuLabel; +EXTERN char* kVolMenuDefault; +EXTERN char* kVolPrompt; +EXTERN char* kOneFile; +EXTERN char* kManyFiles; +EXTERN char* kMenuGetInfo; +EXTERN char* kMenuOpen; +EXTERN char* kMenuOpenWith; +EXTERN char* kMenuNoApps; +EXTERN char* kInfoSize; +EXTERN char* kInfoInFiles; +EXTERN char* kInfoCreated; +EXTERN char* kInfoModified; +EXTERN char* kInfoTimeFmt; +EXTERN char* kInfoKind; +EXTERN char* kInfoPath; + +EXTERN rgb_color kWindowColor; +EXTERN rgb_color kOutlineColor; +EXTERN rgb_color kPieBGColor; +EXTERN rgb_color kEmptySpcColor; +EXTERN int kBasePieColorCount; +EXTERN rgb_color *kBasePieColor; + +// Non-resources :) +PUBLIC_CONST char* kAppSignature EQ("application/x-vnd.haiku-diskusage"); +PUBLIC_CONST char* kHelpFileName EQ("apps/diskusage/DiskUsage.html"); +PUBLIC_CONST char* kPieRectAttrName EQ("mainrect"); + +PUBLIC_CONST char* kHelpBtnLabel EQ("?"); +PUBLIC_CONST char* kEmptyStr EQ(""); +PUBLIC_CONST char* kNameVolPtr EQ("vol"); +PUBLIC_CONST char* kNameFilePtr EQ("file"); + +PUBLIC_CONST float kSmallHMargin EQ(5.0); +PUBLIC_CONST float kSmallVMargin EQ(2.0); +PUBLIC_CONST float kButtonMargin EQ(20.0); +PUBLIC_CONST float kMinButtonWidth EQ(60.0); + +PUBLIC_CONST float kProgBarWidth EQ(150.0); +PUBLIC_CONST float kProgBarHeight EQ(16.0); +PUBLIC_CONST float kReportInterval EQ(2.5); + +PUBLIC_CONST float kDefaultPieSize EQ(400.0); +PUBLIC_CONST float kPieCenterSize EQ(80.0); +PUBLIC_CONST float kPieRingSize EQ(20.0); +PUBLIC_CONST float kPieInnerMargin EQ(10.0); +PUBLIC_CONST float kPieOuterMargin EQ(10.0); +PUBLIC_CONST float kMinSegmentSpan EQ(2.0); +PUBLIC_CONST int kLightenFactor EQ(0x12); +PUBLIC_CONST float kDragThreshold EQ(5.0); + +EXTERN app_info kAppInfo; +EXTERN entry_ref kHelpFileRef; +EXTERN bool kFoundHelpFile; + +#define kMenuSelectVol 'gMSV' +#define kBtnRescan 'gBRF' +#define kBtnHelp 'gHLP' +#define kScanRefresh 'gSRF' +#define kScanProgress 'gSPR' +#define kScanDone 'gSDN' + +// support functions +#define max(x, y) ((x) > (y) ? (x) : (y)) +#define min(x, y) ((x) < (y) ? (x) : (y)) + +#define deg2rad(x) (2.0 * M_PI * (x) / 360.0) +#define rad2deg(x) (360.0 * (x) / (2.0 * M_PI)) + +BResources* read_resources(const char* appSignature); +void size_to_string(off_t byteCount, char* name); + +#endif // COMMON_H + Added: haiku/trunk/src/apps/diskusage/ControlsView.cpp =================================================================== --- haiku/trunk/src/apps/diskusage/ControlsView.cpp 2008-09-07 13:58:49 UTC (rev 27356) +++ haiku/trunk/src/apps/diskusage/ControlsView.cpp 2008-09-07 14:18:01 UTC (rev 27357) @@ -0,0 +1,298 @@ +/* + * Copyright (c) 2008 Stephan A?mus . All rights reserved. + * Distributed under the terms of the MIT/X11 license. + * + * Copyright (c) 1999 Mike Steed. You are free to use and distribute this software + * as long as it is accompanied by it's documentation and this copyright notice. + * The software comes with no warranty, etc. + */ +#include "ControlsView.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Common.h" + + +class VolumeMenuItem: public BMenuItem { +public: + VolumeMenuItem(BVolume* volume, BMessage* message); + virtual ~VolumeMenuItem(); + + virtual void GetContentSize(float* width, float* height); + virtual void DrawContent(); + + BVolume* Volume() const + { return fVolume; } + status_t Invoke() + { return BMenuItem::Invoke(); } + +private: + BBitmap* fIcon; + BVolume* fVolume; +}; + + +VolumeMenuItem::VolumeMenuItem(BVolume* volume, BMessage* message) + : BMenuItem(kEmptyStr, message), + fIcon(new BBitmap(BRect(0, 0, 15, 15), B_RGBA32)), + fVolume(volume) +{ + char name[B_PATH_NAME_LENGTH]; + fVolume->GetName(name); + SetLabel(name); + + if (fVolume->GetIcon(fIcon, B_MINI_ICON) < B_OK) { + delete fIcon; + fIcon = NULL; + } +} + + +VolumeMenuItem::~VolumeMenuItem() +{ + delete fIcon; + delete fVolume; +} + + +void +VolumeMenuItem::GetContentSize(float* width, float* height) +{ + *width = be_plain_font->StringWidth(Label()); + + struct font_height fh; + be_plain_font->GetHeight(&fh); + float fontHeight = fh.ascent + fh.descent + fh.leading; + if (fIcon) { + *height = max(fontHeight, fIcon->Bounds().Height()); + *width += fIcon->Bounds().Width() + kSmallHMargin; + } else + *height = fontHeight; +} + + +void +VolumeMenuItem::DrawContent() +{ + if (fIcon) { + Menu()->SetDrawingMode(B_OP_OVER); + Menu()->MovePenBy(0.0, -1.0); + Menu()->DrawBitmap(fIcon); + Menu()->SetDrawingMode(B_OP_COPY); + Menu()->MovePenBy(fIcon->Bounds().Width() + kSmallHMargin, 0.0); + } + BMenuItem::DrawContent(); +} + + +// #pragma mark - + + +class ControlsView::VolumePopup: public BMenuField { +public: + VolumePopup(BRect r); + virtual ~VolumePopup(); + + virtual void AttachedToWindow(); + virtual void MessageReceived(BMessage* message); + + BVolume* FindDeviceFor(dev_t device, + bool invoke = false); + +private: + void _AddVolume(dev_t device); + void _RemoveVolume(dev_t device); + + BVolumeRoster* fVolumeRoster; +}; + + +ControlsView::VolumePopup::VolumePopup(BRect r) + : BMenuField(r, NULL, kVolMenuLabel, new BPopUpMenu(kVolMenuDefault), + false, B_FOLLOW_LEFT) +{ + SetViewColor(kWindowColor); + SetLowColor(kWindowColor); + + SetDivider(kSmallHMargin + StringWidth(kVolMenuLabel)); + + // Populate the menu with the persistent volumes. + fVolumeRoster = new BVolumeRoster(); + + BVolume tempVolume; + while (fVolumeRoster->GetNextVolume(&tempVolume) == B_OK) { + if (tempVolume.IsPersistent()) { + BVolume* volume = new BVolume(tempVolume); + BMessage* message = new BMessage(kMenuSelectVol); + message->AddPointer(kNameVolPtr, volume); + VolumeMenuItem *item = new VolumeMenuItem(volume, message); + Menu()->AddItem(item); + } + } +} + + +ControlsView::VolumePopup::~VolumePopup() +{ + fVolumeRoster->StopWatching(); + delete fVolumeRoster; +} + + +void +ControlsView::VolumePopup::AttachedToWindow() +{ + // Begin watching mount and unmount events. + fVolumeRoster->StartWatching(BMessenger(this)); +} + + +void +ControlsView::VolumePopup::MessageReceived(BMessage* message) +{ + switch (message->what) { + case B_NODE_MONITOR: + switch (message->FindInt32("opcode")) { + case B_DEVICE_MOUNTED: + _AddVolume(message->FindInt32("new device")); + break; + + case B_DEVICE_UNMOUNTED: + _RemoveVolume(message->FindInt32("device")); + break; + } + break; + + default: + BMenuField::MessageReceived(message); + break; + } +} + + +BVolume* +ControlsView::VolumePopup::FindDeviceFor(dev_t device, bool invoke) +{ + BVolume* volume = NULL; + + // Iterate through items looking for a BVolume representing this device. + for (int i = 0; VolumeMenuItem* item = (VolumeMenuItem*)Menu()->ItemAt(i); i++) { + if (item->Volume()->Device() == device) { + volume = item->Volume(); + if (invoke) + item->Invoke(); + break; + } + } + + return volume; +} + + +void +ControlsView::VolumePopup::_AddVolume(dev_t device) +{ + // Make sure the volume is not already in the menu. + for (int i = 0; i < Menu()->CountItems(); i++) { + VolumeMenuItem* item = (VolumeMenuItem*)Menu()->ItemAt(i); + if (item->Volume()->Device() == device) + return; + } + + // Add the newly mounted volume to the menu. + BVolume* volume = new BVolume(device); + BMessage* message = new BMessage(kMenuSelectVol); + message->AddPointer(kNameVolPtr, volume); + VolumeMenuItem* item = new VolumeMenuItem(volume, message); + Menu()->AddItem(item); +} + + +void +ControlsView::VolumePopup::_RemoveVolume(dev_t device) +{ + for (int i = 0; i < Menu()->CountItems(); i++) { + VolumeMenuItem* item = (VolumeMenuItem*)Menu()->ItemAt(i); + if (item->Volume()->Device() == device) { + // If the volume being removed is currently selected, prompt for a + // different volume. + if (item->IsMarked()) { + // update the displayed volume label now that there is no marked + // item: + Menu()->Superitem()->SetLabel(kVolMenuDefault); + + BMessage messae(kMenuSelectVol); + messae.AddPointer(kNameVolPtr, NULL); + Window()->PostMessage(&messae); + } + + Menu()->RemoveItem(item); + return; + } + } +} + + +// #pragma mark - + + +ControlsView::ControlsView(BRect r) + : BView(r, NULL, B_FOLLOW_LEFT_RIGHT, 0) +{ + SetViewColor(kWindowColor); + + r.top += kSmallVMargin; + r.right -= kSmallHMargin; + float buttonWidth = kButtonMargin + StringWidth(kHelpBtnLabel); + r.left = r.right - buttonWidth; + BButton* helpButton = new BButton(r, NULL, kHelpBtnLabel, new BMessage(kBtnHelp), + B_FOLLOW_RIGHT); + if (!kFoundHelpFile) + helpButton->SetEnabled(false); + + r.right = r.left - kSmallHMargin; + buttonWidth = kButtonMargin + StringWidth(kStrRescan); + r.left = r.right - max(kMinButtonWidth, buttonWidth); + fRescanButton = new BButton(r, NULL, kStrRescan, new BMessage(kBtnRescan), + B_FOLLOW_RIGHT); + + fVolumePopup = new VolumePopup( + BRect(kSmallHMargin, kSmallVMargin, r.left - kSmallHMargin, kSmallVMargin)); + + float width, height; + fRescanButton->GetPreferredSize(&width, &height); + ResizeTo(Bounds().Width(), height + 6.0); + + // Horizontal divider + BRect r = Bounds(); + r.top = r.bottom - 1.0; + r.left -= 5.0; r.right += 5.0; + BBox* divider = new BBox(r, NULL, B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW); + + AddChild(fVolumePopup); + AddChild(divider); + AddChild(fRescanButton); + AddChild(helpButton); +} + + +ControlsView::~ControlsView() +{ +} + + +BVolume* +ControlsView::FindDeviceFor(dev_t device, bool invoke) +{ + return fVolumePopup->FindDeviceFor(device, invoke); +} + + Added: haiku/trunk/src/apps/diskusage/ControlsView.h =================================================================== --- haiku/trunk/src/apps/diskusage/ControlsView.h 2008-09-07 13:58:49 UTC (rev 27356) +++ haiku/trunk/src/apps/diskusage/ControlsView.h 2008-09-07 14:18:01 UTC (rev 27357) @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2008 Stephan A?mus . All rights reserved. + * Distributed under the terms of the MIT/X11 license. + * + * Copyright (c) 1999 Mike Steed. You are free to use and distribute this software + * as long as it is accompanied by it's documentation and this copyright notice. + * The software comes with no warranty, etc. + */ +#ifndef CONTROLS_VIEW_H +#define CONTROLS_VIEW_H + +#include +#include + + +class BVolume; + +class ControlsView: public BView { +public: + ControlsView(BRect r); + virtual ~ControlsView(); + + void SetRescanEnabled(bool enable) + { fRescanButton->SetEnabled(enable); } + + BVolume* FindDeviceFor(dev_t device, + bool invoke = false); + +private: + class VolumePopup; + + VolumePopup* fVolumePopup; + BButton* fRescanButton; +}; + + +#endif // CONTROLS_VIEW_H + Added: haiku/trunk/src/apps/diskusage/DiskUsage.rdef =================================================================== --- haiku/trunk/src/apps/diskusage/DiskUsage.rdef 2008-09-07 13:58:49 UTC (rev 27356) +++ haiku/trunk/src/apps/diskusage/DiskUsage.rdef 2008-09-07 14:18:01 UTC (rev 27357) @@ -0,0 +1,78 @@ +resource app_signature "application/x-vnd.haiku-diskusage"; + +resource app_version { + major = 1, + middle = 0, + minor = 0, + + variety = B_APPV_FINAL, + internal = 0, + + short_info = "1.0.1", + long_info = "1.0.1 (c) 1999 Mike Steed, (c) 2008 Haiku" +}; + +resource app_flags B_MULTIPLE_LAUNCH; + +resource file_types message { + "types" = "application/x-vnd.Be-volume", + "types" = "application/x-vnd.Be-directory" +}; + +resource vector_icon { + $"6E6369660F03010000020016023AF81C3830AFBB29EB3E24FE4903D742949400" + $"8EFF47020016023AFDE4B927BB3BBB443D89C84A587E467D6A007DFFB0020016" + $"023BFC1538B2EABB58DE3E788D4A21874591FF0096FFB0020006023C96323A4D" + $"3FBAFC013D5A974B57A549844D00474747FFA5A0A002001602BC592FBB29A73C" + $"0CE4BD0B7C4892C04B7966007DFFD40200060238DBB4399733BC4A333BA54248" + $"6E6649EE7B00596756FFEBB2B203A7FF0003FF0000040180020306033E800000" + $"00000000003DC00049E00049200000007F7F7EB1EAEAFF4F9DA4020306033E80" + $"000000000000003DC00049E00049200000E3B78D86F4F8C9F4888C9802030603" + $"3E80000000000000003DC00049E00049200000A9525286F5C0D3F4B05A660203" + $"06033E80000000000000003DC00049E00049200000888C9886EBEDF2F4888C98" + $"020016033D400000000000000040000048800000000000FF9BD3FFCD0F0A0622" + $"3C2249445B5A3E5A3139250A05223C2246B54AC1D7393239250A055A31392539" + $"32C7D0BE1E5A3C0A043932B4CBC2564458C921BE980A04444B445B5A3E5A310A" + $"04223C2249445B444B08022743B814C1F10802264329440A05445D495D603E5A" + $"3B5B3F02043F2EC3882EBB2B2E2C3A2CBAB82CBFFF3F46BB2B46C38846523A52" + $"BFFF52BAB80604BF3E2E3E2EBAF2B8B32C3A2CBACC2CBDF9B84CBF1AB7F7BE90" + $"B84CBF1A3E3906033E4039C6D5BCA1C6D5BCA1C651BA7FC024B89AC392B8D4C0" + $"24B89A0604FE3F3AB915C00AB915C00ABA72C14E3F46BCBE46C33846C6DDBDF1" + $"C668C04FC6DDBDF10204423942BCBD42BD2E3F3AC0023ABEB13A3C393CBD2E3C" + $"BCBD3F38BEB138C002380A04233C444B59323926110A090108000A0001001001" + $"178400040A010101000A020102000A030103000A00030A0B0C1001178402040A" + $"0A010A000A0B010B000A0C010C000A00010D1001178400040A0D010D000A0401" + $"04000A050105000A0601061001178520040A0801073024B39901178200040A07" + $"01073020B2E601178200040A0E010E1815FF0117812204" +}; + +resource(101, "RGB_WIN") rgb_color { 0xDE, 0xDB, 0xDE, 0xFF }; +resource(102, "RGB_PIE_OL") rgb_color { 0x80, 0x80, 0x80, 0xFF }; +resource(103, "RGB_PIE_BG") rgb_color { 0xFF, 0xFF, 0xFF, 0xFF }; +resource(104, "RGB_PIE_MT") rgb_color { 0xA0, 0xA0, 0xA0, 0xFF }; +resource(105, "RGB_PIE_1") rgb_color { 0x00, 0x60, 0x60, 0xFF }; +resource(106, "RGB_PIE_2") rgb_color { 0x00, 0x00, 0x68, 0xFF }; +resource(107, "RGB_PIE_3") rgb_color { 0x60, 0x00, 0x60, 0xFF }; +resource(108, "RGB_PIE_4") rgb_color { 0x68, 0x00, 0x00, 0xFF }; + +resource(101, "N_PIE_COLORS") (uint8)4; + +resource(103, "STR_N_FILES") "%d files"; +resource(102, "STR_1_FILE") "%d file"; +resource(101, "STR_VM_LABEL") "Volume:"; +resource(104, "STR_RESCAN") "Rescan"; +resource(105, "STR_SCN_X") "Scanning "; +resource(106, "STR_UNAVAIL") "file unavailable"; +resource(107, "STR_VM_DFLT") "(Select)"; +resource(108, "STR_VPROMPT") "Select a volume to scan"; +resource(109, "STR_M_INFO") "Get Info"; +resource(110, "STR_M_OPEN") "Open"; +resource(111, "STR_M_OPENW") "Open With"; +resource(112, "STR_M_NAPPS") "no supporting apps"; +resource(113, "STR_SIZE") "Size"; +resource(114, "STR_INFILES") " in %d files"; [... truncated: 2149 lines follow ...] From bonefish at mail.berlios.de Sun Sep 7 16:22:53 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sun, 7 Sep 2008 16:22:53 +0200 Subject: [Haiku-commits] r27358 - haiku/trunk/src/tests/system/kernel Message-ID: <200809071422.m87EMrQr015083@sheep.berlios.de> Author: bonefish Date: 2008-09-07 16:22:53 +0200 (Sun, 07 Sep 2008) New Revision: 27358 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27358&view=rev Modified: haiku/trunk/src/tests/system/kernel/time_stats.cpp Log: * More verbose usage text. * Parse the command line options posixly correct. Running command lines that contained options was broken before. Modified: haiku/trunk/src/tests/system/kernel/time_stats.cpp =================================================================== --- haiku/trunk/src/tests/system/kernel/time_stats.cpp 2008-09-07 14:18:01 UTC (rev 27357) +++ haiku/trunk/src/tests/system/kernel/time_stats.cpp 2008-09-07 14:22:53 UTC (rev 27358) @@ -32,7 +32,16 @@ extern const char* __progname; static const char* kUsage = - "Usage: %s [ -h ] [ -o ] [ -s ] \n" + "Usage: %s [ ] \n" + "Executes the given command line and print an analysis of\n" + "the user and kernel times of all threads that ran during that time.\n" + "\n" + "Options:\n" + " -h, --help - Print this usage info.\n" + " -o - Print the results to file .\n" + " -s - Also perform a scheduling analysis over the time the\n" + " child process ran. This requires that scheduler kernel\n" + " tracing had been enabled at compile time.\n" ; @@ -487,7 +496,7 @@ }; opterr = 0; // don't print errors - int c = getopt_long(argc, (char**)argv, "ho:s", sLongOptions, NULL); + int c = getopt_long(argc, (char**)argv, "+ho:s", sLongOptions, NULL); if (c == -1) break; From bonefish at mail.berlios.de Sun Sep 7 17:27:20 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sun, 7 Sep 2008 17:27:20 +0200 Subject: [Haiku-commits] r27359 - haiku/trunk/headers/private/libroot Message-ID: <200809071527.m87FRKDl020171@sheep.berlios.de> Author: bonefish Date: 2008-09-07 17:27:14 +0200 (Sun, 07 Sep 2008) New Revision: 27359 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27359&view=rev Modified: haiku/trunk/headers/private/libroot/libroot_lock.h Log: * Retry in benaphore_lock() when interrupted. * Added TODO in benaphore_lock_etc(). Modified: haiku/trunk/headers/private/libroot/libroot_lock.h =================================================================== --- haiku/trunk/headers/private/libroot/libroot_lock.h 2008-09-07 14:22:53 UTC (rev 27358) +++ haiku/trunk/headers/private/libroot/libroot_lock.h 2008-09-07 15:27:14 UTC (rev 27359) @@ -42,6 +42,8 @@ static inline status_t benaphore_lock_etc(benaphore *ben, uint32 flags, bigtime_t timeout) { +// TODO: This function really shouldn't be used, since timeouts screw the +// benaphore behavior. if (atomic_add(&ben->count, -1) <= 0) return acquire_sem_etc(ben->sem, 1, flags, timeout); @@ -52,9 +54,15 @@ static inline status_t benaphore_lock(benaphore *ben) { - if (atomic_add(&ben->count, -1) <= 0) - return acquire_sem(ben->sem); + if (atomic_add(&ben->count, -1) <= 0) { + status_t error; + do { + error = acquire_sem(ben->sem); + } while (error == B_INTERRUPTED); + return error; + } + return B_OK; } From bonefish at mail.berlios.de Sun Sep 7 17:28:40 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sun, 7 Sep 2008 17:28:40 +0200 Subject: [Haiku-commits] r27360 - haiku/trunk/src/system/libroot/posix/stdlib Message-ID: <200809071528.m87FSeNF020309@sheep.berlios.de> Author: bonefish Date: 2008-09-07 17:28:39 +0200 (Sun, 07 Sep 2008) New Revision: 27360 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27360&view=rev Added: haiku/trunk/src/system/libroot/posix/stdlib/env.cpp Removed: haiku/trunk/src/system/libroot/posix/stdlib/env.c Modified: haiku/trunk/src/system/libroot/posix/stdlib/Jamfile Log: * env.c -> env.cpp * Squashed TODO: Use a benaphore for locking to improve performance. Modified: haiku/trunk/src/system/libroot/posix/stdlib/Jamfile =================================================================== --- haiku/trunk/src/system/libroot/posix/stdlib/Jamfile 2008-09-07 15:27:14 UTC (rev 27359) +++ haiku/trunk/src/system/libroot/posix/stdlib/Jamfile 2008-09-07 15:28:39 UTC (rev 27360) @@ -6,19 +6,19 @@ MergeObject posix_stdlib.o : abs.c atfork.c - atof.c - atoi.c + atof.c + atoi.c bsearch.c - div.c - env.c + div.c + env.cpp exit.c - heapsort.c + heapsort.c merge.c mktemp.c pty.cpp - qsort.c - radixsort.c - rand.c + qsort.c + radixsort.c + rand.c random.c realpath.c strtod.c Deleted: haiku/trunk/src/system/libroot/posix/stdlib/env.c Copied: haiku/trunk/src/system/libroot/posix/stdlib/env.cpp (from rev 27353, haiku/trunk/src/system/libroot/posix/stdlib/env.c) =================================================================== --- haiku/trunk/src/system/libroot/posix/stdlib/env.c 2008-09-07 10:43:43 UTC (rev 27353) +++ haiku/trunk/src/system/libroot/posix/stdlib/env.cpp 2008-09-07 15:28:39 UTC (rev 27360) @@ -0,0 +1,317 @@ +/* + * Copyright 2004-2008, Axel D?rfler, axeld at pinc-software.de. + * Distributed under the terms of the MIT License. + */ + + +#include +#include +#include +#include + +#include + +#include +#include +#include + + +#define RETURN_AND_SET_ERRNO(err) \ + if (err < 0) { \ + errno = err; \ + return -1; \ + } \ + return err; + + +static benaphore sEnvLock; +static char **sManagedEnviron; + +char **environ = NULL; + + +static inline void +lock_variables(void) +{ + benaphore_lock(&sEnvLock); +} + + +static inline void +unlock_variables(void) +{ + benaphore_unlock(&sEnvLock); +} + + +static void +free_variables(void) +{ + int32 i; + + if (sManagedEnviron == NULL) + return; + + for (i = 0; sManagedEnviron[i] != NULL; i++) { + free(sManagedEnviron[i]); + } + + free(sManagedEnviron); + sManagedEnviron = NULL; +} + + +static int32 +count_variables(void) +{ + int32 i = 0; + + if (environ == NULL) + return 0; + + while (environ[i]) + i++; + + return i; +} + + +static int32 +add_variable(void) +{ + int32 count = count_variables() + 1; + char **newEnviron = (char**)realloc(environ, (count + 1) * sizeof(char *)); + if (newEnviron == NULL) + return B_NO_MEMORY; + + newEnviron[count] = NULL; + // null terminate the array + + environ = sManagedEnviron = newEnviron; + + return count - 1; +} + + +static char * +find_variable(const char *name, int32 length, int32 *_index) +{ + int32 i; + + if (environ == NULL) + return NULL; + + for (i = 0; environ[i] != NULL; i++) { + if (!strncmp(name, environ[i], length) && environ[i][length] == '=') { + if (_index != NULL) + *_index = i; + return environ[i]; + } + } + + return NULL; +} + + +/*! Copies the environment from its current location into a heap managed + environment, if it's not already there. + + This is needed whenever the environment is changed, that is, when one + of the POSIX *env() functions is called, and we either used the environment + provided by the kernel, or by an application that changed \c environ + directly. +*/ +static status_t +copy_environ_to_heap_if_needed(void) +{ + int32 i = 0; + + if (environ == sManagedEnviron) + return B_OK; + + // free previously used "environ" if it has been changed by an application + free_variables(); + + sManagedEnviron = (char**)malloc((count_variables() + 1) * sizeof(char *)); + if (sManagedEnviron == NULL) + return B_NO_MEMORY; + + if (environ != NULL) { + // copy from previous + for (; environ[i]; i++) { + sManagedEnviron[i] = strdup(environ[i]); + } + } + + sManagedEnviron[i] = NULL; + // null terminate the array + + environ = sManagedEnviron; + return B_OK; +} + + +static status_t +update_variable(const char *name, int32 length, const char *value, + bool overwrite) +{ + bool update = false; + int32 index; + char *env; + + copy_environ_to_heap_if_needed(); + + env = find_variable(name, length, &index); + if (env != NULL && overwrite) { + // change variable + free(environ[index]); + update = true; + } else if (env == NULL) { + // add variable + index = add_variable(); + if (index < 0) + return B_NO_MEMORY; + + update = true; + } + + if (update) { + environ[index] = (char*)malloc(length + 2 + strlen(value)); + if (environ[index] == NULL) + return B_NO_MEMORY; + + memcpy(environ[index], name, length); + environ[index][length] = '='; + strcpy(environ[index] + length + 1, value); + } + + return B_OK; +} + + +static void +environ_fork_hook(void) +{ + benaphore_init(&sEnvLock, "env lock"); +} + + +// #pragma mark - libroot initializer + + +void +__init_env(const struct user_space_program_args *args) +{ + // Following POSIX, there is no need to make any of the environment + // functions thread-safe - but we do it anyway as much as possible to + // protect our implementation + benaphore_init(&sEnvLock, "env lock"); + environ = args->env; + sManagedEnviron = NULL; + + atfork(environ_fork_hook); +} + + +// #pragma mark - public API + + +int +clearenv(void) +{ + lock_variables(); + + free_variables(); + environ = NULL; + + unlock_variables(); + + return 0; +} + + +char * +getenv(const char *name) +{ + int32 length = strlen(name); + char *value; + + lock_variables(); + + value = find_variable(name, length, NULL); + unlock_variables(); + + if (value == NULL) + return NULL; + + return value + length + 1; +} + + +int +setenv(const char *name, const char *value, int overwrite) +{ + status_t status; + + if (name == NULL || name[0] == '\0' || strchr(name, '=') != NULL) { + errno = B_BAD_VALUE; + return -1; + } + + lock_variables(); + status = update_variable(name, strlen(name), value, overwrite); + unlock_variables(); + + RETURN_AND_SET_ERRNO(status); +} + + +int +unsetenv(const char *name) +{ + int32 index, length; + char *env; + + if (name == NULL || name[0] == '\0' || strchr(name, '=') != NULL) { + errno = B_BAD_VALUE; + return -1; + } + + length = strlen(name); + + lock_variables(); + + copy_environ_to_heap_if_needed(); + + env = find_variable(name, length, &index); + if (env != NULL) { + // we don't free the memory for the slot, we just move the array + // contents + free(env); + memmove(environ + index, environ + index + 1, + sizeof(char *) * (count_variables() - index)); + } + + unlock_variables(); + return 0; +} + + +int +putenv(const char *string) +{ + char *value = strchr(string, '='); + status_t status; + + if (value == NULL) { + errno = B_BAD_VALUE; + return -1; + } + + lock_variables(); + status = update_variable(string, value - string, value + 1, true); + unlock_variables(); + + RETURN_AND_SET_ERRNO(status); +} + From korli at mail.berlios.de Sun Sep 7 18:26:44 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Sun, 7 Sep 2008 18:26:44 +0200 Subject: [Haiku-commits] r27361 - haiku/trunk/src/add-ons/kernel/drivers/audio/hda Message-ID: <200809071626.m87GQiMO029063@sheep.berlios.de> Author: korli Date: 2008-09-07 18:26:44 +0200 (Sun, 07 Sep 2008) New Revision: 27361 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27361&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_multi_audio.cpp Log: added missing 20bit case Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_multi_audio.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_multi_audio.cpp 2008-09-07 15:28:39 UTC (rev 27360) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_multi_audio.cpp 2008-09-07 16:26:44 UTC (rev 27361) @@ -48,6 +48,7 @@ return 2; case B_FMT_18BIT: + case B_FMT_20BIT: case B_FMT_24BIT: case B_FMT_32BIT: case B_FMT_FLOAT: From korli at mail.berlios.de Sun Sep 7 18:36:16 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Sun, 7 Sep 2008 18:36:16 +0200 Subject: [Haiku-commits] r27362 - in haiku/trunk/src/add-ons: kernel/drivers/audio/echo media/media-add-ons/mixer Message-ID: <200809071636.m87GaGWx005596@sheep.berlios.de> Author: korli Date: 2008-09-07 18:36:10 +0200 (Sun, 07 Sep 2008) New Revision: 27362 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27362&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/echo/echo.cpp haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerCore.cpp haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerInput.cpp haiku/trunk/src/add-ons/media/media-add-ons/mixer/Resampler.cpp haiku/trunk/src/add-ons/media/media-add-ons/mixer/Resampler.h Log: * I misunderstood what means 24 bits B_AUDIO_INT (more than 2 years ago!): as audio data is left justified in a 32 bits container, we don't care much and convert as usual 32 bits data * Echo audio driver doesn't support 24 bits in a 32 bits container as proposed by the media kit. We just manage 24 bits as 32 bits samples. * The main benefit of this change is that the hda driver is now working with 24 bits samples (and 192khz). Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/echo/echo.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/echo/echo.cpp 2008-09-07 16:26:44 UTC (rev 27361) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/echo/echo.cpp 2008-09-07 16:36:10 UTC (rev 27362) @@ -204,6 +204,9 @@ PRINT((" status: %s \n", pStatusStrs[status])); return B_ERROR; } + + if (bitsPerSample == 24) + bitsPerSample = 32; if ((stream->channels == channels) && (stream->bitsPerSample == bitsPerSample) && Modified: haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerCore.cpp =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerCore.cpp 2008-09-07 16:26:44 UTC (rev 27361) +++ haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerCore.cpp 2008-09-07 16:36:10 UTC (rev 27362) @@ -263,8 +263,7 @@ fResampler = new Resampler * [fMixBufferChannelCount]; for (int i = 0; i < fMixBufferChannelCount; i++) fResampler[i] = new Resampler(media_raw_audio_format::B_AUDIO_FLOAT, - format.format, - format.valid_bits); + format.format); TRACE("MixerCore::OutputFormatChanged:\n"); TRACE(" fMixBufferFrameRate %ld\n", fMixBufferFrameRate); Modified: haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerInput.cpp =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerInput.cpp 2008-09-07 16:26:44 UTC (rev 27361) +++ haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerInput.cpp 2008-09-07 16:36:10 UTC (rev 27362) @@ -67,7 +67,7 @@ // create resamplers fResampler = new Resampler * [fInputChannelCount]; for (int i = 0; i < fInputChannelCount; i++) - fResampler[i] = new Resampler(fInput.format.u.raw_audio.format, media_raw_audio_format::B_AUDIO_FLOAT, 0); + fResampler[i] = new Resampler(fInput.format.u.raw_audio.format, media_raw_audio_format::B_AUDIO_FLOAT); // fMixerChannelInfo and fMixerChannelCount will be initialized by UpdateInputChannelDestinations() SetMixBufferFormat((int32)mixFrameRate, mixFrameCount); Modified: haiku/trunk/src/add-ons/media/media-add-ons/mixer/Resampler.cpp =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/mixer/Resampler.cpp 2008-09-07 16:26:44 UTC (rev 27361) +++ haiku/trunk/src/add-ons/media/media-add-ons/mixer/Resampler.cpp 2008-09-07 16:36:10 UTC (rev 27362) @@ -13,7 +13,7 @@ #include "Resampler.h" #include "MixerDebug.h" -Resampler::Resampler(uint32 src_format, uint32 dst_format, int16 dst_valid_bits) +Resampler::Resampler(uint32 src_format, uint32 dst_format) : fFunc(0) { if (dst_format == media_raw_audio_format::B_AUDIO_FLOAT) { @@ -43,11 +43,7 @@ switch (dst_format) { // float=>float already handled above case media_raw_audio_format::B_AUDIO_INT: - fFunc = &Resampler::float_to_int32_32; - if (dst_valid_bits == 24) - fFunc = &Resampler::float_to_int32_24; - else if (dst_valid_bits == 20) - fFunc = &Resampler::float_to_int32_20; + fFunc = &Resampler::float_to_int32; return; case media_raw_audio_format::B_AUDIO_SHORT: fFunc = &Resampler::float_to_int16; @@ -308,7 +304,7 @@ } void -Resampler::float_to_int32_32(const void *_src, int32 src_sample_offset, int32 src_sample_count, +Resampler::float_to_int32(const void *_src, int32 src_sample_offset, int32 src_sample_count, void *_dst, int32 dst_sample_offset, int32 dst_sample_count, float _gain) { register const char * src = (const char *) _src; @@ -373,136 +369,6 @@ void -Resampler::float_to_int32_24(const void *_src, int32 src_sample_offset, int32 src_sample_count, - void *_dst, int32 dst_sample_offset, int32 dst_sample_count, float _gain) -{ - register const char * src = (const char *) _src; - register char * dst = (char *) _dst; - register int32 count = dst_sample_count; - register float gain = _gain * 8388607.0; - - if (src_sample_count == dst_sample_count) { - // optimized case for no resampling - while (count--) { - register float sample = *(const float *)src * gain; - if (sample > 8388607.0f) - *(int32 *)dst = 8388607L; - else if (sample < -8388607.0f) - *(int32 *)dst = -8388607L; - else - *(int32 *)dst = (int32)sample; - src += src_sample_offset; - dst += dst_sample_offset; - } - return; - } - - register float delta = float(src_sample_count) / float(dst_sample_count); - register float current = 0.0f; - - if (delta < 1.0) { - // upsample - while (count--) { - register float sample = *(const float *)src * gain; - if (sample > 8388607.0f) - *(int32 *)dst = 8388607L; - else if (sample < -8388607.0f) - *(int32 *)dst = -8388607L; - else - *(int32 *)dst = (int32)sample; - dst += dst_sample_offset; - current += delta; - if (current >= 1.0f) { - current -= 1.0f; - src += src_sample_offset; - } - } - } else { - // downsample - while (count--) { - register float sample = *(const float *)src * gain; - if (sample > 8388607.0f) - *(int32 *)dst = 8388607L; - else if (sample < -8388607.0f) - *(int32 *)dst = -8388607L; - else - *(int32 *)dst = (int32)sample; - dst += dst_sample_offset; - current += delta; - register int32 skipcount = (int32)current; - current -= skipcount; - src += skipcount * src_sample_offset; - } - } -} - - -void -Resampler::float_to_int32_20(const void *_src, int32 src_sample_offset, int32 src_sample_count, - void *_dst, int32 dst_sample_offset, int32 dst_sample_count, float _gain) -{ - register const char * src = (const char *) _src; - register char * dst = (char *) _dst; - register int32 count = dst_sample_count; - register float gain = _gain * 524287.0; - - if (src_sample_count == dst_sample_count) { - // optimized case for no resampling - while (count--) { - register float sample = *(const float *)src * gain; - if (sample > 524287.0f) - *(int32 *)dst = 524287L; - else if (sample < -524287.0f) - *(int32 *)dst = -524287L; - else - *(int32 *)dst = (int32)sample; - src += src_sample_offset; - dst += dst_sample_offset; - } - return; - } - - register float delta = float(src_sample_count) / float(dst_sample_count); - register float current = 0.0f; - - if (delta < 1.0) { - // upsample - while (count--) { - register float sample = *(const float *)src * gain; - if (sample > 524287.0f) - *(int32 *)dst = 524287L; - else if (sample < -524287.0f) - *(int32 *)dst = -524287L; - else - *(int32 *)dst = (int32)sample; - dst += dst_sample_offset; - current += delta; - if (current >= 1.0f) { - current -= 1.0f; - src += src_sample_offset; - } - } - } else { - // downsample - while (count--) { - register float sample = *(const float *)src * gain; - if (sample > 524287.0f) - *(int32 *)dst = 524287L; - else if (sample < -524287.0f) - *(int32 *)dst = -524287L; - else - *(int32 *)dst = (int32)sample; - dst += dst_sample_offset; - current += delta; - register int32 skipcount = (int32)current; - current -= skipcount; - src += skipcount * src_sample_offset; - } - } -} - - -void Resampler::float_to_int16(const void *_src, int32 src_sample_offset, int32 src_sample_count, void *_dst, int32 dst_sample_offset, int32 dst_sample_count, float _gain) { Modified: haiku/trunk/src/add-ons/media/media-add-ons/mixer/Resampler.h =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/mixer/Resampler.h 2008-09-07 16:26:44 UTC (rev 27361) +++ haiku/trunk/src/add-ons/media/media-add-ons/mixer/Resampler.h 2008-09-07 16:36:10 UTC (rev 27362) @@ -14,7 +14,7 @@ class Resampler { public: - Resampler(uint32 sourceformat, uint32 destformat, int16 dst_valid_bits); + Resampler(uint32 sourceformat, uint32 destformat); virtual ~Resampler(); status_t InitCheck(); @@ -33,12 +33,8 @@ void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain); virtual void uint8_to_float (const void *src, int32 src_sample_offset, int32 src_sample_count, void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain); - virtual void float_to_int32_32 (const void *src, int32 src_sample_offset, int32 src_sample_count, + virtual void float_to_int32 (const void *src, int32 src_sample_offset, int32 src_sample_count, void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain); - virtual void float_to_int32_24 (const void *src, int32 src_sample_offset, int32 src_sample_count, - void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain); - virtual void float_to_int32_20 (const void *src, int32 src_sample_offset, int32 src_sample_count, - void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain); virtual void float_to_int16 (const void *src, int32 src_sample_offset, int32 src_sample_count, void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain); virtual void float_to_int8 (const void *src, int32 src_sample_offset, int32 src_sample_count, From korli at mail.berlios.de Sun Sep 7 22:59:32 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Sun, 7 Sep 2008 22:59:32 +0200 Subject: [Haiku-commits] r27363 - haiku/trunk/headers/os/kernel Message-ID: <200809072059.m87KxWfV009986@sheep.berlios.de> Author: korli Date: 2008-09-07 22:59:30 +0200 (Sun, 07 Sep 2008) New Revision: 27363 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27363&view=rev Modified: haiku/trunk/headers/os/kernel/OS.h Log: fixed Atom id. Thanks katisu! Modified: haiku/trunk/headers/os/kernel/OS.h =================================================================== --- haiku/trunk/headers/os/kernel/OS.h 2008-09-07 16:36:10 UTC (rev 27362) +++ haiku/trunk/headers/os/kernel/OS.h 2008-09-07 20:59:30 UTC (rev 27363) @@ -476,7 +476,7 @@ B_CPU_INTEL_PENTIUM_M = 0x1069, B_CPU_INTEL_PENTIUM_III_XEON = 0x106a, B_CPU_INTEL_PENTIUM_III_MODEL_11 = 0x106b, - B_CPU_INTEL_ATOM = 0x106c, + B_CPU_INTEL_ATOM = 0x1106c, B_CPU_INTEL_PENTIUM_M_MODEL_13 = 0x106d, /* Dothan */ B_CPU_INTEL_PENTIUM_CORE, B_CPU_INTEL_PENTIUM_CORE_2, From bonefish at mail.berlios.de Mon Sep 8 02:50:28 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Mon, 8 Sep 2008 02:50:28 +0200 Subject: [Haiku-commits] r27364 - haiku/trunk/src/tests/system/kernel Message-ID: <200809080050.m880oSpi022607@sheep.berlios.de> Author: bonefish Date: 2008-09-08 02:50:27 +0200 (Mon, 08 Sep 2008) New Revision: 27364 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27364&view=rev Added: haiku/trunk/src/tests/system/kernel/path_resolution_test.cpp Modified: haiku/trunk/src/tests/system/kernel/Jamfile Log: Small test program timing our path resolution. Which sucks badly... Modified: haiku/trunk/src/tests/system/kernel/Jamfile =================================================================== --- haiku/trunk/src/tests/system/kernel/Jamfile 2008-09-07 20:59:30 UTC (rev 27363) +++ haiku/trunk/src/tests/system/kernel/Jamfile 2008-09-08 00:50:27 UTC (rev 27364) @@ -18,6 +18,8 @@ SimpleTest page_fault_cache_merge_test : page_fault_cache_merge_test.cpp ; +SimpleTest path_resolution_test : path_resolution_test.cpp ; + SimpleTest port_close_test_1 : port_close_test_1.cpp ; SimpleTest port_close_test_2 : port_close_test_2.cpp ; Added: haiku/trunk/src/tests/system/kernel/path_resolution_test.cpp =================================================================== --- haiku/trunk/src/tests/system/kernel/path_resolution_test.cpp 2008-09-07 20:59:30 UTC (rev 27363) +++ haiku/trunk/src/tests/system/kernel/path_resolution_test.cpp 2008-09-08 00:50:27 UTC (rev 27364) @@ -0,0 +1,48 @@ +/* + * Copyright 2008, Ingo Weinhold, ingo_weinhold at gmx.de. + * Distributed under the terms of the MIT License. + */ + +#include +#include + +#include + + +static void +time_lstat(const char* path) +{ + printf("%-60s ...", path); + fflush(stdout); + bigtime_t startTime = system_time(); + + static const int32 iterations = 10000; + for (int32 i = 0; i < iterations; i++) { + struct stat st; + lstat(path, &st); + } + + bigtime_t totalTime = system_time() - startTime; + printf(" %5.3f us/call\n", (double)totalTime / iterations); +} + + +int +main() +{ + const char* const paths[] = { + "/", + "/boot", + "/boot/develop", + "/boot/develop/headers", + "/boot/develop/headers/posix", + "/boot/develop/headers/posix/sys", + "/boot/develop/headers/posix/sys/stat.h", + NULL + }; + + for (int32 i = 0; paths[i] != NULL; i++) + time_lstat(paths[i]); + + return 0; +} From anevilyak at mail.berlios.de Mon Sep 8 04:45:17 2008 From: anevilyak at mail.berlios.de (anevilyak at BerliOS) Date: Mon, 8 Sep 2008 04:45:17 +0200 Subject: [Haiku-commits] r27365 - in haiku/trunk/src/add-ons/kernel: busses/agp_gart drivers/graphics/intel_extreme Message-ID: <200809080245.m882jHhh002969@sheep.berlios.de> Author: anevilyak Date: 2008-09-08 04:45:14 +0200 (Mon, 08 Sep 2008) New Revision: 27365 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27365&view=rev Modified: haiku/trunk/src/add-ons/kernel/busses/agp_gart/intel_gart.cpp haiku/trunk/src/add-ons/kernel/drivers/graphics/intel_extreme/driver.cpp Log: Patch by Dustin Howett: Add i945GME to the supported devices list (caveat: no overlay). Thanks! Modified: haiku/trunk/src/add-ons/kernel/busses/agp_gart/intel_gart.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/agp_gart/intel_gart.cpp 2008-09-08 00:50:27 UTC (rev 27364) +++ haiku/trunk/src/add-ons/kernel/busses/agp_gart/intel_gart.cpp 2008-09-08 02:45:14 UTC (rev 27365) @@ -56,6 +56,7 @@ {0x2590, 0x2592, INTEL_TYPE_91x, "i915GM"}, {0x2770, 0x2772, INTEL_TYPE_945, "i945G"}, {0x27a0, 0x27a2, INTEL_TYPE_945, "i945GM"}, + {0x27ac, 0x27ae, INTEL_TYPE_945, "i945GME"}, {0x2970, 0x2972, INTEL_TYPE_965, "i946GZ"}, {0x2980, 0x2982, INTEL_TYPE_965, "i965G"}, Modified: haiku/trunk/src/add-ons/kernel/drivers/graphics/intel_extreme/driver.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/graphics/intel_extreme/driver.cpp 2008-09-08 00:50:27 UTC (rev 27364) +++ haiku/trunk/src/add-ons/kernel/drivers/graphics/intel_extreme/driver.cpp 2008-09-08 02:45:14 UTC (rev 27365) @@ -48,6 +48,7 @@ {0x2592, INTEL_TYPE_91x, "i915GM"}, {0x2772, INTEL_TYPE_945, "i945G"}, {0x27a2, INTEL_TYPE_945, "i945GM"}, + {0x27ae, INTEL_TYPE_945, "i945GME"}, {0x29a2, INTEL_TYPE_965, "i965G"}, {0x2a02, INTEL_TYPE_965, "i965GM"}, {0x29b2, INTEL_TYPE_G33, "G33G"}, From bonefish at mail.berlios.de Mon Sep 8 07:08:41 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Mon, 8 Sep 2008 07:08:41 +0200 Subject: [Haiku-commits] r27366 - in haiku/trunk: headers/os/drivers headers/private/fs_shell src/system/kernel/fs src/tools/fs_shell Message-ID: <200809080508.m8858fxv005013@sheep.berlios.de> Author: bonefish Date: 2008-09-08 07:08:37 +0200 (Mon, 08 Sep 2008) New Revision: 27366 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27366&view=rev Modified: haiku/trunk/headers/os/drivers/fs_cache.h haiku/trunk/headers/private/fs_shell/fssh_api_wrapper.h haiku/trunk/headers/private/fs_shell/fssh_fs_cache.h haiku/trunk/src/system/kernel/fs/vfs.cpp haiku/trunk/src/tools/fs_shell/vfs.cpp Log: Implemented a simple directory entry cache to speed up path resolution. Modified: haiku/trunk/headers/os/drivers/fs_cache.h =================================================================== --- haiku/trunk/headers/os/drivers/fs_cache.h 2008-09-08 02:45:14 UTC (rev 27365) +++ haiku/trunk/headers/os/drivers/fs_cache.h 2008-09-08 05:08:37 UTC (rev 27366) @@ -99,6 +99,12 @@ extern status_t file_map_translate(void *_map, off_t offset, size_t size, struct file_io_vec *vecs, size_t *_count, size_t align); +/* entry cache */ +extern status_t entry_cache_add(dev_t mountID, ino_t dirID, const char* name, + ino_t nodeID); +extern status_t entry_cache_remove(dev_t mountID, ino_t dirID, + const char* name); + #ifdef __cplusplus } #endif Modified: haiku/trunk/headers/private/fs_shell/fssh_api_wrapper.h =================================================================== --- haiku/trunk/headers/private/fs_shell/fssh_api_wrapper.h 2008-09-08 02:45:14 UTC (rev 27365) +++ haiku/trunk/headers/private/fs_shell/fssh_api_wrapper.h 2008-09-08 05:08:37 UTC (rev 27366) @@ -846,6 +846,10 @@ #define file_map_invalidate fssh_file_map_invalidate #define file_map_translate fssh_file_map_translate +/* entry cache */ +#define entry_cache_add fssh_entry_cache_add +#define entry_cache_remove fssh_entry_cache_remove + //////////////////////////////////////////////////////////////////////////////// // #pragma mark - fssh_fs_index.h Modified: haiku/trunk/headers/private/fs_shell/fssh_fs_cache.h =================================================================== --- haiku/trunk/headers/private/fs_shell/fssh_fs_cache.h 2008-09-08 02:45:14 UTC (rev 27365) +++ haiku/trunk/headers/private/fs_shell/fssh_fs_cache.h 2008-09-08 05:08:37 UTC (rev 27366) @@ -120,6 +120,13 @@ fssh_size_t size, struct fssh_file_io_vec *vecs, fssh_size_t *_count, fssh_size_t align); +/* entry cache */ +extern fssh_status_t fssh_entry_cache_add(fssh_dev_t mountID, + fssh_ino_t dirID, const char* name, + fssh_ino_t nodeID); +extern fssh_status_t fssh_entry_cache_remove(fssh_dev_t mountID, + fssh_ino_t dirID, const char* name); + #ifdef __cplusplus } #endif Modified: haiku/trunk/src/system/kernel/fs/vfs.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/vfs.cpp 2008-09-08 02:45:14 UTC (rev 27365) +++ haiku/trunk/src/system/kernel/fs/vfs.cpp 2008-09-08 05:08:37 UTC (rev 27366) @@ -44,8 +44,10 @@ #include #include #include +#include #include -#include +#include +#include #include #include #include @@ -105,6 +107,163 @@ // It may be chosen with respect to the available memory or enhanced // by some timestamp/frequency heurism. +const static uint32 kMaxEntryCacheEntryCount = 8192; + // Maximum number of entries per entry cache. It's a hard limit ATM. + +struct EntryCacheKey { + EntryCacheKey(ino_t dirID, const char* name) + : + dir_id(dirID), + name(name) + { + } + + ino_t dir_id; + const char* name; +}; + + +struct EntryCacheEntry : HashTableLink, + DoublyLinkedListLinkImpl { + ino_t node_id; + ino_t dir_id; + char name[1]; +}; + + +struct EntryCacheHashDefinition { + typedef EntryCacheKey KeyType; + typedef EntryCacheEntry ValueType; + + uint32 HashKey(const EntryCacheKey& key) const + { + return (uint32)key.dir_id ^ (uint32)(key.dir_id >> 32) + ^ hash_hash_string(key.name); + } + + size_t Hash(const EntryCacheEntry* value) const + { + return (uint32)value->dir_id ^ (uint32)(value->dir_id >> 32) + ^ hash_hash_string(value->name); + } + + bool Compare(const EntryCacheKey& key, const EntryCacheEntry* value) const + { + return value->dir_id == key.dir_id + && strcmp(value->name, key.name) == 0; + } + + HashTableLink* GetLink(EntryCacheEntry* value) const + { + return value; + } +}; + + +class EntryCache { +public: + // Note: Constructor and destructor are never invoked, since instances of + // this class are member of the fs_mount C structure. Hence we do all + // initialization/uninitialization in Init()/Uninit() explicitly. + + status_t Init() + { + mutex_init(&fLock, "entry cache"); + + new(&fEntries) EntryTable; + new(&fUsedEntries) EntryList; + fEntryCount = 0; + + return fEntries.Init(); + } + + void Uninit() + { + while (EntryCacheEntry* entry = fUsedEntries.Head()) + _Remove(entry); + + fEntries.~EntryTable(); + + mutex_destroy(&fLock); + } + + status_t Add(ino_t dirID, const char* name, ino_t nodeID) + { + MutexLocker _(fLock); + + EntryCacheEntry* entry = fEntries.Lookup(EntryCacheKey(dirID, name)); + if (entry != NULL) { + entry->node_id = nodeID; + return B_OK; + } + + if (fEntryCount >= kMaxEntryCacheEntryCount) + _Remove(fUsedEntries.Head()); + + entry = (EntryCacheEntry*)malloc(sizeof(EntryCacheEntry) + + strlen(name)); + if (entry == NULL) + return B_NO_MEMORY; + + entry->node_id = nodeID; + entry->dir_id = dirID; + strcpy(entry->name, name); + + fEntries.Insert(entry); + fUsedEntries.Add(entry); + fEntryCount++; + + return B_OK; + } + + status_t Remove(ino_t dirID, const char* name) + { + MutexLocker _(fLock); + + EntryCacheEntry* entry = fEntries.Lookup(EntryCacheKey(dirID, name)); + if (entry == NULL) + return B_ENTRY_NOT_FOUND; + + _Remove(entry); + + return B_OK; + } + + bool Lookup(ino_t dirID, const char* name, ino_t& nodeID) + { + MutexLocker _(fLock); + + EntryCacheEntry* entry = fEntries.Lookup(EntryCacheKey(dirID, name)); + if (entry == NULL) + return false; + + // requeue at the end + fUsedEntries.Remove(entry); + fUsedEntries.Add(entry); + + nodeID = entry->node_id; + return true; + } + + void _Remove(EntryCacheEntry* entry) + { + fEntries.Remove(entry); + fUsedEntries.Remove(entry); + free(entry); + fEntryCount--; + } + +private: + typedef OpenHashTable EntryTable; + typedef DoublyLinkedList EntryList; + + mutex fLock; + EntryTable fEntries; + EntryList fUsedEntries; // LRU queue (LRU entry at the head) + uint32 fEntryCount; +}; + + struct vnode : fs_vnode { struct vnode *next; vm_cache *cache; @@ -154,6 +313,7 @@ struct vnode *covers_vnode; KPartition *partition; struct list vnodes; + EntryCache entry_cache; bool unmounting; bool owns_file_device; }; @@ -1919,6 +2079,10 @@ lookup_dir_entry(struct vnode* dir, const char* name, struct vnode** _vnode) { ino_t id; + + if (dir->mount->entry_cache.Lookup(dir->id, name, id)) + return get_vnode(dir->device, id, _vnode, true, false); + status_t status = FS_CALL(dir, lookup, name, &id); if (status < B_OK) return status; @@ -3517,6 +3681,36 @@ } +extern "C" status_t +entry_cache_add(dev_t mountID, ino_t dirID, const char* name, ino_t nodeID) +{ + // lookup mount -- the caller is required to make sure that the mount + // won't go away + MutexLocker locker(sMountMutex); + struct fs_mount* mount = find_mount(mountID); + if (mount == NULL) + return B_BAD_VALUE; + locker.Unlock(); + + return mount->entry_cache.Add(dirID, name, nodeID); +} + + +extern "C" status_t +entry_cache_remove(dev_t mountID, ino_t dirID, const char* name) +{ + // lookup mount -- the caller is required to make sure that the mount + // won't go away + MutexLocker locker(sMountMutex); + struct fs_mount* mount = find_mount(mountID); + if (mount == NULL) + return B_BAD_VALUE; + locker.Unlock(); + + return mount->entry_cache.Remove(dirID, name); +} + + // #pragma mark - private VFS API // Functions the VFS exports for other parts of the kernel @@ -6572,6 +6766,10 @@ mount->device_name = strdup(device); // "device" can be NULL + status = mount->entry_cache.Init(); + if (status != B_OK) + goto err2; + mount->fs = get_file_system(fsName); if (mount->fs == NULL) { status = ENODEV; @@ -6698,6 +6896,8 @@ put_file_system(mount->fs); free(mount->device_name); err3: + mount->entry_cache.Uninit(); +err2: free(mount->fs_name); err1: free(mount->volume); @@ -6884,6 +7084,8 @@ partition->Unregister(); } + mount->entry_cache.Uninit(); + free(mount->device_name); free(mount->fs_name); free(mount->volume); Modified: haiku/trunk/src/tools/fs_shell/vfs.cpp =================================================================== --- haiku/trunk/src/tools/fs_shell/vfs.cpp 2008-09-08 02:45:14 UTC (rev 27365) +++ haiku/trunk/src/tools/fs_shell/vfs.cpp 2008-09-08 05:08:37 UTC (rev 27366) @@ -2238,6 +2238,23 @@ } +extern "C" fssh_status_t +fssh_entry_cache_add(fssh_dev_t mountID, fssh_ino_t dirID, const char* name, + fssh_ino_t nodeID) +{ + // We don't implement an entry cache in the FS shell. + return FSSH_B_OK; +} + + +extern "C" fssh_status_t +fssh_entry_cache_remove(fssh_dev_t mountID, fssh_ino_t dirID, const char* name) +{ + // We don't implement an entry cache in the FS shell. + return FSSH_B_ENTRY_NOT_FOUND; +} + + // #pragma mark - private VFS API // Functions the VFS exports for other parts of the kernel From bonefish at mail.berlios.de Mon Sep 8 07:09:14 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Mon, 8 Sep 2008 07:09:14 +0200 Subject: [Haiku-commits] r27367 - haiku/trunk/src/add-ons/kernel/file_systems/bfs Message-ID: <200809080509.m8859ErH005526@sheep.berlios.de> Author: bonefish Date: 2008-09-08 07:09:13 +0200 (Mon, 08 Sep 2008) New Revision: 27367 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27367&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp Log: Use the new entry cache. Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp 2008-09-08 05:08:37 UTC (rev 27366) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp 2008-09-08 05:09:13 UTC (rev 27367) @@ -549,6 +549,8 @@ return status; } + entry_cache_add(volume->ID(), directory->ID(), file, *_vnodeID); + locker.Unlock(); Inode* inode; @@ -827,6 +829,8 @@ } if (status >= B_OK) { + entry_cache_add(volume->ID(), directory->ID(), name, *_vnodeID); + transaction.Done(); // register the cookie @@ -896,6 +900,8 @@ put_vnode(volume->FSVolume(), id); if (status == B_OK) { + entry_cache_add(volume->ID(), directory->ID(), name, id); + transaction.Done(); notify_entry_created(volume->ID(), directory->ID(), name, id); @@ -935,6 +941,8 @@ off_t id; if ((status = directory->Remove(transaction, name, &id)) == B_OK) { + entry_cache_remove(volume->ID(), directory->ID(), name); + transaction.Done(); notify_entry_removed(volume->ID(), directory->ID(), name, id); @@ -1055,6 +1063,8 @@ if (status < B_OK) return status; + entry_cache_remove(volume->ID(), newDirectory->ID(), newName); + notify_entry_removed(volume->ID(), newDirectory->ID(), newName, clobber); @@ -1097,6 +1107,9 @@ status = inode->WriteBack(transaction); if (status == B_OK) { + entry_cache_remove(volume->ID(), oldDirectory->ID(), oldName); + entry_cache_add(volume->ID(), newDirectory->ID(), newName, id); + transaction.Done(); notify_entry_moved(volume->ID(), oldDirectory->ID(), oldName, @@ -1423,6 +1436,9 @@ if (status == B_OK) { *_newVnodeID = id; put_vnode(volume->FSVolume(), id); + + entry_cache_add(volume->ID(), directory->ID(), name, id); + transaction.Done(); notify_entry_created(volume->ID(), directory->ID(), name, id); @@ -1445,6 +1461,8 @@ off_t id; status_t status = directory->Remove(transaction, name, &id, true); if (status == B_OK) { + entry_cache_remove(volume->ID(), directory->ID(), name); + transaction.Done(); notify_entry_removed(volume->ID(), directory->ID(), name, id); @@ -1807,6 +1825,9 @@ _superVnode->private_node = inode; _superVnode->ops = &gBFSVnodeOps; *_nodeID = id; + + entry_cache_add(volume->ID(), directory->ID(), name, id); + transaction.Done(); notify_entry_created(volume->ID(), directory->ID(), name, id); From jackburton at mail.berlios.de Mon Sep 8 10:32:01 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Mon, 8 Sep 2008 10:32:01 +0200 Subject: [Haiku-commits] r27368 - haiku/trunk/src/system/boot/platform/bios_ia32 Message-ID: <200809080832.m888W1Zd020710@sheep.berlios.de> Author: jackburton Date: 2008-09-08 10:31:57 +0200 (Mon, 08 Sep 2008) New Revision: 27368 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27368&view=rev Modified: haiku/trunk/src/system/boot/platform/bios_ia32/acpi.cpp Log: argument was missing from the TRACE call Modified: haiku/trunk/src/system/boot/platform/bios_ia32/acpi.cpp =================================================================== --- haiku/trunk/src/system/boot/platform/bios_ia32/acpi.cpp 2008-09-08 05:09:13 UTC (rev 27367) +++ haiku/trunk/src/system/boot/platform/bios_ia32/acpi.cpp 2008-09-08 08:31:57 UTC (rev 27368) @@ -79,7 +79,7 @@ TRACE(("acpi: Looking for '%.4s'. Skipping '%.4s'\n", signature, header->signature)); continue; } - TRACE(("acpi: Found '%.4s' @ %p\n", signature)); + TRACE(("acpi: Found '%.4s' @ %p\n", signature, pointer)); return header; } From mmlr at mail.berlios.de Mon Sep 8 10:34:01 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Mon, 8 Sep 2008 10:34:01 +0200 Subject: [Haiku-commits] r27369 - haiku/trunk/src/servers/app Message-ID: <200809080834.m888Y1HT020813@sheep.berlios.de> Author: mmlr Date: 2008-09-08 10:33:49 +0200 (Mon, 08 Sep 2008) New Revision: 27369 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27369&view=rev Modified: haiku/trunk/src/servers/app/DefaultDecorator.cpp Log: Respect B_NOT_MINIMIZABLE in the default decorator. Maybe we should recheck all the flags in the window code though instead of relying fully on the decorator. Modified: haiku/trunk/src/servers/app/DefaultDecorator.cpp =================================================================== --- haiku/trunk/src/servers/app/DefaultDecorator.cpp 2008-09-08 08:31:57 UTC (rev 27368) +++ haiku/trunk/src/servers/app/DefaultDecorator.cpp 2008-09-08 08:33:49 UTC (rev 27369) @@ -580,7 +580,7 @@ if (buttons == B_SECONDARY_MOUSE_BUTTON) return DEC_MOVETOBACK; - if (fWasDoubleClick) + if (fWasDoubleClick && !(fFlags & B_NOT_MINIMIZABLE)) return DEC_MINIMIZE; return DEC_DRAG; From stefano.ceccherini at gmail.com Mon Sep 8 10:36:01 2008 From: stefano.ceccherini at gmail.com (Stefano Ceccherini) Date: Mon, 8 Sep 2008 10:36:01 +0200 Subject: [Haiku-commits] r27369 - haiku/trunk/src/servers/app In-Reply-To: <200809080834.m888Y1HT020813@sheep.berlios.de> References: <200809080834.m888Y1HT020813@sheep.berlios.de> Message-ID: <894b9700809080136o7181671cu99b87c97b7b02787@mail.gmail.com> 2008/9/8 : > Author: mmlr > Date: 2008-09-08 10:33:49 +0200 (Mon, 08 Sep 2008) > New Revision: 27369 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27369&view=rev > > Modified: > haiku/trunk/src/servers/app/DefaultDecorator.cpp > Log: > Respect B_NOT_MINIMIZABLE in the default decorator. Maybe we should recheck all the flags in the window code though instead of relying fully on the decorator. ... or change the way decorators work. I mean, currently they can do a bit too much, like crashing the whole app_server if something goes wrong. Food for thought for later, though. From mmlr at mail.berlios.de Mon Sep 8 10:36:42 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Mon, 8 Sep 2008 10:36:42 +0200 Subject: [Haiku-commits] r27370 - haiku/trunk/src/apps/installer Message-ID: <200809080836.m888ag4g020953@sheep.berlios.de> Author: mmlr Date: 2008-09-08 10:36:38 +0200 (Mon, 08 Sep 2008) New Revision: 27370 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27370&view=rev Modified: haiku/trunk/src/apps/installer/InstallerWindow.cpp Log: Make the installer window not minimizable, as without a Deskbar loaded, minimizing makes things a bit difficult... Modified: haiku/trunk/src/apps/installer/InstallerWindow.cpp =================================================================== --- haiku/trunk/src/apps/installer/InstallerWindow.cpp 2008-09-08 08:33:49 UTC (rev 27369) +++ haiku/trunk/src/apps/installer/InstallerWindow.cpp 2008-09-08 08:36:38 UTC (rev 27370) @@ -69,7 +69,7 @@ InstallerWindow::InstallerWindow(BRect frame_rect) : BWindow(frame_rect, "Installer", B_TITLED_WINDOW, - B_NOT_ZOOMABLE | B_NOT_RESIZABLE), + B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE | B_NOT_RESIZABLE), fDriveSetupLaunched(false), fInstallStatus(kReadyForInstall), fLastSrcItem(NULL), From stippi at mail.berlios.de Mon Sep 8 13:02:40 2008 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Mon, 8 Sep 2008 13:02:40 +0200 Subject: [Haiku-commits] r27371 - haiku/trunk/src/apps/diskusage Message-ID: <200809081102.m88B2evW009380@sheep.berlios.de> Author: stippi Date: 2008-09-08 13:02:39 +0200 (Mon, 08 Sep 2008) New Revision: 27371 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27371&view=rev Added: haiku/trunk/src/apps/diskusage/DiskUsage.cpp Modified: haiku/trunk/src/apps/diskusage/App.cpp haiku/trunk/src/apps/diskusage/App.h haiku/trunk/src/apps/diskusage/Jamfile Log: * Full integration as a Tracker add-on. Code taken from TextSearch. * Fixed settings file saving when the settings file didn't exist yet. * Fixed problem with launching DiskUsage with refs. In that case, ReadyToRun() is called later than RefsReceived(). I remember the same thing happens on BeOS. Modified: haiku/trunk/src/apps/diskusage/App.cpp =================================================================== --- haiku/trunk/src/apps/diskusage/App.cpp 2008-09-08 08:36:38 UTC (rev 27370) +++ haiku/trunk/src/apps/diskusage/App.cpp 2008-09-08 11:02:39 UTC (rev 27371) @@ -22,7 +22,8 @@ App::App() : BApplication(kAppSignature), fResources(read_resources(kAppSignature)), - fMainWindow(NULL) + fMainWindow(NULL), + fSavedRefsReceived(NULL) { } @@ -30,6 +31,7 @@ App::~App() { delete fResources; + delete fSavedRefsReceived; } @@ -51,7 +53,13 @@ void App::RefsReceived(BMessage* message) { - fMainWindow->PostMessage(message); + if (fMainWindow == NULL) { + // ReadyToRun() has not been called yet, this happens when someone + // launches us with a B_REFS_RECEIVED message. + delete fSavedRefsReceived; + fSavedRefsReceived = new BMessage(*message); + } else + fMainWindow->PostMessage(message); } @@ -74,6 +82,13 @@ } fMainWindow = new MainWindow(frame); + + if (fSavedRefsReceived) { + // RefsReceived() was called earlier than ReadyToRun() + fMainWindow->PostMessage(fSavedRefsReceived); + delete fSavedRefsReceived; + fSavedRefsReceived = NULL; + } } @@ -87,23 +102,11 @@ if (settings.AddRect("window frame", fMainWindow->Frame()) != B_OK || find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK || path.Append("DiskUsage") != B_OK - || settingsFile.SetTo(path.Path(), B_WRITE_ONLY) != B_OK + || settingsFile.SetTo(path.Path(), + B_CREATE_FILE | B_WRITE_ONLY | B_ERASE_FILE) != B_OK || settings.Flatten(&settingsFile) != B_OK) { fprintf(stderr, "Failed to write application settings.\n"); } return BApplication::QuitRequested(); } - - -// #pragma mark - - - -int -main() -{ - App app; - app.Run(); - return 0; -} - Modified: haiku/trunk/src/apps/diskusage/App.h =================================================================== --- haiku/trunk/src/apps/diskusage/App.h 2008-09-08 08:36:38 UTC (rev 27370) +++ haiku/trunk/src/apps/diskusage/App.h 2008-09-08 11:02:39 UTC (rev 27371) @@ -28,6 +28,7 @@ private: BResources* fResources; MainWindow* fMainWindow; + BMessage* fSavedRefsReceived; }; #endif // APP_H Added: haiku/trunk/src/apps/diskusage/DiskUsage.cpp =================================================================== --- haiku/trunk/src/apps/diskusage/DiskUsage.cpp 2008-09-08 08:36:38 UTC (rev 27370) +++ haiku/trunk/src/apps/diskusage/DiskUsage.cpp 2008-09-08 11:02:39 UTC (rev 27371) @@ -0,0 +1,89 @@ +/* + * Copyright (c) 1998-2007 Matthijs Hollemans + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +// NOTE: This code is the same in TextSearch. Maybe it could be made +// into some kind of common base class? + +#include "App.h" + +#include +#include +#include +#include + +#include "Common.h" + + +int +main() +{ + App app; + app.Run(); + return 0; +} + + +void +process_refs(entry_ref dirRef, BMessage* message, void* /*reserved*/) +{ + // Tracker calls this function when the user invokes the add-on. + // "dir_ref" contains the entry_ref of the current directory. + // "message" is a standard B_REFS_RECEIVED BMessage whose "refs" + // array contains the entry_refs of the selected files. The last + // argument, "reserved", is currently unused. + + // This version of TrackerGrep is a Tracker add-on, but primarily + // it is a stand-alone application. The add-on launches the app + // on the set of files you had selected in Tracker. That way you + // get the benefits of the Tracker add-on with the benefits of the + // stand-alone application. + + if (!message->HasRef("refs")) + message->AddRef("refs", &dirRef); + + // get the path of the Tracker add-on + image_info image; + int32 cookie = 0; + status_t status = get_next_image_info(0, &cookie, &image); + + while (status == B_OK) { + if (((char*)process_refs >= (char*)image.text + && (char*)process_refs <= (char*)image.text + image.text_size) + || ((char*)process_refs >= (char*)image.data + && (char*)process_refs <= (char*)image.data + image.data_size)) + break; + + status = get_next_image_info(0, &cookie, &image); + } + + entry_ref addonRef; + + if (get_ref_for_path(image.name, &addonRef) == B_OK) { + // It's better to launch the application by its entry + // than by its application signature. There may be + // multiple instances and we would not be certain + // that the desired one is launched - the one which was + // loaded into Tracker and whose process_refs() was called. + be_roster->Launch(&addonRef, message); + } else + be_roster->Launch(kAppSignature, message); +} Modified: haiku/trunk/src/apps/diskusage/Jamfile =================================================================== --- haiku/trunk/src/apps/diskusage/Jamfile 2008-09-08 08:36:38 UTC (rev 27370) +++ haiku/trunk/src/apps/diskusage/Jamfile 2008-09-08 11:02:39 UTC (rev 27371) @@ -4,6 +4,7 @@ App.cpp Common.cpp ControlsView.cpp + DiskUsage.cpp InfoWindow.cpp MainWindow.cpp PieView.cpp From stippi at mail.berlios.de Mon Sep 8 13:04:40 2008 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Mon, 8 Sep 2008 13:04:40 +0200 Subject: [Haiku-commits] r27372 - haiku/trunk/build/jam Message-ID: <200809081104.m88B4eIc011072@sheep.berlios.de> Author: stippi Date: 2008-09-08 13:04:39 +0200 (Mon, 08 Sep 2008) New Revision: 27372 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27372&view=rev Modified: haiku/trunk/build/jam/HaikuImage Log: Add DiskUsage to the build and also integrate it as a Tracker add-on. Modified: haiku/trunk/build/jam/HaikuImage =================================================================== --- haiku/trunk/build/jam/HaikuImage 2008-09-08 11:02:39 UTC (rev 27371) +++ haiku/trunk/build/jam/HaikuImage 2008-09-08 11:04:39 UTC (rev 27372) @@ -53,9 +53,9 @@ zipcloak zipgrep zipnote zipsplit zmore znew ; -BEOS_APPS = AboutSystem ActivityMonitor CodyCam DeskCalc DiskProbe DriveSetup - CDPlayer Expander Icon-O-Matic Installer LaunchBox Magnify Mail MediaPlayer - MidiPlayer NetworkStatus PackageInstaller People PowerStatus +BEOS_APPS = AboutSystem ActivityMonitor CodyCam DeskCalc DiskProbe DiskUsage + DriveSetup CDPlayer Expander Icon-O-Matic Installer LaunchBox Magnify Mail + MediaPlayer MidiPlayer NetworkStatus PackageInstaller People PowerStatus ProcessController ShowImage SoundRecorder StyledEdit Terminal TextSearch TV Workspaces ; @@ -237,8 +237,8 @@ # Deskbar Application links AddDirectoryToHaikuImage home config be Applications ; DESKBAR_APPLICATIONS = ActivityMonitor CodyCam CDPlayer DeskCalc DiskProbe - DriveSetup Icon-O-Matic Magnify Mail MediaPlayer MidiPlayer People - SoundRecorder StyledEdit Terminal TV + DriveSetup DiskUsage Icon-O-Matic Magnify Mail MediaPlayer MidiPlayer + People SoundRecorder StyledEdit Terminal TV ; local app ; for app in $(DESKBAR_APPLICATIONS) { @@ -397,6 +397,8 @@ : /boot/beos/preferences/Backgrounds : Background-B ; AddSymlinkToHaikuImage beos system add-ons Tracker : /boot/beos/apps/TextSearch : TextSearch-G ; +AddSymlinkToHaikuImage beos system add-ons Tracker + : /boot/beos/apps/DiskUsage : DiskUsage-I ; AddFilesToHaikuImage beos system add-ons input_server devices : keyboard mouse wacom ; AddFilesToHaikuImage beos system add-ons input_server filters : screen_saver ; From stippi at mail.berlios.de Mon Sep 8 13:23:41 2008 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Mon, 8 Sep 2008 13:23:41 +0200 Subject: [Haiku-commits] r27373 - haiku/trunk/src/apps/text_search Message-ID: <200809081123.m88BNf9Y009773@sheep.berlios.de> Author: stippi Date: 2008-09-08 13:23:40 +0200 (Mon, 08 Sep 2008) New Revision: 27373 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27373&view=rev Modified: haiku/trunk/src/apps/text_search/Model.cpp Log: Change default settings to "Invoke in Pe" if Pe is installed. Modified: haiku/trunk/src/apps/text_search/Model.cpp =================================================================== --- haiku/trunk/src/apps/text_search/Model.cpp 2008-09-08 11:04:39 UTC (rev 27372) +++ haiku/trunk/src/apps/text_search/Model.cpp 2008-09-08 11:23:40 UTC (rev 27373) @@ -33,8 +33,11 @@ #include #include #include +#include +#include "GlobalDefs.h" + using std::nothrow; @@ -64,6 +67,12 @@ fFilePanelPath = path.Path(); else fFilePanelPath = "/boot/home"; + + entry_ref dummy; + if (be_roster->FindApp(PE_SIGNATURE, &dummy) == B_OK) { + // Pe is installed, change the default settings + fInvokePe = true; + } } From stippi at mail.berlios.de Mon Sep 8 13:24:25 2008 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Mon, 8 Sep 2008 13:24:25 +0200 Subject: [Haiku-commits] r27374 - haiku/trunk/src/apps/text_search Message-ID: <200809081124.m88BOPF3011218@sheep.berlios.de> Author: stippi Date: 2008-09-08 13:24:24 +0200 (Mon, 08 Sep 2008) New Revision: 27374 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27374&view=rev Modified: haiku/trunk/src/apps/text_search/GlobalDefs.h Log: Change prefs file name to just "TextSearch". No reason to append "Settings" if this file is to be found in the "settings" folder... Modified: haiku/trunk/src/apps/text_search/GlobalDefs.h =================================================================== --- haiku/trunk/src/apps/text_search/GlobalDefs.h 2008-09-08 11:23:40 UTC (rev 27373) +++ haiku/trunk/src/apps/text_search/GlobalDefs.h 2008-09-08 11:24:24 UTC (rev 27374) @@ -9,7 +9,7 @@ #define APP_SIGNATURE "application/x-vnd.mahlzeit.trackergrep" #define APP_NAME "TextSearch" -#define PREFS_FILE "TextSearchSettings" +#define PREFS_FILE "TextSearch" #define HISTORY_LIMIT 20 #define TRACKER_SIGNATURE "application/x-vnd.Be-TRAK" From stippi at mail.berlios.de Mon Sep 8 13:25:00 2008 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Mon, 8 Sep 2008 13:25:00 +0200 Subject: [Haiku-commits] r27375 - haiku/trunk/src/apps/text_search Message-ID: <200809081125.m88BP0lO013169@sheep.berlios.de> Author: stippi Date: 2008-09-08 13:24:59 +0200 (Mon, 08 Sep 2008) New Revision: 27375 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27375&view=rev Modified: haiku/trunk/src/apps/text_search/TextSearch.cpp Log: * Small cleanup * Mention the fact that the same code is used in DiskUsage. Modified: haiku/trunk/src/apps/text_search/TextSearch.cpp =================================================================== --- haiku/trunk/src/apps/text_search/TextSearch.cpp 2008-09-08 11:24:24 UTC (rev 27374) +++ haiku/trunk/src/apps/text_search/TextSearch.cpp 2008-09-08 11:24:59 UTC (rev 27375) @@ -19,6 +19,10 @@ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ + +// NOTE: This code is the same in DiskUsge. Maybe it could be made +// into some kind of common base class? + #include "GrepApp.h" #include @@ -58,10 +62,8 @@ // get the path of the Tracker add-on image_info image; int32 cookie = 0; - status_t status = B_OK; + status_t status = get_next_image_info(0, &cookie, &image); - status = get_next_image_info(0, &cookie, &image); - while (status == B_OK) { if (((char*)process_refs >= (char*)image.text && (char*)process_refs <= (char*)image.text + image.text_size) From stippi at mail.berlios.de Mon Sep 8 13:26:07 2008 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Mon, 8 Sep 2008 13:26:07 +0200 Subject: [Haiku-commits] r27376 - haiku/trunk/src/apps/text_search Message-ID: <200809081126.m88BQ7CC019764@sheep.berlios.de> Author: stippi Date: 2008-09-08 13:25:57 +0200 (Mon, 08 Sep 2008) New Revision: 27376 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27376&view=rev Modified: haiku/trunk/src/apps/text_search/GrepListView.cpp haiku/trunk/src/apps/text_search/GrepListView.h Log: Add method to remove all subitems of a result item, and optionally also the item itself. Modified: haiku/trunk/src/apps/text_search/GrepListView.cpp =================================================================== --- haiku/trunk/src/apps/text_search/GrepListView.cpp 2008-09-08 11:24:59 UTC (rev 27375) +++ haiku/trunk/src/apps/text_search/GrepListView.cpp 2008-09-08 11:25:57 UTC (rev 27376) @@ -58,3 +58,31 @@ *_index = -1; return NULL; } + + +ResultItem* +GrepListView::RemoveResults(const entry_ref& ref, bool completeItem) +{ + int32 index; + ResultItem* item = FindItem(ref, &index); + if (item == NULL) + return NULL; + + // remove all the sub items + while (true) { + BListItem* subItem = FullListItemAt(index + 1); + if (subItem && subItem->OutlineLevel() > 0) + delete RemoveItem(index + 1); + else + break; + } + + if (completeItem) { + // remove file item itself + delete RemoveItem(index); + item = NULL; + } + + return item; +} + Modified: haiku/trunk/src/apps/text_search/GrepListView.h =================================================================== --- haiku/trunk/src/apps/text_search/GrepListView.h 2008-09-08 11:24:59 UTC (rev 27375) +++ haiku/trunk/src/apps/text_search/GrepListView.h 2008-09-08 11:25:57 UTC (rev 27376) @@ -41,6 +41,9 @@ ResultItem* FindItem(const entry_ref& ref, int32* _index) const; + + ResultItem* RemoveResults(const entry_ref& ref, + bool completeItem); }; #endif // GREP_LIST_VIEW_H From stippi at mail.berlios.de Mon Sep 8 13:31:07 2008 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Mon, 8 Sep 2008 13:31:07 +0200 Subject: [Haiku-commits] r27377 - haiku/trunk/src/apps/text_search Message-ID: <200809081131.m88BV7Vu029782@sheep.berlios.de> Author: stippi Date: 2008-09-08 13:31:06 +0200 (Mon, 08 Sep 2008) New Revision: 27377 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27377&view=rev Modified: haiku/trunk/src/apps/text_search/ChangesIterator.cpp haiku/trunk/src/apps/text_search/GrepWindow.cpp Log: Node monitoring changes: * In the ChangesIterator, just remove removed files from the HashMap, regardless if they could be considered "temporary" or not. * If a file is removed, we can directly remove it from the results list. This makes removing files from the result list more robust and quicker if this was the only thing that happened with regards to node monitoring (the grep process does not need to be run again). * Refactored removing result items from the list on result notifications. * Beginnings of supporting moving files within the watched folder hierarchy. If they were just moved, the new location should update in the list. (not well tested) Modified: haiku/trunk/src/apps/text_search/ChangesIterator.cpp =================================================================== --- haiku/trunk/src/apps/text_search/ChangesIterator.cpp 2008-09-08 11:25:57 UTC (rev 27376) +++ haiku/trunk/src/apps/text_search/ChangesIterator.cpp 2008-09-08 11:31:06 UTC (rev 27377) @@ -100,18 +100,9 @@ { HashString key(path); if (fPathMap.ContainsKey(key)) { - uint32 mode = fPathMap.Get(key); - if (mode == ENTRY_ADDED) { - TRACE("ignoring: %s\n", path); - fPathMap.Remove(key); - return; - } else if (mode == ENTRY_REMOVED) - return; + TRACE("ignoring: %s\n", path); + fPathMap.Remove(key); } - - TRACE("removed: %s\n", path); - - fPathMap.Put(key, ENTRY_REMOVED); } Modified: haiku/trunk/src/apps/text_search/GrepWindow.cpp =================================================================== --- haiku/trunk/src/apps/text_search/GrepWindow.cpp 2008-09-08 11:25:57 UTC (rev 27376) +++ haiku/trunk/src/apps/text_search/GrepWindow.cpp 2008-09-08 11:31:06 UTC (rev 27377) @@ -50,7 +50,7 @@ static const bigtime_t kChangesPulseInterval = 150000; -//#define TRACE_NODE_MONITORING +#define TRACE_NODE_MONITORING #ifdef TRACE_NODE_MONITORING # define TRACE_NM(x...) printf(x) #else @@ -881,8 +881,15 @@ if (message->FindString("path", &path) == B_OK) { if (opCode == B_ENTRY_CREATED) fChangesIterator->EntryAdded(path.String()); - else + else { + // in order to remove temporary files fChangesIterator->EntryRemoved(path.String()); + // remove from the list view already + BEntry entry(path.String()); + entry_ref ref; + if (entry.GetRef(&ref) == B_OK) + fSearchResults->RemoveResults(ref, true); + } } else { #ifdef TRACE_NODE_MONITORING printf("incompatible message:\n"); @@ -893,14 +900,47 @@ break; } case B_ENTRY_MOVED: - #ifdef TRACE_NODE_MONITORING - printf("B_ENTRY_MOVED\n"); - message->PrintToStream(); - #endif - // TODO: If the path is now outside the folder hierarchy, it's just - // a "removed" entry. If the move happened within the hierarchy, - // it should be a combined removed/added event. + { + TRACE_NM("B_ENTRY_MOVED\n"); + + BString path; + if (message->FindString("path", &path) != B_OK) { + #ifdef TRACE_NODE_MONITORING + printf("incompatible message:\n"); + message->PrintToStream(); + #endif + break; + } + + bool added; + if (message->FindBool("added", &added) != B_OK) + added = false; + bool removed; + if (message->FindBool("removed", &removed) != B_OK) + removed = false; + + if (added) { + // new files + } else if (removed) { + // remove files + } else { + // files changed location, but are still within the search + // path! + BEntry entry(path.String()); + entry_ref ref; + if (entry.GetRef(&ref) == B_OK) { + int32 index; + ResultItem* item = fSearchResults->FindItem(ref, &index); + item->SetText(path.String()); + // take care of invalidation, the index is currently + // the full list index, but needs to be the visible + // items index for this + index = fSearchResults->IndexOf(item); + fSearchResults->InvalidateItem(index); + } + } break; + } case B_STAT_CHANGED: case B_ATTR_CHANGED: { @@ -1001,27 +1041,9 @@ BStringItem* item = NULL; if (fModel->fState == STATE_UPDATE) { - int32 index; - item = fSearchResults->FindItem(ref, &index); - if (item) { - // remove any sub items - while (true) { - BListItem* subItem = fSearchResults->FullListItemAt(index + 1); - if (subItem && subItem->OutlineLevel() > 0) - delete fSearchResults->RemoveItem(index + 1); - else - break; - } - } - if (count == 0) { - // During updates because of node monitor events, negatives are - // also reported (count == 0). - if (item) { - // remove file item itself - delete fSearchResults->RemoveItem(index); - } - return; - } + // During updates because of node monitor events, negatives are + // also reported (count == 0). + item = fSearchResults->RemoveResults(ref, count == 0); } if (item == NULL) { item = new ResultItem(ref); From emitrax at gmail.com Mon Sep 8 13:34:39 2008 From: emitrax at gmail.com (Salvatore Benedetto) Date: Mon, 8 Sep 2008 11:34:39 +0000 Subject: [Haiku-commits] r27372 - haiku/trunk/build/jam In-Reply-To: <200809081104.m88B4eIc011072@sheep.berlios.de> References: <200809081104.m88B4eIc011072@sheep.berlios.de> Message-ID: 2008/9/8 stippi at BerliOS : > Author: stippi > Date: 2008-09-08 13:04:39 +0200 (Mon, 08 Sep 2008) > New Revision: 27372 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27372&view=rev > > Modified: > haiku/trunk/build/jam/HaikuImage > Log: > Add DiskUsage to the build and also integrate it as a Tracker add-on. Just tested, but it's not what I expected from the name :-) I'm looking for an application that show graphically the block currently used, and updates live when new blocks are written. This might be useful when looking for bugs that corrupts the file system by overwritting blocks already in use. Which is what I'm doing right now. Yep, I yet found another bug. Regards, -- Salvatore Benedetto (a.k.a. emitrax) Student of Computer Engineer University of Pisa www.haiku-os.it From superstippi at gmx.de Mon Sep 8 13:43:43 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Mon, 08 Sep 2008 13:43:43 +0200 Subject: [Haiku-commits] r27372 - haiku/trunk/build/jam In-Reply-To: References: <200809081104.m88B4eIc011072@sheep.berlios.de> Message-ID: <20080908114343.189650@gmx.net> -------- Original-Nachricht -------- > Datum: Mon, 8 Sep 2008 11:34:39 +0000 > Von: "Salvatore Benedetto" > An: "SVN commits to the Haiku source repository" > Betreff: Re: [Haiku-commits] r27372 - haiku/trunk/build/jam > 2008/9/8 stippi at BerliOS : > > Author: stippi > > Date: 2008-09-08 13:04:39 +0200 (Mon, 08 Sep 2008) > > New Revision: 27372 > > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27372&view=rev > > > > Modified: > > haiku/trunk/build/jam/HaikuImage > > Log: > > Add DiskUsage to the build and also integrate it as a Tracker add-on. > > Just tested, but it's not what I expected from the name :-) > I'm looking for an application that show graphically the block > currently used, and > updates live when new blocks are written. This might be useful when > looking for bugs > that corrupts the file system by overwritting blocks already in use. > Which is what I'm doing > right now. Yep, I yet found another bug. This app is a user app for when the user is interested where all the space has gone on a volume (like "Oh, I have a 4 Gig swapfile which I don't need..."). Not a low level debugging tool. ;-) But nice that you are on to another BFS bug! Best regards, -Stephan From anevilyak at gmail.com Mon Sep 8 14:39:08 2008 From: anevilyak at gmail.com (Rene Gollent) Date: Mon, 8 Sep 2008 07:39:08 -0500 Subject: [Haiku-commits] r27372 - haiku/trunk/build/jam In-Reply-To: References: <200809081104.m88B4eIc011072@sheep.berlios.de> Message-ID: On Mon, Sep 8, 2008 at 6:34 AM, Salvatore Benedetto wrote: > Just tested, but it's not what I expected from the name :-) > I'm looking for an application that show graphically the block > currently used, and > updates live when new blocks are written. This might be useful when > looking for bugs > that corrupts the file system by overwritting blocks already in use. > Which is what I'm doing > right now. Yep, I yet found another bug. Right click, Get Info on the volume icon in Tracker should do that if I understand you correctly. Regards, Rene From emitrax at gmail.com Mon Sep 8 14:45:03 2008 From: emitrax at gmail.com (Salvatore Benedetto) Date: Mon, 8 Sep 2008 12:45:03 +0000 Subject: [Haiku-commits] r27372 - haiku/trunk/build/jam In-Reply-To: References: <200809081104.m88B4eIc011072@sheep.berlios.de> Message-ID: 2008/9/8 Rene Gollent : > On Mon, Sep 8, 2008 at 6:34 AM, Salvatore Benedetto wrote: >> Just tested, but it's not what I expected from the name :-) >> I'm looking for an application that show graphically the block >> currently used, and >> updates live when new blocks are written. This might be useful when >> looking for bugs >> that corrupts the file system by overwritting blocks already in use. >> Which is what I'm doing >> right now. Yep, I yet found another bug. > > Right click, Get Info on the volume icon in Tracker should do that if > I understand you correctly. Nope. That just show the memory used (and free). I'm more looking for a tool like the one used in windows 98 (?) to defragment the disk. I haven't used winX for ages, but I do recall a similar tool. Although it was used for defragmentation, it had a graphical overview of the block used. > Regards, > > Rene > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > -- Salvatore Benedetto (a.k.a. emitrax) Student of Computer Engineer University of Pisa www.haiku-os.it From jackburton at mail.berlios.de Mon Sep 8 15:26:38 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Mon, 8 Sep 2008 15:26:38 +0200 Subject: [Haiku-commits] r27378 - haiku/trunk/src/apps/diskusage Message-ID: <200809081326.m88DQcZB009736@sheep.berlios.de> Author: jackburton Date: 2008-09-08 15:26:36 +0200 (Mon, 08 Sep 2008) New Revision: 27378 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27378&view=rev Modified: haiku/trunk/src/apps/diskusage/Common.cpp Log: gcc4 complains on missing declaration of exit() Modified: haiku/trunk/src/apps/diskusage/Common.cpp =================================================================== --- haiku/trunk/src/apps/diskusage/Common.cpp 2008-09-08 11:31:06 UTC (rev 27377) +++ haiku/trunk/src/apps/diskusage/Common.cpp 2008-09-08 13:26:36 UTC (rev 27378) @@ -11,6 +11,7 @@ #include #include +#include #include #include From jackburton at mail.berlios.de Mon Sep 8 15:27:32 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Mon, 8 Sep 2008 15:27:32 +0200 Subject: [Haiku-commits] r27379 - haiku/trunk/src/apps/diskusage Message-ID: <200809081327.m88DRWXb009790@sheep.berlios.de> Author: jackburton Date: 2008-09-08 15:27:31 +0200 (Mon, 08 Sep 2008) New Revision: 27379 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27379&view=rev Modified: haiku/trunk/src/apps/diskusage/ControlsView.cpp Log: (gcc4) local variable shadows a parameter Modified: haiku/trunk/src/apps/diskusage/ControlsView.cpp =================================================================== --- haiku/trunk/src/apps/diskusage/ControlsView.cpp 2008-09-08 13:26:36 UTC (rev 27378) +++ haiku/trunk/src/apps/diskusage/ControlsView.cpp 2008-09-08 13:27:31 UTC (rev 27379) @@ -272,7 +272,7 @@ ResizeTo(Bounds().Width(), height + 6.0); // Horizontal divider - BRect r = Bounds(); + r = Bounds(); r.top = r.bottom - 1.0; r.left -= 5.0; r.right += 5.0; BBox* divider = new BBox(r, NULL, B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW); From stefano.ceccherini at gmail.com Mon Sep 8 15:29:31 2008 From: stefano.ceccherini at gmail.com (Stefano Ceccherini) Date: Mon, 8 Sep 2008 15:29:31 +0200 Subject: [Haiku-commits] r27379 - haiku/trunk/src/apps/diskusage In-Reply-To: <200809081327.m88DRWXb009790@sheep.berlios.de> References: <200809081327.m88DRWXb009790@sheep.berlios.de> Message-ID: <894b9700809080629l7b5769ack3cd59913269fed63@mail.gmail.com> 2008/9/8 : > Author: jackburton > Date: 2008-09-08 15:27:31 +0200 (Mon, 08 Sep 2008) > New Revision: 27379 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27379&view=rev > > Modified: > haiku/trunk/src/apps/diskusage/ControlsView.cpp > Log: > (gcc4) local variable shadows a parameter This app still doesn't compile on gcc4. Here's the error it throws out, which I can't understand. C++ generated/objects/haiku/x86/release/apps/diskusage/InfoWindow.o In file included from /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/memory:60, from /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/string:47, from src/apps/diskusage/Snapshot.h:12, from src/apps/diskusage/InfoWindow.cpp:21: /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:289:22: error: macro "min" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:291:22: error: macro "max" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:319:23: error: macro "min" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:321:23: error: macro "max" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:373:23: error: macro "min" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:375:23: error: macro "max" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:424:30: error: macro "min" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:426:30: error: macro "max" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:475:32: error: macro "min" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:477:32: error: macro "max" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:526:26: error: macro "min" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:528:26: error: macro "max" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:577:24: error: macro "min" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:579:24: error: macro "max" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:628:33: error: macro "min" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:630:33: error: macro "max" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:679:22: error: macro "min" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:681:22: error: macro "max" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:730:31: error: macro "min" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:732:31: error: macro "max" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:781:23: error: macro "min" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:783:23: error: macro "max" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:832:32: error: macro "min" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:834:32: error: macro "max" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:883:28: error: macro "min" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:885:28: error: macro "max" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:934:37: error: macro "min" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:936:37: error: macro "max" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:985:24: error: macro "min" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:987:24: error: macro "max" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:1042:25: error: macro "min" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:1044:25: error: macro "max" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:1099:30: error: macro "min" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:1101:30: error: macro "max" requires 2 arguments, but only 1 given In file included from /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/string:47, from src/apps/diskusage/Snapshot.h:12, from src/apps/diskusage/InfoWindow.cpp:21: /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/memory:76:62: error: macro "max" requires 2 arguments, but only 1 given /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:289: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:291: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:291: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:294: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:319: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:321: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:321: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:324: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:373: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:375: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:375: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:378: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:424: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:426: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:426: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:429: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:475: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:477: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:477: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:480: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:526: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:528: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:528: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:531: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:577: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:579: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:579: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:582: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:628: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:630: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:630: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:633: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:679: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:681: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:681: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:684: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:730: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:732: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:732: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:735: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:781: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:783: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:783: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:786: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:832: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:834: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:834: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:837: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:883: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:885: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:885: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:888: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:934: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:936: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:936: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:939: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:985: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:987: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:987: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:990: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:1042: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:1044: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:1044: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:1047: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:1099: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:1101: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:1101: error: expected ';' before 'throw' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/limits:1104: error: expected `;' before 'static' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/memory: In function 'std::pair<_Tp*, long int> std::__get_temporary_buffer(ptrdiff_t, _Tp*)': /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/memory:76: error: 'max' is not a member of 'std::numeric_limits' /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.h: In member function 'int std::basic_string<_CharT, _Traits, _Alloc>::compare(const std::basic_string<_CharT, _Traits, _Alloc>&) const': /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.h:1928: error: expected unqualified-id before '(' token /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h: In function 'void std::__merge_sort_loop(_RandomAccessIterator1, _RandomAccessIterator1, _RandomAccessIterator2, _Distance)': /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:3232: error: expected unqualified-id before '(' token /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h: In function 'void std::__merge_sort_loop(_RandomAccessIterator1, _RandomAccessIterator1, _RandomAccessIterator2, _Distance, _Compare)': /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:3255: error: expected unqualified-id before '(' token /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.tcc: In member function 'typename std::basic_string<_CharT, _Traits, _Alloc>::size_type std::basic_string<_CharT, _Traits, _Alloc>::rfind(const _CharT*, typename _Alloc::rebind<_CharT>::other::size_type, typename _Alloc::rebind<_CharT>::other::size_type) const': /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.tcc:761: error: expected unqualified-id before '(' token /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.tcc: In member function 'int std::basic_string<_CharT, _Traits, _Alloc>::compare(typename _Alloc::rebind<_CharT>::other::size_type, typename _Alloc::rebind<_CharT>::other::size_type, const std::basic_string<_CharT, _Traits, _Alloc>&) const': /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.tcc:898: error: expected unqualified-id before '(' token /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.tcc: In member function 'int std::basic_string<_CharT, _Traits, _Alloc>::compare(typename _Alloc::rebind<_CharT>::other::size_type, typename _Alloc::rebind<_CharT>::other::size_type, const std::basic_string<_CharT, _Traits, _Alloc>&, typename _Alloc::rebind<_CharT>::other::size_type, typename _Alloc::rebind<_CharT>::other::size_type) const': /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.tcc:915: error: expected unqualified-id before '(' token /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.tcc: In member function 'int std::basic_string<_CharT, _Traits, _Alloc>::compare(const _CharT*) const': /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.tcc:931: error: expected unqualified-id before '(' token /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.tcc: In member function 'int std::basic_string<_CharT, _Traits, _Alloc>::compare(typename _Alloc::rebind<_CharT>::other::size_type, typename _Alloc::rebind<_CharT>::other::size_type, const _CharT*) const': /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.tcc:947: error: expected unqualified-id before '(' token /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.tcc: In member function 'int std::basic_string<_CharT, _Traits, _Alloc>::compare(typename _Alloc::rebind<_CharT>::other::size_type, typename _Alloc::rebind<_CharT>::other::size_type, const _CharT*, typename _Alloc::rebind<_CharT>::other::size_type) const': /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.tcc:963: error: expected unqualified-id before '(' token src/apps/diskusage/Snapshot.h: At global scope: src/apps/diskusage/Snapshot.h:25: error: 'string' has not been declared src/apps/diskusage/Snapshot.h:34: error: ISO C++ forbids declaration of 'vector' with no type src/apps/diskusage/Snapshot.h:34: error: expected ';' before '<' token src/apps/diskusage/Snapshot.h:42: error: 'string' does not name a type src/apps/diskusage/InfoWindow.cpp: In constructor 'InfoWin::InfoWin(BPoint, FileInfo*, BWindow*)': src/apps/diskusage/InfoWindow.cpp:57: error: 'string' was not declared in this scope src/apps/diskusage/InfoWindow.cpp:57: error: 'string' cannot appear in a constant-expression src/apps/diskusage/InfoWindow.cpp:57: error: template argument 1 is invalid src/apps/diskusage/InfoWindow.cpp:57: error: template argument 2 is invalid src/apps/diskusage/InfoWindow.cpp:57: error: invalid type in declaration before ';' token src/apps/diskusage/InfoWindow.cpp:58: error: expected initializer before '<' token src/apps/diskusage/InfoWindow.cpp:65: error: 'InfoList' was not declared in this scope src/apps/diskusage/InfoWindow.cpp:65: error: expected `;' before 'info' src/apps/diskusage/InfoWindow.cpp:76: error: 'info' was not declared in this scope src/apps/diskusage/InfoWindow.cpp:76: error: functional cast expression list treated as compound expression src/apps/diskusage/InfoWindow.cpp:76: warning: left-hand operand of comma has no effect src/apps/diskusage/InfoWindow.cpp:83: error: functional cast expression list treated as compound expression src/apps/diskusage/InfoWindow.cpp:83: warning: left-hand operand of comma has no effect src/apps/diskusage/InfoWindow.cpp:86: error: functional cast expression list treated as compound expression src/apps/diskusage/InfoWindow.cpp:86: warning: left-hand operand of comma has no effect src/apps/diskusage/InfoWindow.cpp:91: error: functional cast expression list treated as compound expression src/apps/diskusage/InfoWindow.cpp:91: warning: left-hand operand of comma has no effect src/apps/diskusage/InfoWindow.cpp:95: error: expected `;' before 'path' src/apps/diskusage/InfoWindow.cpp:96: error: 'path' was not declared in this scope src/apps/diskusage/InfoWindow.cpp:97: error: functional cast expression list treated as compound expression src/apps/diskusage/InfoWindow.cpp:115: error: 'InfoList' is not a class or namespace src/apps/diskusage/InfoWindow.cpp:115: error: expected `;' before 'i' src/apps/diskusage/InfoWindow.cpp:116: error: 'i' was not declared in this scope src/apps/diskusage/InfoWindow.cpp:146: error: 'i' was not declared in this scope src/apps/diskusage/InfoWindow.cpp:66: warning: unused variable 'item' /managed-dir/haiku/generated/cross-tools/bin/i586-pc-haiku-gcc -c "src/apps/diskusage/InfoWindow.cpp" -O -Wall -Wno-trigraphs -Wno-ctor-dtor-privacy -Woverloaded-virtual -Wpointer-arith -Wcast-align -Wsign-compare -fno-strict-aliasing -fno-tree-vrp -nostdinc -Wno-multichar -Wno-deprecated -D_ZETA_USING_DEPRECATED_API_=1 -D_ZETA_TS_FIND_DIR_=1 -D__HAIKU__ -DHAIKU_DISTRO_COMPATIBILITY_DEFAULT -D__INTEL__ -DARCH_x86 -DHAIKU_TARGET_PLATFORM_HAIKU -iquote build/user_config_headers -iquote build/config_headers -iquote src/apps/diskusage -iquote generated/objects/common/apps/diskusage -iquote generated/objects/cygwin/x86/common/apps/diskusage -iquote generated/objects/haiku/x86/common/apps/diskusage -I /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/include -I headers -I headers/posix -I headers/gnu -I headers/glibc -I headers/os -I headers/os/add-ons -I headers/os/add-ons/file_system -I headers/os/add-ons/graphics -I headers/os/add-ons/input_server -I headers/os/add-ons/ registrar -I headers/os/add-ons/screen_saver -I headers/os/add-ons/tracker -I headers/os/app -I headers/os/device -I headers/os/drivers -I headers/os/game -I headers/os/interface -I headers/os/kernel -I headers/os/media -I headers/os/mail -I headers/os/midi -I headers/os/midi2 -I headers/os/net -I headers/os/opengl -I headers/os/storage -I headers/os/support -I headers/os/translation -I headers/private/. -I /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2 -I /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/i586-pc-haiku -I /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/backward -I /managed-dir/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/ext -o "generated/objects/haiku/x86/release/apps/diskusage/InfoWindow.o" ; ...failed C++ generated/objects/haiku/x86/release/apps/diskusage/InfoWindow.o ... ...removing generated/objects/haiku/x86/release/apps/diskusage/InfoWindow.o ...skipped DiskUsage for lack of InfoWindow.o... ...skipped haiku.image-copy-files-dummy-beos/apps for lack of DiskUsage... ...skipped haiku.vmdk for lack of haiku.image-copy-files... ...failed updating 1 target(s)... ...skipped 3 target(s)... ...updated 14 target(s)... stefano.ceccherini at CECCHERINI /managed-dir/haiku $ From bonefish at mail.berlios.de Mon Sep 8 15:45:28 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Mon, 8 Sep 2008 15:45:28 +0200 Subject: [Haiku-commits] r27380 - haiku/trunk/src/system/kernel/vm Message-ID: <200809081345.m88DjSsb012768@sheep.berlios.de> Author: bonefish Date: 2008-09-08 15:45:27 +0200 (Mon, 08 Sep 2008) New Revision: 27380 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27380&view=rev Modified: haiku/trunk/src/system/kernel/vm/vm.cpp Log: When mapping a file into memory we do now immediately map all active pages into the team's address space. Doing that is relatively cheap and saves later page faults. Modified: haiku/trunk/src/system/kernel/vm/vm.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm.cpp 2008-09-08 13:27:31 UTC (rev 27379) +++ haiku/trunk/src/system/kernel/vm/vm.cpp 2008-09-08 13:45:27 UTC (rev 27380) @@ -2087,6 +2087,33 @@ } +/*! \a cache must be locked. The area's address space must be read-locked. +*/ +static void +pre_map_area_pages(vm_area* area, VMCache* cache) +{ + addr_t baseAddress = area->base; + addr_t cacheOffset = area->cache_offset; + page_num_t firstPage = cacheOffset / B_PAGE_SIZE; + page_num_t endPage = firstPage + area->size / B_PAGE_SIZE; + + for (VMCachePagesTree::Iterator it + = cache->pages.GetIterator(firstPage, true, true); + vm_page *page = it.Next();) { + if (page->cache_offset >= endPage) + break; + + // skip inactive pages + if (page->state == PAGE_STATE_BUSY || page->usage_count <= 0) + continue; + + vm_map_page(area, page, + baseAddress + (page->cache_offset * B_PAGE_SIZE - cacheOffset), + B_READ_AREA | B_KERNEL_READ_AREA); + } +} + + /*! Will map the file specified by \a fd to an area in memory. The file will be mirrored beginning at the specified \a offset. The \a offset and \a size arguments have to be page aligned. @@ -2139,6 +2166,38 @@ return status; CObjectDeleter vnodePutter(vnode, vfs_put_vnode); + // If we're going to pre-map pages, we need to reserve the pages needed by + // the mapping backend upfront. + page_num_t reservedPreMapPages = 0; + if ((protection & B_READ_AREA) != 0) { + AddressSpaceWriteLocker locker; + status = locker.SetTo(team); + if (status != B_OK) + return status; + + vm_translation_map *map = &locker.AddressSpace()->translation_map; + reservedPreMapPages = map->ops->map_max_pages_need(map, 0, size - 1); + + locker.Unlock(); + + vm_page_reserve_pages(reservedPreMapPages); + } + + struct PageUnreserver { + PageUnreserver(page_num_t count) + : fCount(count) + { + } + + ~PageUnreserver() + { + if (fCount > 0) + vm_page_unreserve_pages(fCount); + } + + page_num_t fCount; + } pageUnreserver(reservedPreMapPages); + AddressSpaceWriteLocker locker(team); if (!locker.IsLocked()) return B_BAD_TEAM_ID; @@ -2161,6 +2220,9 @@ cache->ReleaseRefLocked(); } + if (status == B_OK && (protection & B_READ_AREA) != 0) + pre_map_area_pages(area, cache); + cache->Unlock(); if (status < B_OK) From anevilyak at mail.berlios.de Mon Sep 8 15:49:54 2008 From: anevilyak at mail.berlios.de (anevilyak at BerliOS) Date: Mon, 8 Sep 2008 15:49:54 +0200 Subject: [Haiku-commits] r27381 - haiku/trunk/src/apps/diskusage Message-ID: <200809081349.m88Dns6e013060@sheep.berlios.de> Author: anevilyak Date: 2008-09-08 15:49:54 +0200 (Mon, 08 Sep 2008) New Revision: 27381 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27381&view=rev Modified: haiku/trunk/src/apps/diskusage/Common.h haiku/trunk/src/apps/diskusage/ControlsView.cpp haiku/trunk/src/apps/diskusage/InfoWindow.cpp haiku/trunk/src/apps/diskusage/PieView.cpp haiku/trunk/src/apps/diskusage/PieView.h haiku/trunk/src/apps/diskusage/Scanner.cpp haiku/trunk/src/apps/diskusage/Scanner.h haiku/trunk/src/apps/diskusage/Snapshot.h haiku/trunk/src/apps/diskusage/StatusView.cpp Log: gcc4 build fixes. Modified: haiku/trunk/src/apps/diskusage/Common.h =================================================================== --- haiku/trunk/src/apps/diskusage/Common.h 2008-09-08 13:45:27 UTC (rev 27380) +++ haiku/trunk/src/apps/diskusage/Common.h 2008-09-08 13:49:54 UTC (rev 27381) @@ -93,10 +93,6 @@ #define kScanProgress 'gSPR' #define kScanDone 'gSDN' -// support functions -#define max(x, y) ((x) > (y) ? (x) : (y)) -#define min(x, y) ((x) < (y) ? (x) : (y)) - #define deg2rad(x) (2.0 * M_PI * (x) / 360.0) #define rad2deg(x) (360.0 * (x) / (2.0 * M_PI)) Modified: haiku/trunk/src/apps/diskusage/ControlsView.cpp =================================================================== --- haiku/trunk/src/apps/diskusage/ControlsView.cpp 2008-09-08 13:45:27 UTC (rev 27380) +++ haiku/trunk/src/apps/diskusage/ControlsView.cpp 2008-09-08 13:49:54 UTC (rev 27381) @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -72,7 +73,7 @@ be_plain_font->GetHeight(&fh); float fontHeight = fh.ascent + fh.descent + fh.leading; if (fIcon) { - *height = max(fontHeight, fIcon->Bounds().Height()); + *height = max_c(fontHeight, fIcon->Bounds().Height()); *width += fIcon->Bounds().Width() + kSmallHMargin; } else *height = fontHeight; @@ -260,7 +261,7 @@ r.right = r.left - kSmallHMargin; buttonWidth = kButtonMargin + StringWidth(kStrRescan); - r.left = r.right - max(kMinButtonWidth, buttonWidth); + r.left = r.right - max_c(kMinButtonWidth, buttonWidth); fRescanButton = new BButton(r, NULL, kStrRescan, new BMessage(kBtnRescan), B_FOLLOW_RIGHT); Modified: haiku/trunk/src/apps/diskusage/InfoWindow.cpp =================================================================== --- haiku/trunk/src/apps/diskusage/InfoWindow.cpp 2008-09-08 13:45:27 UTC (rev 27380) +++ haiku/trunk/src/apps/diskusage/InfoWindow.cpp 2008-09-08 13:49:54 UTC (rev 27381) @@ -20,6 +20,8 @@ #include "Common.h" #include "Snapshot.h" +using std::string; +using std::vector; LeftView::LeftView(BRect frame, BBitmap* icon) : BView(frame, NULL, B_FOLLOW_NONE, B_WILL_DRAW), @@ -115,9 +117,9 @@ InfoList::iterator i = info.begin(); while (i != info.end()) { float w = smallFont.StringWidth((*i).first.c_str()) + 2.0 * kSmallHMargin; - leftWidth = max(leftWidth, w); + leftWidth = max_c(leftWidth, w); w = smallFont.StringWidth((*i).second.c_str()) + 2.0 * kSmallHMargin; - rightWidth = max(rightWidth, w); + rightWidth = max_c(rightWidth, w); i++; } Modified: haiku/trunk/src/apps/diskusage/PieView.cpp =================================================================== --- haiku/trunk/src/apps/diskusage/PieView.cpp 2008-09-08 13:45:27 UTC (rev 27380) +++ haiku/trunk/src/apps/diskusage/PieView.cpp 2008-09-08 13:49:54 UTC (rev 27381) @@ -94,7 +94,7 @@ be_plain_font->GetHeight(&fh); float fontHeight = ceilf(fh.ascent) + ceilf(fh.descent) + ceilf(fh.leading); - *_height = max(fontHeight, fIcon->Bounds().Height()); + *_height = max_c(fontHeight, fIcon->Bounds().Height()); } } Modified: haiku/trunk/src/apps/diskusage/PieView.h =================================================================== --- haiku/trunk/src/apps/diskusage/PieView.h 2008-09-08 13:45:27 UTC (rev 27380) +++ haiku/trunk/src/apps/diskusage/PieView.h 2008-09-08 13:49:54 UTC (rev 27381) @@ -25,6 +25,9 @@ class Scanner; class MainWindow; +using std::map; +using std::vector; + class PieView: public BView { public: PieView(BRect frame, MainWindow* window); Modified: haiku/trunk/src/apps/diskusage/Scanner.cpp =================================================================== --- haiku/trunk/src/apps/diskusage/Scanner.cpp 2008-09-08 13:45:27 UTC (rev 27380) +++ haiku/trunk/src/apps/diskusage/Scanner.cpp 2008-09-08 13:49:54 UTC (rev 27381) @@ -12,6 +12,7 @@ #include "Common.h" +using std::vector; Scanner::Scanner(BVolume *v, BHandler *handler) : BLooper(), Modified: haiku/trunk/src/apps/diskusage/Scanner.h =================================================================== --- haiku/trunk/src/apps/diskusage/Scanner.h 2008-09-08 13:45:27 UTC (rev 27380) +++ haiku/trunk/src/apps/diskusage/Scanner.h 2008-09-08 13:49:54 UTC (rev 27381) @@ -21,6 +21,8 @@ class BDirectory; +using std::string; + class Scanner: public BLooper { public: Scanner(BVolume* volume, BHandler* handler); Modified: haiku/trunk/src/apps/diskusage/Snapshot.h =================================================================== --- haiku/trunk/src/apps/diskusage/Snapshot.h 2008-09-08 13:45:27 UTC (rev 27380) +++ haiku/trunk/src/apps/diskusage/Snapshot.h 2008-09-08 13:49:54 UTC (rev 27381) @@ -18,11 +18,14 @@ class BMimeType; class BVolume; +using std::string; +using std::vector; + struct FileInfo { FileInfo(); ~FileInfo(); - void GetPath(string& path) const; + void GetPath(std::string& path) const; FileInfo* FindChild(const char* name) const; BMimeType* Type() const; @@ -31,7 +34,7 @@ off_t size; int count; FileInfo* parent; - vector children; + std::vector children; }; @@ -39,7 +42,7 @@ VolumeSnapshot(const BVolume* volume); ~VolumeSnapshot(); - string name; + std::string name; off_t capacity; off_t freeBytes; FileInfo* rootDir; Modified: haiku/trunk/src/apps/diskusage/StatusView.cpp =================================================================== --- haiku/trunk/src/apps/diskusage/StatusView.cpp 2008-09-08 13:45:27 UTC (rev 27380) +++ haiku/trunk/src/apps/diskusage/StatusView.cpp 2008-09-08 13:49:54 UTC (rev 27381) @@ -20,8 +20,8 @@ #include "Scanner.h" -StatusView::StatusView(BRect r) - : BView(r, NULL, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM, B_WILL_DRAW), +StatusView::StatusView(BRect rect) + : BView(rect, NULL, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM, B_WILL_DRAW), fCurrentFileInfo(NULL) { SetViewColor(kWindowColor); @@ -33,7 +33,7 @@ float fixedHeight = ceilf(fh.ascent) + ceilf(fh.descent) + ceilf(fh.leading); ResizeTo(Bounds().Width(), - 2.0 * kSmallVMargin + max(plainHeight, fixedHeight)); + 2.0 * kSmallVMargin + max_c(plainHeight, fixedHeight)); BRect r = Bounds(); r.top += kSmallVMargin; From superstippi at gmx.de Mon Sep 8 15:53:24 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Mon, 08 Sep 2008 15:53:24 +0200 Subject: [Haiku-commits] r27381 - haiku/trunk/src/apps/diskusage In-Reply-To: <200809081349.m88Dns6e013060@sheep.berlios.de> References: <200809081349.m88Dns6e013060@sheep.berlios.de> Message-ID: <20080908135324.307890@gmx.net> Hi, > Author: anevilyak > Date: 2008-09-08 15:49:54 +0200 (Mon, 08 Sep 2008) > New Revision: 27381 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27381&view=rev > > Modified: > haiku/trunk/src/apps/diskusage/Common.h > haiku/trunk/src/apps/diskusage/ControlsView.cpp > haiku/trunk/src/apps/diskusage/InfoWindow.cpp > haiku/trunk/src/apps/diskusage/PieView.cpp > haiku/trunk/src/apps/diskusage/PieView.h > haiku/trunk/src/apps/diskusage/Scanner.cpp > haiku/trunk/src/apps/diskusage/Scanner.h > haiku/trunk/src/apps/diskusage/Snapshot.h > haiku/trunk/src/apps/diskusage/StatusView.cpp > Log: > gcc4 build fixes. Thanks a lot, Stefano and Ren?! Sorry to have caused you work. I actually wanted to change the min/max stuff, but appearantly forgot about it later. Best regards, -Stephan From anevilyak at gmail.com Mon Sep 8 15:54:18 2008 From: anevilyak at gmail.com (Rene Gollent) Date: Mon, 8 Sep 2008 08:54:18 -0500 Subject: [Haiku-commits] r27381 - haiku/trunk/src/apps/diskusage In-Reply-To: <20080908135324.307890@gmx.net> References: <200809081349.m88Dns6e013060@sheep.berlios.de> <20080908135324.307890@gmx.net> Message-ID: On Mon, Sep 8, 2008 at 8:53 AM, Stephan Assmus wrote: > Thanks a lot, Stefano and Ren?! Sorry to have caused you work. I actually wanted to change the min/max stuff, but appearantly forgot about it later. No worries, hope I didn't step on any work in progress you had there :) Regards, Rene From stefano.ceccherini at gmail.com Mon Sep 8 15:56:52 2008 From: stefano.ceccherini at gmail.com (Stefano Ceccherini) Date: Mon, 8 Sep 2008 15:56:52 +0200 Subject: [Haiku-commits] r27381 - haiku/trunk/src/apps/diskusage In-Reply-To: <20080908135324.307890@gmx.net> References: <200809081349.m88Dns6e013060@sheep.berlios.de> <20080908135324.307890@gmx.net> Message-ID: <894b9700809080656gd3a3b47y45ff791b045efa0c@mail.gmail.com> 2008/9/8 Stephan Assmus : > Thanks a lot, Stefano and Ren?! Sorry to have caused you work. I actually wanted to change the min/max stuff, but appearantly forgot about it later. No problem, really. I just wanted to see DiskUsage in action :) From superstippi at gmx.de Mon Sep 8 15:57:27 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Mon, 08 Sep 2008 15:57:27 +0200 Subject: [Haiku-commits] r27381 - haiku/trunk/src/apps/diskusage In-Reply-To: References: <200809081349.m88Dns6e013060@sheep.berlios.de> <20080908135324.307890@gmx.net> Message-ID: <20080908135727.80660@gmx.net> -------- Original-Nachricht -------- > Datum: Mon, 8 Sep 2008 08:54:18 -0500 > Von: "Rene Gollent" > An: "SVN commits to the Haiku source repository" > Betreff: Re: [Haiku-commits] r27381 - haiku/trunk/src/apps/diskusage > On Mon, Sep 8, 2008 at 8:53 AM, Stephan Assmus wrote: > > Thanks a lot, Stefano and Ren?! Sorry to have caused you work. I > actually wanted to change the min/max stuff, but appearantly forgot about it > later. > > No worries, hope I didn't step on any work in progress you had there :) No, no... I was taking kind of a break here... :-) Best regards, -Stephan From stippi at mail.berlios.de Mon Sep 8 16:07:07 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Mon, 8 Sep 2008 16:07:07 +0200 Subject: [Haiku-commits] r27382 - haiku/trunk/src/add-ons/media/media-add-ons/opensound Message-ID: <200809081407.m88E77wX014745@sheep.berlios.de> Author: stippi Date: 2008-09-08 16:07:06 +0200 (Mon, 08 Sep 2008) New Revision: 27382 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27382&view=rev Modified: haiku/trunk/src/add-ons/media/media-add-ons/opensound/OpenSoundDeviceEngine.cpp Log: * Use the older fragments API for setting the driver buffer size, since it gives much more fine grained control. * Use a smaller buffer on Haiku, this will give some slight clicks when something is going on (for example launching Firefox), but should be bearable. The reduced latency is otherwise quite nice and VLC works again which outweights the seldom clicks. Obviously the best is to find and fix scheduler problems, but in the meantime, this may be more helpful to people. Modified: haiku/trunk/src/add-ons/media/media-add-ons/opensound/OpenSoundDeviceEngine.cpp =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/opensound/OpenSoundDeviceEngine.cpp 2008-09-08 13:49:54 UTC (rev 27381) +++ haiku/trunk/src/add-ons/media/media-add-ons/opensound/OpenSoundDeviceEngine.cpp 2008-09-08 14:07:06 UTC (rev 27382) @@ -35,7 +35,7 @@ CALLED(); fInitCheckStatus = B_NO_INIT; memcpy(&fAudioInfo, info, sizeof(oss_audioinfo)); - + // XXX:REMOVEME // set default format /* @@ -96,37 +96,28 @@ return EIO; } - // set latency policy = fragment size and total driver buffer size + // set driver buffer size by using the "fragments" API // TODO: export this setting as a BParameter? - // NOTE stippi: 4 means 2048 bytes driver buffer in my tests on a C-Media - // This latency is long enough for playback on BeOS. On Haiku, testing on - // HD Audio hardware, it is too short. However, I seem to remember the - // HD Audio supports 32 bit sample width (while C-Media supports "only" - // 16). If OSS uses the same 2048 bytes even for 32 bit/sample, then I - // could see how that would be asking for too much, since that would - // effectively half the latency. + // NOTE stippi: 2048 bytes driver buffer is long enough for playback on + // BeOS. On Haiku, testing on HD Audio hardware, it is too short. However, + // I seem to remember the HD Audio supports 32 bit sample width (while + // C-Media supports "only" 16). If OSS uses the same 2048 bytes even for + // 32 bit/sample, then I could see how that would be asking for too much, + // since that would effectively half the latency. + #ifdef HAIKU_TARGET_PLATFORM_HAIKU - v = 5; + uint32 bufferCount = 6; + uint32 bufferSize = 0x000b; // 1024 bytes #else - v = 4; + uint32 bufferCount = 4; + uint32 bufferSize = 0x000a; // 512 bytes #endif - if (ioctl(fFD, SNDCTL_DSP_POLICY, &v, sizeof(int)) < 0) { - if (errno != EIO && errno != EINVAL) { - fInitCheckStatus = errno; - Close(); - return EIO; - } - // TODO: use this older API as fallback: -#if 0 - // set fragments - v = 0x7fff0000 | 0x000b; // unlimited * 2048 - if (ioctl(fFD, SNDCTL_DSP_SETFRAGMENT, &v, sizeof(int)) < 0) { - fInitCheckStatus = errno; - Close(); - return EIO; - } -#endif + v = (bufferCount << 16) | bufferSize; + if (ioctl(fFD, SNDCTL_DSP_SETFRAGMENT, &v, sizeof(int)) < 0) { + fInitCheckStatus = errno; + Close(); + return EIO; } fDriverBufferSize = 2048; @@ -180,7 +171,7 @@ if (fFD < 0) return ENODEV; - + if (ioctl(fFD, SNDCTL_ENGINEINFO, &fAudioInfo, sizeof(oss_audioinfo)) < 0) return errno; @@ -216,7 +207,7 @@ int chans = -1; CALLED(); if (ioctl(fFD, SNDCTL_DSP_CHANNELS, &chans, sizeof(int)) < 0) { - PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", + PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", __FUNCTION__, "SNDCTL_DSP_CHANNELS", strerror(errno))); return -1; } @@ -227,7 +218,7 @@ { CALLED(); if (ioctl(fFD, SNDCTL_DSP_CHANNELS, &chans, sizeof(int)) < 0) { - PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", + PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", __FUNCTION__, "SNDCTL_DSP_CHANNELS", strerror(errno))); return EIO; } @@ -241,7 +232,7 @@ int fmt = -1; CALLED(); if (ioctl(fFD, SNDCTL_DSP_GETFMTS, &fmt, sizeof(int)) < 0) { - PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", + PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", __FUNCTION__, "SNDCTL_DSP_GETFMTS", strerror(errno))); return -1; } @@ -252,7 +243,7 @@ { CALLED(); if (ioctl(fFD, SNDCTL_DSP_SETFMT, &fmt, sizeof(int)) < 0) { - PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", + PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", __FUNCTION__, "SNDCTL_DSP_SETFMT", strerror(errno))); return EIO; } @@ -265,7 +256,7 @@ int speed = -1; CALLED(); if (ioctl(fFD, SNDCTL_DSP_SPEED, &speed, sizeof(int)) < 0) { - PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", + PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", __FUNCTION__, "SNDCTL_DSP_SPEED", strerror(errno))); return -1; } @@ -276,7 +267,7 @@ { CALLED(); if (ioctl(fFD, SNDCTL_DSP_SPEED, &speed, sizeof(int)) < 0) { - PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", + PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", __FUNCTION__, "SNDCTL_DSP_SPEED", strerror(errno))); return EIO; } @@ -295,7 +286,7 @@ if (!(fOpenMode & OPEN_READ)) return 0; if (ioctl(fFD, SNDCTL_DSP_GETISPACE, info, sizeof(audio_buf_info)) < 0) { - PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", + PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", __FUNCTION__, "SNDCTL_DSP_GETISPACE", strerror(errno))); return EIO; } @@ -314,7 +305,7 @@ if (!(fOpenMode & OPEN_WRITE)) return 0; if (ioctl(fFD, SNDCTL_DSP_GETOSPACE, info, sizeof(audio_buf_info)) < 0) { - PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", + PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", __FUNCTION__, "SNDCTL_DSP_GETOSPACE", strerror(errno))); return EIO; } @@ -335,12 +326,12 @@ if (!(fOpenMode & OPEN_READ)) return 0; if (ioctl(fFD, SNDCTL_DSP_CURRENT_IPTR, info, sizeof(oss_count_t)) < 0) { - PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", + PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", __FUNCTION__, "SNDCTL_DSP_CURRENT_IPTR", strerror(errno))); //return EIO; // fallback: try GET*PTR if (ioctl(fFD, SNDCTL_DSP_GETIPTR, &cinfo, sizeof(count_info)) < 0) { - PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", + PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", __FUNCTION__, "SNDCTL_DSP_GETIPTR", strerror(errno))); return 0; } @@ -371,7 +362,7 @@ memset(&info, 0, sizeof(oss_count_t)); if (ioctl(fFD, SNDCTL_DSP_CURRENT_OPTR, &info, sizeof(oss_count_t)) < 0) { - PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", + PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", __FUNCTION__, "SNDCTL_DSP_CURRENT_OPTR", strerror(errno))); return 0; @@ -380,7 +371,7 @@ if (fragmentPos != NULL) { count_info cinfo; if (ioctl(fFD, SNDCTL_DSP_GETOPTR, &cinfo, sizeof(count_info)) < 0) { - PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", + PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", __FUNCTION__, "SNDCTL_DSP_GETOPTR", strerror(errno))); return 0; } @@ -405,7 +396,7 @@ if (!(fOpenMode & OPEN_WRITE)) return 0; if (ioctl(fFD, SNDCTL_DSP_GETERROR, &info, sizeof(info)) < 0) { - PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", + PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", __FUNCTION__, "SNDCTL_DSP_GETERROR", strerror(errno))); return 0; } @@ -423,7 +414,7 @@ if (!(fOpenMode & OPEN_WRITE)) return 0; if (ioctl(fFD, SNDCTL_DSP_GETERROR, &info, sizeof(info)) < 0) { - PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", + PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", __FUNCTION__, "SNDCTL_DSP_GETERROR", strerror(errno))); return 0; } @@ -446,12 +437,12 @@ group.id = 0; group.mode = PCM_ENABLE_INPUT; if (ioctl(fFD, SNDCTL_DSP_SYNCGROUP, &group, sizeof(group)) < 0) { - PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", + PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", __FUNCTION__, "SNDCTL_DSP_SYNCGROUP", strerror(errno))); return EIO; } if (ioctl(fFD, SNDCTL_DSP_SYNCSTART, &group.id, sizeof(group.id)) < 0) { - PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", + PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", __FUNCTION__, "SNDCTL_DSP_SYNCSTART", strerror(errno))); return EIO; } @@ -546,14 +537,14 @@ err = WildcardFormatFor(fmt, wc); if (err < B_OK) return err; - + err = Open(rec ? OPEN_READ : OPEN_WRITE); if (err < B_OK) return err; - + if (format.type == B_MEDIA_RAW_AUDIO) { media_multi_audio_format &raw = format.u.raw_audio; - + // channel count raw.channel_count = MAX((unsigned)(Info()->min_channels), MIN((unsigned)(Info()->max_channels), raw.channel_count)); err = SetChannels(raw.channel_count); @@ -586,10 +577,10 @@ Close(); return err; } - + // endianness raw.byte_order = OpenSoundDevice::convert_oss_format_to_endian(afmt); - + // sample rate raw.frame_rate = OpenSoundDevice::select_oss_rate(Info(), raw.frame_rate); // measured in Hertz //raw.frame_rate = OpenSoundDevice::convert_oss_rate_to_media_rate(Info()->max_rate); // measured in Hertz @@ -648,14 +639,14 @@ err = WildcardFormatFor(fmt, wc); if (err < B_OK) return err; - + err = Open(rec ? OPEN_READ : OPEN_WRITE); if (err < B_OK) return err; - + if (format.type == B_MEDIA_RAW_AUDIO) { media_multi_audio_format &raw = format.u.raw_audio; - + PRINT(("%s:step1 fmt=0x%08x, raw.format=0x%08lx\n", __FUNCTION__, fmt, raw.format)); // select the best as default if (!raw.format) { @@ -686,7 +677,7 @@ Close(); return err; } - + // endianness if (!raw.byte_order) raw.byte_order = OpenSoundDevice::convert_oss_format_to_endian(afmt); @@ -694,7 +685,7 @@ Close(); return B_MEDIA_BAD_FORMAT; } - + // channel count if (raw.channel_count == 0) raw.channel_count = (unsigned)Info()->min_channels; @@ -716,7 +707,7 @@ Close(); return err; } - + #if 0 raw.buffer_size = DEFAULT_BUFFER_SIZE * (raw.format & media_raw_audio_format::B_AUDIO_SIZE_MASK) @@ -724,7 +715,7 @@ #endif audio_buf_info abinfo; if (ioctl(fFD, rec?SNDCTL_DSP_GETISPACE:SNDCTL_DSP_GETOSPACE, &abinfo, sizeof(abinfo)) < 0) { - PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", + PRINT(("OpenSoundDeviceEngine::%s: %s: %s\n", __FUNCTION__, "SNDCTL_DSP_GET?SPACE", strerror(errno))); return -1; } From jackburton at mail.berlios.de Mon Sep 8 16:42:40 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Mon, 8 Sep 2008 16:42:40 +0200 Subject: [Haiku-commits] r27383 - haiku/trunk/src/kits/interface Message-ID: <200809081442.m88Egeuf017864@sheep.berlios.de> Author: jackburton Date: 2008-09-08 16:42:38 +0200 (Mon, 08 Sep 2008) New Revision: 27383 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27383&view=rev Modified: haiku/trunk/src/kits/interface/View.cpp Log: added a comment explaining why the implementation should be moved to the server Modified: haiku/trunk/src/kits/interface/View.cpp =================================================================== --- haiku/trunk/src/kits/interface/View.cpp 2008-09-08 14:07:06 UTC (rev 27382) +++ haiku/trunk/src/kits/interface/View.cpp 2008-09-08 14:42:38 UTC (rev 27383) @@ -61,9 +61,7 @@ # define BVTRACE ; #endif -#define MAX_ATTACHMENT_SIZE 49152 - static property_info sViewPropInfo[] = { { "Frame", { B_GET_PROPERTY, 0 }, { B_DIRECT_SPECIFIER, 0 }, "Returns the view's frame rectangle.", 0, @@ -4400,7 +4398,10 @@ #if 1 // TODO: Move the implementation to the server!!! - + // This implementation is pretty slow, since just creating an offscreen bitmap + // takes a lot of time. That's the main reason why it should be moved + // to the server. + // Here the idea is to get rid of the padding bytes in the bitmap, // as padding complicates and slows down the iteration. // TODO: Maybe it's not so nice as it assumes BBitmaps to be aligned @@ -4433,7 +4434,7 @@ for (int32 y = 0; y < height; y++) { for (int32 x = 0; x < width; x++) { bit = *bits++; - if (bit != (uint32)-1) { + if (bit != 0xFFFFFFFF) { rect.left = x; rect.right = rect.left; rect.top = rect.bottom = y; From julun at mail.berlios.de Mon Sep 8 22:23:00 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Mon, 8 Sep 2008 22:23:00 +0200 Subject: [Haiku-commits] r27384 - haiku/trunk/src/servers/app Message-ID: <200809082023.m88KN0B5008408@sheep.berlios.de> Author: julun Date: 2008-09-08 22:23:00 +0200 (Mon, 08 Sep 2008) New Revision: 27384 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27384&view=rev Modified: haiku/trunk/src/servers/app/ServerWindow.cpp Log: * comment the code that prevents programmatically resize events during a user resize, this makes ArtPAint's tool pallete window resize properly Thanks Stephan for explaining me two time what to look for :) Modified: haiku/trunk/src/servers/app/ServerWindow.cpp =================================================================== --- haiku/trunk/src/servers/app/ServerWindow.cpp 2008-09-08 14:42:38 UTC (rev 27383) +++ haiku/trunk/src/servers/app/ServerWindow.cpp 2008-09-08 20:23:00 UTC (rev 27384) @@ -889,16 +889,18 @@ STRACE(("ServerWindow %s: Message AS_WINDOW_RESIZE %.1f, %.1f\n", Title(), xResizeBy, yResizeBy)); - if (fWindow->IsResizing()) { + // comment this code for the time being, as some apps rely + // on the programmatically resize behavior during user resize +// if (fWindow->IsResizing()) { // While the user resizes the window, we ignore // pragmatically set window bounds - fLink.StartMessage(B_BUSY); - } else { +// fLink.StartMessage(B_BUSY); +// } else { //fDesktop->UnlockSingleWindow(); fDesktop->ResizeWindowBy(fWindow, xResizeBy, yResizeBy); //fDesktop->LockSingleWindow(); fLink.StartMessage(B_OK); - } +// } fLink.Flush(); break; } @@ -2198,13 +2200,13 @@ { DTRACE(("ServerWindow %s: Message AS_STROKE/FILL_TRIANGLE\n", Title())); - BPoint pts[3]; + BPoint pts[3]; BRect rect; - for (int32 i = 0; i < 3; i++) { + for (int32 i = 0; i < 3; i++) { link.Read(&(pts[i])); fCurrentView->ConvertToScreenForDrawing(&pts[i]); - } + } link.Read(&rect); From bonefish at mail.berlios.de Tue Sep 9 01:03:54 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Tue, 9 Sep 2008 01:03:54 +0200 Subject: [Haiku-commits] r27385 - haiku/trunk/build/jam Message-ID: <200809082303.m88N3rnC001246@sheep.berlios.de> Author: bonefish Date: 2008-09-09 01:03:52 +0200 (Tue, 09 Sep 2008) New Revision: 27385 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27385&view=rev Modified: haiku/trunk/build/jam/OverriddenJamRules Log: * When using the generic attribute emulation the Link actions does now first remove the target and its attributes (if any). Before gcc would just unlink it and leak the attributes, which could lead to later mixups, if the file's inode ID was re-used. As reported by Rene this improves the attribute mixup situation, but doesn't solve it completely. So that status quo is still the same: When using the generic attribute emulation one has to build from the scratch to be sure all attributes are fine. * Got rid of superfluous whitespace. Modified: haiku/trunk/build/jam/OverriddenJamRules =================================================================== --- haiku/trunk/build/jam/OverriddenJamRules 2008-09-08 20:23:00 UTC (rev 27384) +++ haiku/trunk/build/jam/OverriddenJamRules 2008-09-08 23:03:52 UTC (rev 27385) @@ -11,7 +11,7 @@ } #------------------------------------------------------------------------------- -# Link rule/action are overwritten as they don't handle linking files who's name +# Link rule/action are overwritten as they don't handle linking files who's name # contain spaces very well. Also adds resources and version to executable. #------------------------------------------------------------------------------- rule Link @@ -29,7 +29,7 @@ NEEDLIBS on $(1) = [ on $(1) return $(NEEDLIBS) ] ; LINKLIBS on $(1) = [ on $(1) return $(LINKLIBS) ] ; - + MODE on $(<) = $(EXEMODE) ; on $(1) XRes $(1) : $(RESFILES) ; if ! [ on $(1) return $(DONT_USE_BEOS_RULES) ] { @@ -46,9 +46,24 @@ Chmod $(<) ; } -actions Link bind NEEDLIBS LINK_BEGIN_GLUE LINK_END_GLUE -{ - $(LINK) $(LINKFLAGS) -o "$(1)" $(UNDEFS) "$(LINK_BEGIN_GLUE)" "$(2)" "$(NEEDLIBS)" $(LINKLIBS) "$(LINK_END_GLUE)" ; +# When using "real" attributes (i.e. BeOS attributes or xattr/extattr) on the +# host platform, unlinking the main target by gcc will also automatically get +# rid of the attributes. When using the generic attribute emulation, which +# uses separate files, we need to remove the target explicitely first, so that +# the attributes won't be "leaked". +if $(HOST_PLATFORM_BEOS_COMPATIBLE) || $(HAIKU_HOST_USE_XATTR) = 1 { + actions Link bind NEEDLIBS LINK_BEGIN_GLUE LINK_END_GLUE + { + $(LINK) $(LINKFLAGS) -o "$(1)" $(UNDEFS) "$(LINK_BEGIN_GLUE)" "$(2)" \ + "$(NEEDLIBS)" $(LINKLIBS) "$(LINK_END_GLUE)" ; + } +} else { + actions Link bind NEEDLIBS LINK_BEGIN_GLUE LINK_END_GLUE + { + $(RM) "$(1)" + $(LINK) $(LINKFLAGS) -o "$(1)" $(UNDEFS) "$(LINK_BEGIN_GLUE)" "$(2)" \ + "$(NEEDLIBS)" $(LINKLIBS) "$(LINK_END_GLUE)" ; + } } rule Object @@ -57,7 +72,7 @@ local headers ; local sysHeaders ; local defines ; - + on $(1) { # use on $(1) variable values if ! $(PLATFORM) in $(SUPPORTED_PLATFORMS) { return ; @@ -77,11 +92,11 @@ if $(PLATFORM) = host { sysHeaders += $(HOST_HDRS) ; defines += $(HOST_DEFINES) ; - + if $(USES_BE_API) { sysHeaders += $(HOST_BE_API_HEADERS) ; } - + } else { sysHeaders += $(TARGET_HDRS) ; defines += $(TARGET_DEFINES) ; @@ -102,12 +117,12 @@ # the regexp pattern $(HDRSCAN) and then invokes $(HDRRULE) # with the scanned file as the target and the found headers # as the sources. HDRSEARCH is the value of SEARCH used for - # the found header files. Finally, if jam must deal with + # the found header files. Finally, if jam must deal with # header files of the same name in different directories, # they can be distinguished with HDRGRIST. - # $(SEARCH_SOURCE:E) is where cc first looks for #include - # "foo.h" files. If the source file is in a distant directory, + # $(SEARCH_SOURCE:E) is where cc first looks for #include + # "foo.h" files. If the source file is in a distant directory, # look there. Else, look in "" (the current directory). HDRRULE on $(>) = HdrRule ; @@ -162,7 +177,7 @@ local systemIncludesOption ; if [ on $(1) return $(PLATFORM) ] = host { flags = [ on $(1) return $(HOST_ASFLAGS) $(ASFLAGS) ] ; - + CC on $(1) = $(HOST_CC) ; includesSeparator = $(HOST_INCLUDES_SEPARATOR) ; @@ -171,7 +186,7 @@ } else { flags = [ on $(1) return $(TARGET_ASFLAGS) $(ASFLAGS) ] ; - + CC on $(1) = $(TARGET_CC) ; includesSeparator = $(TARGET_INCLUDES_SEPARATOR) ; @@ -292,7 +307,7 @@ } } -actions Cc +actions Cc { $(CC) $(CCFLAGS) -c "$(2)" $(CCDEFS) $(CCHDRS) -o "$(1)" ; } @@ -306,30 +321,30 @@ local includesSeparator ; local localIncludesOption ; local systemIncludesOption ; - + # optimization flags if $(DEBUG) = 0 { flags += $(OPTIM) ; } else { flags += -O0 ; } - + if $(PLATFORM) = host { # warning flags if $(WARNINGS) != 0 { flags += $(HOST_WARNING_C++FLAGS) ; } - + # debug and other flags flags += $(HOST_C++FLAGS) $(HOST_DEBUG_$(DEBUG)_C++FLAGS) $(SUBDIRC++FLAGS) $(C++FLAGS) ; - + if $(USES_BE_API) { flags += $(HOST_BE_API_C++FLAGS) ; } - + C++ on $(1) = $(HOST_C++) ; - + includesSeparator = $(HOST_INCLUDES_SEPARATOR) ; localIncludesOption = $(HOST_LOCAL_INCLUDES_OPTION) ; systemIncludesOption = $(HOST_SYSTEM_INCLUDES_OPTION) ; @@ -339,18 +354,18 @@ if $(WARNINGS) != 0 { flags += $(TARGET_WARNING_C++FLAGS) ; } - + # debug and other flags flags += $(TARGET_C++FLAGS) $(TARGET_DEBUG_$(DEBUG)_C++FLAGS) $(SUBDIRC++FLAGS) $(C++FLAGS) ; - + C++ on $(1) = $(TARGET_C++) ; includesSeparator = $(TARGET_INCLUDES_SEPARATOR) ; localIncludesOption = $(TARGET_LOCAL_INCLUDES_OPTION) ; systemIncludesOption = $(TARGET_SYSTEM_INCLUDES_OPTION) ; } - + C++FLAGS on $(<) = $(flags) ; CCHDRS on $(<) = [ FIncludes $(HDRS) : $(localIncludesOption) ] $(includesSeparator) @@ -403,21 +418,21 @@ AR on $(_l) = $(TARGET_AR) $(TARGET_ARFLAGS) ; RANLIB on $(_l) = $(TARGET_RANLIB) ; } - + # library depends on its member objects - + if $(KEEPOBJS) { LocalDepends obj : $(_s) ; } - + LocalDepends lib : $(_l) ; - + # Set LOCATE for the library and its contents. The bound # value shows up as $(NEEDLIBS) on the Link actions. # For compatibility, we only do this if the library doesn't # already have a path. - + if ! $(_l:D) { # locate the library only, if it hasn't been located yet @@ -430,13 +445,13 @@ } MakeLocate $(_l)($(_s:BS)) : $(dir) ; } - - if $(NOARSCAN) - { + + if $(NOARSCAN) + { # If we can't scan the library to timestamp its contents, # we have to just make the library depend directly on the - # on-disk object files. - + # on-disk object files. + Depends $(_l) : $(_s) ; } else @@ -444,26 +459,26 @@ # If we can scan the library, we make the library depend # on its members and each member depend on the on-disk # object file. - + Depends $(_l) : $(_l)($(_s:BS)) ; - + for _i in $(_s) { Depends $(_l)($(_i:BS)) : $(_i) ; } } - + LocalClean clean : $(_l) ; - + # bonefish: Not needed on the supported platforms. Maybe later... # if $(CRELIB) { CreLib $(_l) : $(_s[1]) ; } - + Archive $(_l) : $(_s) ; - + if $(RANLIB) { Ranlib $(_l) ; } - + # If we can't scan the library, we have to leave the .o's around. - + if ! ( $(KEEPOBJS) || $(NOARSCAN) || $(NOARUPDATE) ) { RmTemps $(_l) : $(_s) ; } @@ -549,7 +564,7 @@ local s ; # Cheesy gate to prevent multiple invocations on same dir - # MkDir1 has the actions + # MkDir1 has the actions # Arrange for jam dirs $(dir:G=)-mkdir = true ; @@ -560,7 +575,7 @@ # $(dir:P) = $(dir)'s parent, & we recurse until root s = $(dir:P) ; # parent keeps grist - + if $(s:G=) && $(s) != $(dir) { Depends $(dir) : $(s) ; dir = $(s) ; From jackburton at mail.berlios.de Tue Sep 9 10:13:49 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Tue, 9 Sep 2008 10:13:49 +0200 Subject: [Haiku-commits] r27386 - haiku/trunk/build/jam Message-ID: <200809090813.m898Dn2r020011@sheep.berlios.de> Author: jackburton Date: 2008-09-09 10:13:47 +0200 (Tue, 09 Sep 2008) New Revision: 27386 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27386&view=rev Modified: haiku/trunk/build/jam/NetBootArchive Log: applied patch by Olivier Coursire which removes block_io from the NetBootArchive script (bug #2714) Modified: haiku/trunk/build/jam/NetBootArchive =================================================================== --- haiku/trunk/build/jam/NetBootArchive 2008-09-08 23:03:52 UTC (rev 27385) +++ haiku/trunk/build/jam/NetBootArchive 2008-09-09 08:13:47 UTC (rev 27386) @@ -42,7 +42,7 @@ AddFilesToNetBootArchive beos system add-ons kernel file_systems : $(BEOS_ADD_ONS_FILE_SYSTEMS) ; AddFilesToNetBootArchive beos system add-ons kernel generic - : block_io ide_adapter locked_pool scsi_periph ; + : ide_adapter locked_pool scsi_periph ; AddFilesToNetBootArchive beos system add-ons kernel partitioning_systems : intel session ; AddFilesToNetBootArchive beos system add-ons kernel interrupt_controllers @@ -86,7 +86,7 @@ $(BEOS_ADD_ONS_BUS_MANAGERS) ahci generic_ide_pci $(X86_ONLY)ide_isa silicon_image_3112 $(BEOS_ADD_ONS_FILE_SYSTEMS) - block_io ide_adapter locked_pool scsi_periph + ide_adapter locked_pool scsi_periph intel session $(PPC_ONLY)openpic $(X86_ONLY)generic_x86 From axeld at pinc-software.de Tue Sep 9 10:33:38 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Tue, 09 Sep 2008 10:33:38 +0200 CEST Subject: [Haiku-commits] =?utf-8?q?r27246_-_in_haiku/trunk=3A_headers/os/d?= =?utf-8?q?rivers_headers/private/fs=5Fshell__src/add-ons/kernel/file=5Fsy?= =?utf-8?q?stems/bfs_src/add-ons/kernel/file=5Fsystems/ext2_src/add-ons/ke?= =?utf-8?q?rnel/file=5Fsystems/fat_src/system/kernel/cache_src/tools/fs=5F?= =?utf-8?q?shell?= In-Reply-To: <200808302306.m7UN6fKW027316@sheep.berlios.de> Message-ID: <3210030481-BeMail@zon> bonefish at mail.berlios.de wrote: > * Added parameter "size_t align" to file_map_translate(). If > 1, the > vector at the end of the file will be aligned to the given value. Is the "align" value likely to be changed? Because if not, we could also move it to the construction of the file map. Bye, Axel. From axeld at pinc-software.de Tue Sep 9 11:19:27 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Tue, 09 Sep 2008 11:19:27 +0200 CEST Subject: [Haiku-commits] r27236 - haiku/trunk/src/apps/deskbar In-Reply-To: <200808291931.m7TJVExn016907@sheep.berlios.de> Message-ID: <5959662682-BeMail@zon> julun at BerliOS wrote: > Log: > * Reuse calendar from shared to have a bitmore advanced panel > while holding down the mouse over the date area in Deskbar. Nice one! IMO the UI looks a bit alien to the rest, though. Bye, Axel. From jackburton at mail.berlios.de Tue Sep 9 11:53:30 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Tue, 9 Sep 2008 11:53:30 +0200 Subject: [Haiku-commits] r27387 - haiku/trunk/src/servers/app Message-ID: <200809090953.m899rUFp031309@sheep.berlios.de> Author: jackburton Date: 2008-09-09 11:53:27 +0200 (Tue, 09 Sep 2008) New Revision: 27387 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27387&view=rev Modified: haiku/trunk/src/servers/app/Jamfile haiku/trunk/src/servers/app/ServerApp.cpp haiku/trunk/src/servers/app/ServerWindow.cpp Log: Remove unused RamLinkMsgReader. Its functionality was integrated inside LinkMsgReader/Sender by Julun. Modified: haiku/trunk/src/servers/app/Jamfile =================================================================== --- haiku/trunk/src/servers/app/Jamfile 2008-09-09 08:13:47 UTC (rev 27386) +++ haiku/trunk/src/servers/app/Jamfile 2008-09-09 09:53:27 UTC (rev 27387) @@ -42,7 +42,6 @@ OffscreenWindow.cpp PNGDump.cpp ProfileMessageSupport.cpp - RAMLinkMsgReader.cpp RGBColor.cpp RegionPool.cpp Screen.cpp Modified: haiku/trunk/src/servers/app/ServerApp.cpp =================================================================== --- haiku/trunk/src/servers/app/ServerApp.cpp 2008-09-09 08:13:47 UTC (rev 27386) +++ haiku/trunk/src/servers/app/ServerApp.cpp 2008-09-09 09:53:27 UTC (rev 27387) @@ -29,7 +29,6 @@ #include "HWInterface.h" #include "InputManager.h" #include "OffscreenServerWindow.h" -#include "RAMLinkMsgReader.h" #include "Screen.h" #include "ServerApp.h" #include "ServerBitmap.h" Modified: haiku/trunk/src/servers/app/ServerWindow.cpp =================================================================== --- haiku/trunk/src/servers/app/ServerWindow.cpp 2008-09-09 08:13:47 UTC (rev 27386) +++ haiku/trunk/src/servers/app/ServerWindow.cpp 2008-09-09 09:53:27 UTC (rev 27387) @@ -29,7 +29,6 @@ #include "HWInterface.h" #include "Overlay.h" #include "ProfileMessageSupport.h" -#include "RAMLinkMsgReader.h" #include "RenderingBuffer.h" #include "ServerApp.h" #include "ServerBitmap.h" From jackburton at mail.berlios.de Tue Sep 9 11:54:09 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Tue, 9 Sep 2008 11:54:09 +0200 Subject: [Haiku-commits] r27388 - haiku/trunk/src/servers/app Message-ID: <200809090954.m899s9id031335@sheep.berlios.de> Author: jackburton Date: 2008-09-09 11:54:07 +0200 (Tue, 09 Sep 2008) New Revision: 27388 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27388&view=rev Removed: haiku/trunk/src/servers/app/RAMLinkMsgReader.cpp haiku/trunk/src/servers/app/RAMLinkMsgReader.h Log: Should have been part of the previous commit Deleted: haiku/trunk/src/servers/app/RAMLinkMsgReader.cpp Deleted: haiku/trunk/src/servers/app/RAMLinkMsgReader.h From superstippi at gmx.de Tue Sep 9 12:06:47 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Tue, 09 Sep 2008 12:06:47 +0200 Subject: [Haiku-commits] r27236 - haiku/trunk/src/apps/deskbar In-Reply-To: <5959662682-BeMail@zon> References: <5959662682-BeMail@zon> Message-ID: <20080909100647.282360@gmx.net> -------- Original-Nachricht -------- > Datum: Tue, 09 Sep 2008 11:19:27 +0200 CEST > Von: "Axel D?rfler" > An: "SVN commits to the Haiku sourcerepository=?utf-8?q?" > Betreff: Re: [Haiku-commits] r27236 - haiku/trunk/src/apps/deskbar > julun at BerliOS wrote: > > Log: > > * Reuse calendar from shared to have a bitmore advanced panel > > while holding down the mouse over the date area in Deskbar. > > Nice one! > IMO the UI looks a bit alien to the rest, though. Yes, this was definitely very useful! The only irritation is that when you change the month (for example to peak ahead), the date with the same month day is still marked, even though it has nothing to do with the current date. Maybe the calendar view could be set into some kind of read-only mode? Best regards, -Stephan From ingo_weinhold at gmx.de Tue Sep 9 13:58:39 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Tue, 09 Sep 2008 13:58:39 +0200 Subject: [Haiku-commits] r27246 - in haiku/trunk: headers/os/drivers headers/private/fs_shell src/add-ons/kernel/file_systems/bfs src/add-ons/kernel/file_systems/ext2 src/add-ons/kernel/file_systems/fat src/system/kernel/cache src/tools/fs_shell In-Reply-To: <3210030481-BeMail@zon> References: <3210030481-BeMail@zon> Message-ID: <20080909135839.527.1@knochen-vm.localdomain> On 2008-09-09 at 10:33:38 [+0200], Axel D?rfler wrote: > bonefish at mail.berlios.de wrote: > > * Added parameter "size_t align" to file_map_translate(). If > 1, the > > vector at the end of the file will be aligned to the given value. > > Is the "align" value likely to be changed? Because if not, we could > also move it to the construction of the file map. Currently the {read,write}_pages() hooks still use file_map_translate() without alignment. I haven't investigated whether using an alignment there, too, would be safe. These hooks are obsolete (save in FS shell), so I guess it should have no effect. CU, Ingo From jackburton at mail.berlios.de Tue Sep 9 15:28:32 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Tue, 9 Sep 2008 15:28:32 +0200 Subject: [Haiku-commits] r27389 - haiku/trunk/src/kits/interface Message-ID: <200809091328.m89DSWhC013277@sheep.berlios.de> Author: jackburton Date: 2008-09-09 15:28:30 +0200 (Tue, 09 Sep 2008) New Revision: 27389 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27389&view=rev Modified: haiku/trunk/src/kits/interface/Bitmap.cpp Log: non 32 bit offscreen bitmaps were never cleared to white, due to the way they currently work: when the offscreen window is created, the current content of the bitmap is copied to the back buffer, and since the clearing came later, it was never copied to it. This fixes the problem with FlattenPictureTest not working correctly for colorspace different than RGB(A)32. Modified: haiku/trunk/src/kits/interface/Bitmap.cpp =================================================================== --- haiku/trunk/src/kits/interface/Bitmap.cpp 2008-09-09 09:54:07 UTC (rev 27388) +++ haiku/trunk/src/kits/interface/Bitmap.cpp 2008-09-09 13:28:30 UTC (rev 27389) @@ -1055,16 +1055,6 @@ fInitError = error; if (fInitError == B_OK) { - if (flags & B_BITMAP_ACCEPTS_VIEWS) { - fWindow = new(std::nothrow) BWindow(Bounds(), fServerToken); - if (fWindow) { - // A BWindow starts life locked and is unlocked - // in Show(), but this window is never shown and - // it's message loop is never started. - fWindow->Unlock(); - } else - fInitError = B_NO_MEMORY; - } // clear to white if the flags say so. if (flags & (B_BITMAP_CLEAR_TO_WHITE | B_BITMAP_ACCEPTS_VIEWS)) { if (fColorSpace == B_CMAP8) { @@ -1076,6 +1066,20 @@ memset(fBasePointer, 0xff, fSize); } } + // TODO: Creating an offscreen window with a non32 bit bitmap + // copies the current content of the bitmap to a back buffer. + // So at this point the bitmap has to be already cleared to white. + // Better move the above code to the server so the problem looks more clear. + if (flags & B_BITMAP_ACCEPTS_VIEWS) { + fWindow = new(std::nothrow) BWindow(Bounds(), fServerToken); + if (fWindow) { + // A BWindow starts life locked and is unlocked + // in Show(), but this window is never shown and + // it's message loop is never started. + fWindow->Unlock(); + } else + fInitError = B_NO_MEMORY; + } } } From superstippi at gmx.de Tue Sep 9 15:40:41 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Tue, 09 Sep 2008 15:40:41 +0200 Subject: [Haiku-commits] r27389 - haiku/trunk/src/kits/interface In-Reply-To: <200809091328.m89DSWhC013277@sheep.berlios.de> References: <200809091328.m89DSWhC013277@sheep.berlios.de> Message-ID: <20080909134041.95960@gmx.net> -------- Original-Nachricht -------- > Datum: Tue, 9 Sep 2008 15:28:32 +0200 > Von: jackburton at mail.berlios.de > An: haiku-commits at lists.berlios.de > Betreff: [Haiku-commits] r27389 - haiku/trunk/src/kits/interface > Author: jackburton > Date: 2008-09-09 15:28:30 +0200 (Tue, 09 Sep 2008) > New Revision: 27389 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27389&view=rev > > Modified: > haiku/trunk/src/kits/interface/Bitmap.cpp > Log: > non 32 bit offscreen bitmaps were never cleared to white, due to the way > they currently work: when the offscreen window is created, the current > content of the bitmap is copied to the back buffer, and since the clearing came > later, it was never copied to it. This fixes the problem with > FlattenPictureTest not working correctly for colorspace different than RGB(A)32. Nice one! Best regards, -Stephan From stefano.ceccherini at gmail.com Tue Sep 9 15:49:08 2008 From: stefano.ceccherini at gmail.com (Stefano Ceccherini) Date: Tue, 9 Sep 2008 15:49:08 +0200 Subject: [Haiku-commits] r27389 - haiku/trunk/src/kits/interface In-Reply-To: <20080909134041.95960@gmx.net> References: <200809091328.m89DSWhC013277@sheep.berlios.de> <20080909134041.95960@gmx.net> Message-ID: <894b9700809090649q368252a2wc4fa954436c309ad@mail.gmail.com> 2008/9/9 Stephan Assmus : > > -------- Original-Nachricht -------- >> Datum: Tue, 9 Sep 2008 15:28:32 +0200 >> Von: jackburton at mail.berlios.de >> An: haiku-commits at lists.berlios.de >> Betreff: [Haiku-commits] r27389 - haiku/trunk/src/kits/interface > >> Author: jackburton >> Date: 2008-09-09 15:28:30 +0200 (Tue, 09 Sep 2008) >> New Revision: 27389 >> ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27389&view=rev >> >> Modified: >> haiku/trunk/src/kits/interface/Bitmap.cpp >> Log: >> non 32 bit offscreen bitmaps were never cleared to white, due to the way >> they currently work: when the offscreen window is created, the current >> content of the bitmap is copied to the back buffer, and since the clearing came >> later, it was never copied to it. This fixes the problem with >> FlattenPictureTest not working correctly for colorspace different than RGB(A)32. > > Nice one! > > Best regards, > -Stephan Thanks! Btw, I noticed that in some cases bitmaps are cleared to white *twice*, since the BitmapManager in the server clears the bitmaps it creates. Not every bitmap is created through it, though. The UtilityBitmaps in the server, for example, are not. From axeld at mail.berlios.de Tue Sep 9 17:18:51 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 9 Sep 2008 17:18:51 +0200 Subject: [Haiku-commits] r27390 - haiku/trunk/src/system/boot/platform/bios_ia32 Message-ID: <200809091518.m89FIplj024790@sheep.berlios.de> Author: axeld Date: 2008-09-09 17:18:51 +0200 (Tue, 09 Sep 2008) New Revision: 27390 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27390&view=rev Modified: haiku/trunk/src/system/boot/platform/bios_ia32/video.cpp Log: * closest_video_mode() now only returns modes with a width less or equal than the one specified. This should fix the "video mode out of range" message of your monitor during boot, in case you had that one. Thanks to Hartmut Reh for his help to be able to spot this. * The mode returned by find_edid_mode(..., true) was never used. * find_edid_mode() did not return any mode if there were no detailed modes available. Modified: haiku/trunk/src/system/boot/platform/bios_ia32/video.cpp =================================================================== --- haiku/trunk/src/system/boot/platform/bios_ia32/video.cpp 2008-09-09 13:28:30 UTC (rev 27389) +++ haiku/trunk/src/system/boot/platform/bios_ia32/video.cpp 2008-09-09 15:18:51 UTC (rev 27390) @@ -117,6 +117,10 @@ } +/*! Returns the VESA mode closest to the one specified, with a width less or + equal as specified. + The height as well as the depth may vary in both directions, though. +*/ static video_mode * closest_video_mode(int32 width, int32 height, int32 depth) { @@ -126,6 +130,12 @@ video_mode *mode = NULL; while ((mode = (video_mode *)list_get_next_item(&sModeList, mode)) != NULL) { + if (mode->width > width) { + // Only choose modes with a width less or equal than the searched + // one; or else it might well be that the monitor cannot keep up. + continue; + } + uint32 diff = 2 * abs(mode->width - width) + abs(mode->height - height) + abs(mode->bits_per_pixel - depth); @@ -173,7 +183,7 @@ } } - return NULL; + return mode; } @@ -1097,7 +1107,7 @@ // mode video_mode *defaultMode = find_edid_mode(info, false); if (defaultMode == NULL) - find_edid_mode(info, true); + defaultMode = find_edid_mode(info, true); if (defaultMode != NULL) { // We found a new default mode to use! From anevilyak at gmail.com Tue Sep 9 18:39:31 2008 From: anevilyak at gmail.com (Rene Gollent) Date: Tue, 9 Sep 2008 11:39:31 -0500 Subject: [Haiku-commits] r27390 - haiku/trunk/src/system/boot/platform/bios_ia32 In-Reply-To: <200809091518.m89FIplj024790@sheep.berlios.de> References: <200809091518.m89FIplj024790@sheep.berlios.de> Message-ID: On Tue, Sep 9, 2008 at 10:18 AM, axeld at BerliOS wrote: > Author: axeld > Date: 2008-09-09 17:18:51 +0200 (Tue, 09 Sep 2008) > New Revision: 27390 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27390&view=rev > > Modified: > haiku/trunk/src/system/boot/platform/bios_ia32/video.cpp > Log: > * closest_video_mode() now only returns modes with a width less or equal than > the one specified. This should fix the "video mode out of range" message of > your monitor during boot, in case you had that one. Thanks to Hartmut Reh > for his help to be able to spot this. > * The mode returned by find_edid_mode(..., true) was never used. > * find_edid_mode() did not return any mode if there were no detailed modes > available. > > Welcome back! :) Regards, Rene From umccullough at gmail.com Tue Sep 9 18:48:51 2008 From: umccullough at gmail.com (Urias McCullough) Date: Tue, 9 Sep 2008 09:48:51 -0700 Subject: [Haiku-commits] r27390 - haiku/trunk/src/system/boot/platform/bios_ia32 In-Reply-To: <200809091518.m89FIplj024790@sheep.berlios.de> References: <200809091518.m89FIplj024790@sheep.berlios.de> Message-ID: <1e80d8750809090948x734aeee6kf950b02b184b1fbb@mail.gmail.com> 2008/9/9 axeld at BerliOS : > Author: axeld > Date: 2008-09-09 17:18:51 +0200 (Tue, 09 Sep 2008) > New Revision: 27390 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27390&view=rev > > Modified: > haiku/trunk/src/system/boot/platform/bios_ia32/video.cpp > Log: > * closest_video_mode() now only returns modes with a width less or equal than > the one specified. This should fix the "video mode out of range" message of > your monitor during boot, in case you had that one. Thanks to Hartmut Reh > for his help to be able to spot this. > * The mode returned by find_edid_mode(..., true) was never used. > * find_edid_mode() did not return any mode if there were no detailed modes > available. Would this have possibly affected the video mode chosen by the intel_extreme driver? I started having problems with this on one of my machines recently and had to start using VESA video instead (choosing a resolution manually at boot didn't fix it). I haven't had a chance to look into it deeply yet. From sbenedetto at mail.berlios.de Tue Sep 9 19:57:37 2008 From: sbenedetto at mail.berlios.de (sbenedetto at BerliOS) Date: Tue, 9 Sep 2008 19:57:37 +0200 Subject: [Haiku-commits] r27391 - haiku/trunk/src/system/kernel/posix Message-ID: <200809091757.m89HvbkU029983@sheep.berlios.de> Author: sbenedetto Date: 2008-09-09 19:57:36 +0200 (Tue, 09 Sep 2008) New Revision: 27391 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27391&view=rev Modified: haiku/trunk/src/system/kernel/posix/xsi_message_queue.cpp Log: * Wake up waiting threads when a new message is sent or received * Removed sXsiMessageCountLock in favor of atomic_* function utility * free up any remaining messages when a queue gets destroyed Modified: haiku/trunk/src/system/kernel/posix/xsi_message_queue.cpp =================================================================== --- haiku/trunk/src/system/kernel/posix/xsi_message_queue.cpp 2008-09-09 15:18:51 UTC (rev 27390) +++ haiku/trunk/src/system/kernel/posix/xsi_message_queue.cpp 2008-09-09 17:57:36 UTC (rev 27391) @@ -113,12 +113,8 @@ fMessageQueue.msg_qbytes = MAX_BYTES_PER_QUEUE; } - ~XsiMessageQueue() - { - mutex_destroy(&fLock); - // TODO: free up all messages - // TODO: Wake up any thread still waiting - } + // Implemented after sXsiMessageCount is declared + ~XsiMessageQueue(); status_t BlockAndUnlock(struct thread *thread, MutexLocker *queueLocker) { @@ -199,7 +195,7 @@ return fID; } - // Implemented after sXsiMessageCountLock is declared + // Implemented after sXsiMessageCount is declared bool Insert(queued_message *message); key_t IpcKey() const @@ -217,7 +213,7 @@ return fMessageQueue.msg_qbytes; } - // Implemented after sXsiMessageCountLock is declared + // Implemented after sXsiMessageCount is declared queued_message *Remove(long typeRequested); uint32 SequenceNumber() const @@ -240,6 +236,27 @@ fMessageQueue.msg_perm.mode = (flags & 0x01ff); } + void WakeUpThread(bool waitForMessage) + { + InterruptsSpinLocker _(gThreadSpinlock); + if (waitForMessage) { + // Wake up all waiting thread for a message + // TODO: this can cause starvation for any + // very-unlucky-and-slow thread + while (queued_thread *entry = fWaitingToReceive.RemoveHead()) { + entry->queued = false; + fThreadsWaitingToReceive--; + thread_unblock_locked(entry->thread, 0); + } + } else { + while (queued_thread *entry = fWaitingToSend.RemoveHead()) { + entry->queued = false; + fThreadsWaitingToSend--; + thread_unblock_locked(entry->thread, 0); + } + } + } + HashTableLink* Link() { return &fLink; @@ -358,7 +375,6 @@ static mutex sIpcLock; static mutex sXsiMessageQueueLock; -static mutex sXsiMessageCountLock; static uint32 sGlobalSequenceNumber = 1; static vint32 sXsiMessageCount = 0; @@ -368,24 +384,59 @@ // #pragma mark - +XsiMessageQueue::~XsiMessageQueue() +{ + mutex_destroy(&fLock); + + // Wake up any threads still waiting + if (fThreadsWaitingToSend || fThreadsWaitingToReceive) { + InterruptsSpinLocker _(gThreadSpinlock); + while (queued_thread *entry = fWaitingToReceive.RemoveHead()) { + entry->queued = false; + thread_unblock_locked(entry->thread, EIDRM); + } + while (queued_thread *entry = fWaitingToSend.RemoveHead()) { + entry->queued = false; + thread_unblock_locked(entry->thread, EIDRM); + } + } + + // Free up any remaining messages + if (fMessageQueue.msg_qnum) { + while (queued_message *message = fMessage.RemoveHead()) { + atomic_add(&sXsiMessageCount, -1); + delete message; + } + } +} + + bool XsiMessageQueue::Insert(queued_message *message) { // The only situation that would make us (potentially) wait // is that we exceed with bytes or with the total number of messages - MutexLocker _(sXsiMessageCountLock); - if (fBytesInQueue == fMessageQueue.msg_qbytes - || fBytesInQueue + message->length > fMessageQueue.msg_qbytes - || sXsiMessageCount >= MAX_XSI_MESSAGE) + if (fBytesInQueue + message->length > fMessageQueue.msg_qbytes) return true; + while (true) { + int32 oldCount = atomic_get(&sXsiMessageCount); + if (oldCount >= MAX_XSI_MESSAGE) + return true; + // If another thread updates the counter we keep + // iterating + if (atomic_test_and_set(&sXsiMessageCount, oldCount + 1, oldCount) + == oldCount) + break; + } + fMessage.Add(message); fMessageQueue.msg_qnum++; fMessageQueue.msg_lspid = getpid(); fMessageQueue.msg_stime = real_time_clock(); fBytesInQueue += message->length; - sXsiMessageCount++; - // TODO: Wake up any thread waiting on receive + if (fThreadsWaitingToReceive) + WakeUpThread(true /* WaitForMessage */); return false; } @@ -428,9 +479,9 @@ fMessageQueue.msg_lrpid = getpid(); fMessageQueue.msg_rtime = real_time_clock(); fBytesInQueue -= message->length; - MutexLocker _(sXsiMessageCountLock); - sXsiMessageCount--; - // TODO: Wake up any thread waiting on send + atomic_add(&sXsiMessageCount, -1); + if (fThreadsWaitingToSend) + WakeUpThread(false /* WaitForMessage */); return message; } @@ -466,7 +517,6 @@ mutex_init(&sIpcLock, "global POSIX message queue IPC table"); mutex_init(&sXsiMessageQueueLock, "global POSIX xsi message queue table"); - mutex_init(&sXsiMessageCountLock, "global POSIX xsi message count"); } @@ -754,7 +804,7 @@ } } - return B_ERROR; + return B_OK; } From teammaui at web.de Tue Sep 9 20:25:59 2008 From: teammaui at web.de (=?utf-8?Q?Ralf_Sch=C3=BClke?=) Date: Tue, 09 Sep 2008 20:25:59 +0200 Subject: [Haiku-commits] r27390 - haiku/trunk/src/system/boot/platform/bios_ia32 In-Reply-To: References: <200809091518.m89FIplj024790@sheep.berlios.de> Message-ID: On Tue, 09 Sep 2008 18:39:31 +0200, Rene Gollent wrote: > On Tue, Sep 9, 2008 at 10:18 AM, axeld at BerliOS > wrote: >> Author: axeld >> Date: 2008-09-09 17:18:51 +0200 (Tue, 09 Sep 2008) >> New Revision: 27390 >> ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27390&view=rev > Welcome back! :) > Welcome back Axel ;-) -- Ralf Sch?lke aka stargater From korli at users.berlios.de Tue Sep 9 21:02:47 2008 From: korli at users.berlios.de (=?ISO-8859-1?Q?J=E9r=F4me_Duval?=) Date: Tue, 9 Sep 2008 21:02:47 +0200 Subject: [Haiku-commits] r27390 - haiku/trunk/src/system/boot/platform/bios_ia32 In-Reply-To: <200809091518.m89FIplj024790@sheep.berlios.de> References: <200809091518.m89FIplj024790@sheep.berlios.de> Message-ID: Hi Axel, 2008/9/9 axeld at BerliOS > * closest_video_mode() now only returns modes with a width less or equal > than > the one specified. This should fix the "video mode out of range" message > of > your monitor during boot, in case you had that one. Thanks to Hartmut Reh > for his help to be able to spot this. > I still have the "video mode out of range" message but after the boot (when the desktop should appear). Though it works when I choose a fail-safe video mode (ie 1280*1024*32). Bye, J?r?me -------------- next part -------------- An HTML attachment was scrubbed... URL: From host.haiku at gmx.de Tue Sep 9 21:06:12 2008 From: host.haiku at gmx.de (julun) Date: Tue, 09 Sep 2008 21:06:12 +0200 Subject: [Haiku-commits] r27236 - haiku/trunk/src/apps/deskbar In-Reply-To: <20080909100647.282360@gmx.net> References: <5959662682-BeMail@zon> <20080909100647.282360@gmx.net> Message-ID: <48C6C924.3050707@gmx.de> Stephan Assmus schrieb: > -------- Original-Nachricht -------- >> Datum: Tue, 09 Sep 2008 11:19:27 +0200 CEST >> Von: "Axel D?rfler" >> An: "SVN commits to the Haiku sourcerepository=?utf-8?q?" >> Betreff: Re: [Haiku-commits] r27236 - haiku/trunk/src/apps/deskbar > >> julun at BerliOS wrote: >>> Log: >>> * Reuse calendar from shared to have a bitmore advanced panel >>> while holding down the mouse over the date area in Deskbar. >> Nice one! >> IMO the UI looks a bit alien to the rest, though. > > Yes, this was definitely very useful! The only irritation is that when you change the month (for example to peak ahead), the date with the same month day is still marked, even though it has nothing to do with the current date. Maybe the calendar view could be set into some kind of read-only mode? I can change that to only 'highlight' the current date and show the selection (if focus) when switching back and forth. Would that make sense? But this might not going to happen before the weekend. Best regards, Karsten From superstippi at gmx.de Tue Sep 9 23:22:31 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Tue, 09 Sep 2008 23:22:31 +0200 Subject: [Haiku-commits] r27236 - haiku/trunk/src/apps/deskbar In-Reply-To: <48C6C924.3050707@gmx.de> References: <5959662682-BeMail@zon> <20080909100647.282360@gmx.net> <48C6C924.3050707@gmx.de> Message-ID: <20080909212231.73870@gmx.net> Hi, > > Yes, this was definitely very useful! The only irritation is that when > > you change the month (for example to peak ahead), the date with the same > > month day is still marked, even though it has nothing to do with the current > > date. Maybe the calendar view could be set into some kind of read-only mode? > > I can change that to only 'highlight' the current date and show the > selection (if focus) when switching back and forth. Would that make > sense? But this might not going to happen before the weekend. I only mean that if it's Sep 9th, and I switch forward to October, it currently highlights Oct 9th, even though I cannot and don't want to change the current date. There should be nothing highlighted in October or any other month than September when in this "read-only" mode of the control Best regards, -Stephan From host.haiku at gmx.de Tue Sep 9 23:29:19 2008 From: host.haiku at gmx.de (julun) Date: Tue, 09 Sep 2008 23:29:19 +0200 Subject: [Haiku-commits] r27236 - haiku/trunk/src/apps/deskbar In-Reply-To: <20080909212231.73870@gmx.net> References: <5959662682-BeMail@zon> <20080909100647.282360@gmx.net> <48C6C924.3050707@gmx.de> <20080909212231.73870@gmx.net> Message-ID: <48C6EAAF.3040509@gmx.de> Stephan Assmus schrieb: > Hi, > >>> Yes, this was definitely very useful! The only irritation is that when >>> you change the month (for example to peak ahead), the date with the same >>> month day is still marked, even though it has nothing to do with the current >>> date. Maybe the calendar view could be set into some kind of read-only mode? >> I can change that to only 'highlight' the current date and show the >> selection (if focus) when switching back and forth. Would that make >> sense? But this might not going to happen before the weekend. > > I only mean that if it's Sep 9th, and I switch forward to October, it currently highlights Oct 9th, even though I cannot and don't want to change the current date. There should be nothing highlighted in October or any other month than September when in this "read-only" mode of the control Yes that's what i meant too :) There is also this focus indicator, that's what i descried wrongly as selection. Since one can switch the month by keyboard as well (press space on a 'disabled' day) it would still be useful to have it. Karsten From axeld at mail.berlios.de Tue Sep 9 23:30:38 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 9 Sep 2008 23:30:38 +0200 Subject: [Haiku-commits] r27392 - haiku/trunk/src/system/boot/platform/bios_ia32 Message-ID: <200809092130.m89LUcm5024283@sheep.berlios.de> Author: axeld Date: 2008-09-09 23:30:37 +0200 (Tue, 09 Sep 2008) New Revision: 27392 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27392&view=rev Modified: haiku/trunk/src/system/boot/platform/bios_ia32/acpi.cpp Log: * acpi_init() could pass a NULL "rsdp" to acpi_check_rsdt() which would happily dereference it no matter what. This fixes CID 1282. Modified: haiku/trunk/src/system/boot/platform/bios_ia32/acpi.cpp =================================================================== --- haiku/trunk/src/system/boot/platform/bios_ia32/acpi.cpp 2008-09-09 17:57:36 UTC (rev 27391) +++ haiku/trunk/src/system/boot/platform/bios_ia32/acpi.cpp 2008-09-09 21:30:37 UTC (rev 27392) @@ -12,11 +12,12 @@ #include "acpi.h" #include "mmu.h" +#include + #include #include -#include //#define TRACE_ACPI #ifdef TRACE_ACPI @@ -44,7 +45,7 @@ acpi_descriptor_header *rsdt = (acpi_descriptor_header *)mmu_map_physical_memory( rsdp->rsdt_address, B_PAGE_SIZE, kDefaultPageFlags); - if (!rsdt || strncmp(rsdt->signature, ACPI_RSDT_SIGNATURE, 4) != 0) { + if (rsdt == NULL || strncmp(rsdt->signature, ACPI_RSDT_SIGNATURE, 4) != 0) { TRACE(("acpi: invalid root system description table\n")); return B_ERROR; } @@ -57,11 +58,11 @@ acpi_descriptor_header * acpi_find_table(char *signature) { - if (sAcpiRsdt == NULL) { + if (sAcpiRsdt == NULL) return NULL; - } - // Tried to keep numEntries a static variable; kept turning up 0 on table scan + // Tried to keep numEntries a static variable; kept turning up 0 on table + // scan // TODO: This calculates numEntries for every acpi probe. int32 numEntries = (sAcpiRsdt->length - sizeof(acpi_descriptor_header)) / 4; if (numEntries <= 0) { @@ -69,14 +70,19 @@ return NULL; } - TRACE(("acpi: searching %ld entries for table '%.4s'\n", numEntries, signature)); - uint32 *pointer = (uint32 *)((uint8 *)sAcpiRsdt + sizeof(acpi_descriptor_header)); + TRACE(("acpi: searching %ld entries for table '%.4s'\n", numEntries, + signature)); + + uint32 *pointer = (uint32 *)((uint8 *)sAcpiRsdt + + sizeof(acpi_descriptor_header)); + for (int32 j = 0; j < numEntries; j++, pointer++) { acpi_descriptor_header *header = (acpi_descriptor_header *) mmu_map_physical_memory(*pointer, B_PAGE_SIZE, kDefaultPageFlags); - if (!header || strncmp(header->signature, signature, 4) != 0) { + if (header == NULL || strncmp(header->signature, signature, 4) != 0) { // not interesting for us - TRACE(("acpi: Looking for '%.4s'. Skipping '%.4s'\n", signature, header->signature)); + TRACE(("acpi: Looking for '%.4s'. Skipping '%.4s'\n", signature, + header->signature)); continue; } TRACE(("acpi: Found '%.4s' @ %p\n", signature, pointer)); @@ -91,21 +97,22 @@ void acpi_init(void) { - acpi_rsdp *rsdp = NULL; // Try to find the ACPI RSDP. for (int32 i = 0; acpi_scan_spots[i].length > 0; i++) { - char *pointer; - TRACE(("acpi_init: entry base 0x%lx, limit 0x%lx\n", acpi_scan_spots[i].start, - acpi_scan_spots[i].stop)); - for (pointer = (char *)acpi_scan_spots[i].start; + acpi_rsdp *rsdp = NULL; + + TRACE(("acpi_init: entry base 0x%lx, limit 0x%lx\n", + acpi_scan_spots[i].start, acpi_scan_spots[i].stop)); + + for (char *pointer = (char *)acpi_scan_spots[i].start; (uint32)pointer < acpi_scan_spots[i].stop; pointer += 16) { if (strncmp(pointer, ACPI_RSDP_SIGNATURE, 8) == 0) { TRACE(("acpi_init: found ACPI RSDP signature at %p\n", pointer)); rsdp = (acpi_rsdp *)pointer; } } - if (acpi_check_rsdt(rsdp) == B_OK) + + if (rsdp != NULL && acpi_check_rsdt(rsdp) == B_OK) break; } - } From bonefish at mail.berlios.de Tue Sep 9 23:32:15 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Tue, 9 Sep 2008 23:32:15 +0200 Subject: [Haiku-commits] r27393 - haiku/trunk/src/servers/media Message-ID: <200809092132.m89LWF6G024515@sheep.berlios.de> Author: bonefish Date: 2008-09-09 23:32:15 +0200 (Tue, 09 Sep 2008) New Revision: 27393 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27393&view=rev Modified: haiku/trunk/src/servers/media/media_server.cpp Log: * CID 153 (line 754): delete array with delete[]. * CID 152 (line 796): delete array with delete[]. * Automatic whitespace cleanup. Modified: haiku/trunk/src/servers/media/media_server.cpp =================================================================== --- haiku/trunk/src/servers/media/media_server.cpp 2008-09-09 21:30:37 UTC (rev 27392) +++ haiku/trunk/src/servers/media/media_server.cpp 2008-09-09 21:32:15 UTC (rev 27393) @@ -118,7 +118,7 @@ thread_id control_thread; BLocker *fLocker; - + virtual void MessageReceived(BMessage *msg); virtual void ReadyToRun(); typedef BApplication inherited; @@ -151,7 +151,7 @@ TerminateAddonServer(); // and start a new one StartAddonServer(); - + gAddOnManager->LoadState(); } @@ -219,14 +219,14 @@ BEntry entry; BDirectory dir; entry_ref ref; - + err = GetAppInfo(&info); err |= entry.SetTo(&info.ref); err |= entry.GetParent(&entry); err |= dir.SetTo(&entry); err |= entry.SetTo(&dir, "media_addon_server"); err |= entry.GetRef(&ref); - + if (err == B_OK) be_roster->Launch(&ref); if (err == B_OK) @@ -236,7 +236,7 @@ err = be_roster->Launch(B_MEDIA_ADDON_SERVER_SIGNATURE); if (err == B_OK) return; - + (new BAlert("media_server", "Launching media_addon_server failed.\n\n" "media_server will terminate", "OK"))->Go(); fprintf(stderr, "Launching media_addon_server (%s) failed: %s\n", @@ -264,14 +264,14 @@ "(%s)\n", err, strerror(err)); } } - + // wait 5 seconds for it to terminate for (int i = 0; i < 50; i++) { if (!be_roster->IsRunning(B_MEDIA_ADDON_SERVER_SIGNATURE)) return; snooze(100000); // 100 ms } - + // try to kill it (or many of them), up to 10 seconds for (int i = 0; i < 50; i++) { team_id id = be_roster->TeamFor(B_MEDIA_ADDON_SERVER_SIGNATURE); @@ -287,7 +287,7 @@ } -void +void ServerApp::HandleMessage(int32 code, void *data, size_t size) { status_t rv; @@ -317,7 +317,7 @@ gNodeManager->RescanDefaultNodes(); break; } - + case SERVER_REGISTER_APP: { const server_register_app_request *request @@ -338,7 +338,7 @@ request->SendReply(rv, &reply, sizeof(reply)); break; } - + case SERVER_GET_MEDIAADDON_REF: { server_get_mediaaddon_ref_request *msg @@ -360,7 +360,7 @@ request->SendReply(rv, &reply, sizeof(reply)); break; } - + case SERVER_GET_LIVE_NODE_INFO: { const server_get_live_node_info_request *request @@ -372,7 +372,7 @@ request->SendReply(rv, &reply, sizeof(reply)); break; } - + case SERVER_GET_LIVE_NODES: { const server_get_live_nodes_request *request @@ -419,7 +419,7 @@ } break; } - + case SERVER_GET_NODE_FOR: { const server_get_node_for_request *request @@ -430,7 +430,7 @@ request->SendReply(rv, &reply, sizeof(reply)); break; } - + case SERVER_RELEASE_NODE: { const server_release_node_request *request @@ -440,7 +440,7 @@ request->SendReply(rv, &reply, sizeof(reply)); break; } - + case SERVER_REGISTER_NODE: { const server_register_node_request *request @@ -452,7 +452,7 @@ request->SendReply(rv, &reply, sizeof(reply)); break; } - + case SERVER_UNREGISTER_NODE: { const server_unregister_node_request *request @@ -493,7 +493,7 @@ request->SendReply(rv, &reply, sizeof(reply)); break; } - + case SERVER_PUBLISH_OUTPUTS: { const server_publish_outputs_request *request @@ -544,7 +544,7 @@ request->SendReply(rv, &reply, sizeof(reply)); break; } - + case SERVER_GET_DORMANT_NODE_FOR: { const server_get_dormant_node_for_request *request @@ -585,7 +585,7 @@ write_port(msg->reply_port, 0, &reply, sizeof(reply)); break; } - + case SERVER_UNREGISTER_MEDIAADDON: { server_unregister_mediaaddon_command *msg @@ -593,7 +593,7 @@ gNodeManager->UnregisterAddon(msg->addonid); break; } - + case SERVER_REGISTER_DORMANT_NODE: { xfer_server_register_dormant_node *msg @@ -603,10 +603,10 @@ gNodeManager->InvalidateDormantFlavorInfo(msg->purge_id); rv = dfi.Unflatten(msg->dfi_type, &(msg->dfi), msg->dfi_size); ASSERT(rv == B_OK); - gNodeManager->AddDormantFlavorInfo(dfi); + gNodeManager->AddDormantFlavorInfo(dfi); break; } - + case SERVER_GET_DORMANT_NODES: { xfer_server_get_dormant_nodes *msg @@ -615,7 +615,7 @@ dormant_node_info * infos = new dormant_node_info[msg->maxcount]; reply.count = msg->maxcount; reply.result = gNodeManager->GetDormantNodes( - infos, + infos, &reply.count, msg->has_input ? &msg->inputformat : NULL, msg->has_output ? &msg->outputformat : NULL, @@ -631,7 +631,7 @@ delete [] infos; break; } - + case SERVER_GET_DORMANT_FLAVOR_INFO: { xfer_server_get_dormant_flavor_info *msg @@ -684,7 +684,7 @@ request->SendReply(B_OK, &reply, sizeof(reply)); break; } - + case SERVER_REGISTER_BUFFER: { const server_register_buffer_request *request @@ -693,9 +693,9 @@ server_register_buffer_reply reply; status_t status; if (request->info.buffer == 0) { - reply.info = request->info; + reply.info = request->info; // size, offset, flags, area is kept - // get a new beuffer id into reply.info.buffer + // get a new beuffer id into reply.info.buffer status = gBufferManager->RegisterBuffer(request->team, request->info.size, request->info.flags, request->info.offset, request->info.area, @@ -718,15 +718,15 @@ gBufferManager->UnregisterBuffer(cmd->team, cmd->bufferid); break; } - + case SERVER_REWINDTYPES: { const server_rewindtypes_request *request = reinterpret_cast(data); server_rewindtypes_reply reply; - + BString **types = NULL; - + rv = gMMediaFilesManager->RewindTypes( &types, &reply.count); if(reply.count>0) { @@ -750,25 +750,25 @@ } } } - - delete types; - + + delete[] types; + rv = request->SendReply(rv, &reply, sizeof(reply)); if (rv != B_OK) { // if we couldn't send the message, delete the area - delete_area(reply.area); + delete_area(reply.area); } break; } - + case SERVER_REWINDREFS: { const server_rewindrefs_request *request = reinterpret_cast(data); server_rewindrefs_reply reply; - + BString **items = NULL; - + rv = gMMediaFilesManager->RewindRefs(request->type, &items, &reply.count); // we create an area here, and pass it to the library, @@ -792,9 +792,9 @@ } } } - - delete items; + delete[] items; + rv = request->SendReply(rv, &reply, sizeof(reply)); if (rv != B_OK) { // if we couldn't send the message, delete the area @@ -802,7 +802,7 @@ } break; } - + case SERVER_GETREFFOR: { const server_getreffor_request *request @@ -818,33 +818,33 @@ request->SendReply(rv, &reply, sizeof(reply)); break; } - + case SERVER_SETREFFOR: { const server_setreffor_request *request = reinterpret_cast(data); server_setreffor_reply reply; entry_ref ref = request->ref; - + rv = gMMediaFilesManager->SetRefFor(request->type, request->item, ref); request->SendReply(rv, &reply, sizeof(reply)); break; } - + case SERVER_REMOVEREFFOR: { const server_removereffor_request *request = reinterpret_cast(data); server_removereffor_reply reply; entry_ref ref = request->ref; - + rv = gMMediaFilesManager->RemoveRefFor(request->type, request->item, ref); request->SendReply(rv, &reply, sizeof(reply)); break; } - + case SERVER_REMOVEITEM: { const server_removeitem_request *request @@ -874,11 +874,11 @@ const server_get_decoder_for_format_request *>(data); server_get_decoder_for_format_reply reply; rv = gAddOnManager->GetDecoderForFormat(&reply.ref, - request->format); + request->format); request->SendReply(rv, &reply, sizeof(reply)); break; } - + default: printf("media_server: received unknown message code %#08lx\n", code); @@ -893,7 +893,7 @@ ServerApp *app; ssize_t size; int32 code; - + app = (ServerApp *)arg; while ((size = read_port_etc(app->control_port, &code, data, sizeof(data), 0, 0)) > 0) { @@ -903,7 +903,7 @@ return 0; } -void +void ServerApp::MessageReceived(BMessage *msg) { TRACE("ServerApp::MessageReceived %lx enter\n", msg->what); @@ -917,7 +917,7 @@ case MMEDIAFILESMANAGER_SAVE_TIMER: gMMediaFilesManager->TimerMessage(); break; - + case MEDIA_SERVER_GET_FORMATS: gFormatManager->GetFormats(*msg); break; @@ -925,7 +925,7 @@ case MEDIA_SERVER_MAKE_FORMAT_FOR: gFormatManager->MakeFormatFor(*msg); break; - + case MEDIA_SERVER_ADD_SYSTEM_BEEP_EVENT: gMMediaFilesManager->HandleAddSystemBeepEvent(msg); break; From bonefish at mail.berlios.de Wed Sep 10 00:11:04 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Wed, 10 Sep 2008 00:11:04 +0200 Subject: [Haiku-commits] r27394 - haiku/trunk/src/apps/aboutsystem Message-ID: <200809092211.m89MB4Co029371@sheep.berlios.de> Author: bonefish Date: 2008-09-10 00:11:03 +0200 (Wed, 10 Sep 2008) New Revision: 27394 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27394&view=rev Modified: haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp Log: Added Zhao Shuai to the contributors list. Modified: haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp =================================================================== --- haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp 2008-09-09 21:32:15 UTC (rev 27393) +++ haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp 2008-09-09 22:11:03 UTC (rev 27394) @@ -531,6 +531,7 @@ "Gerald Zajac\n" "?ukasz Zemczak\n" "JiSheng Zhang\n" + "Zhao Shuai\n" "\n" B_UTF8_ELLIPSIS " and probably some more we forgot to mention " "(sorry!)" "\n\n"); From leavengood at mail.berlios.de Wed Sep 10 07:36:46 2008 From: leavengood at mail.berlios.de (leavengood at BerliOS) Date: Wed, 10 Sep 2008 07:36:46 +0200 Subject: [Haiku-commits] r27395 - in haiku/trunk/src/apps: . installedpackages Message-ID: <200809100536.m8A5akfq016074@sheep.berlios.de> Author: leavengood Date: 2008-09-10 07:36:45 +0200 (Wed, 10 Sep 2008) New Revision: 27395 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27395&view=rev Added: haiku/trunk/src/apps/installedpackages/ haiku/trunk/src/apps/installedpackages/Jamfile haiku/trunk/src/apps/installedpackages/UninstallView.cpp haiku/trunk/src/apps/installedpackages/UninstallView.h haiku/trunk/src/apps/installedpackages/UninstallWindow.cpp haiku/trunk/src/apps/installedpackages/UninstallWindow.h haiku/trunk/src/apps/installedpackages/main.cpp Modified: haiku/trunk/src/apps/Jamfile Log: ADDING the InstalledPackages application originally created by ?\197?\129ukasz Zemczak for Summer of Code 2007. It probably still needs some work but it is better put into SVN than sitting on my machine. I figure it might one day be morphed into a simple Haiku package manager (though maybe we don't want that...) Modified: haiku/trunk/src/apps/Jamfile =================================================================== --- haiku/trunk/src/apps/Jamfile 2008-09-09 22:11:03 UTC (rev 27394) +++ haiku/trunk/src/apps/Jamfile 2008-09-10 05:36:45 UTC (rev 27395) @@ -19,6 +19,7 @@ SubInclude HAIKU_TOP src apps fontdemo ; SubInclude HAIKU_TOP src apps glteapot ; SubInclude HAIKU_TOP src apps icon-o-matic ; +SubInclude HAIKU_TOP src apps installedpackages ; SubInclude HAIKU_TOP src apps installer ; SubInclude HAIKU_TOP src apps launchbox ; SubInclude HAIKU_TOP src apps login ; Added: haiku/trunk/src/apps/installedpackages/Jamfile =================================================================== --- haiku/trunk/src/apps/installedpackages/Jamfile 2008-09-09 22:11:03 UTC (rev 27394) +++ haiku/trunk/src/apps/installedpackages/Jamfile 2008-09-10 05:36:45 UTC (rev 27395) @@ -0,0 +1,17 @@ +SubDir HAIKU_TOP src apps installedpackages ; + +SetSubDirSupportedPlatformsBeOSCompatible ; + +UsePrivateHeaders shared interface ; +SubDirHdrs $(HAIKU_TOP) src apps packageinstaller ; + +SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits interface ] ; +SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src apps packageinstaller ] ; + +Application InstalledPackages : + InstalledPackageInfo.cpp + main.cpp + UninstallWindow.cpp + UninstallView.cpp + : be tracker +; Added: haiku/trunk/src/apps/installedpackages/UninstallView.cpp =================================================================== --- haiku/trunk/src/apps/installedpackages/UninstallView.cpp 2008-09-09 22:11:03 UTC (rev 27394) +++ haiku/trunk/src/apps/installedpackages/UninstallView.cpp 2008-09-10 05:36:45 UTC (rev 27395) @@ -0,0 +1,368 @@ +/* + * Copyright (c) 2007, Haiku, Inc. + * Distributed under the terms of the MIT license. + * + * Author: + * ?ukasz 'Sil2100' Zemczak + */ +#include "UninstallView.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + +enum { + P_MSG_REMOVE = 'umrm', + P_MSG_SELECT +}; + + +// Reserved +#define T(x) x + + +// TODO list: +// - B_ENTRY_MOVED +// - Right now the installed package info naming convention is the same +// as at SoftwareValet. Maybe there would be a better one? +// - Add a status window (reuse the one from PackageInstall) + + +class UninstallView::InfoItem : public BStringItem { + public: + InfoItem(const char *name, const char *version, node_ref ref) + : BStringItem(name), + fVersion(version), + fNodeRef(ref) + { + } + + const char * GetName() { return BStringItem::Text(); } + const char * GetVersion() { return fVersion.String(); }; + node_ref GetNodeRef() { return fNodeRef; }; + + private: + BString fVersion; + node_ref fNodeRef; +}; + + + + +UninstallView::UninstallView(BRect frame) + : BView(frame, "uninstall_view", B_FOLLOW_NONE, 0) +{ + _InitView(); +} + + +UninstallView::~UninstallView() +{ + _ClearAppList(); + + // Stop all node watching + stop_watching(this); +} + + +void +UninstallView::AttachedToWindow() +{ + fAppList->SetTarget(this); + fButton->SetTarget(this); + + _ReloadAppList(); + + // We loaded the list, but now let's set up a node watcher for the packages + // directory, so that we can update the list of installed packages in real + // time + _CachePathToPackages(); + node_ref ref; + fWatcherRunning = false; + BDirectory dir(fToPackages.Path()); + if (dir.InitCheck() != B_OK) { + // The packages/ directory obviously does not exist. + // Since this is the case, we need to watch for it to appear first + + BPath path; + fToPackages.GetParent(&path); + if (dir.SetTo(path.Path()) != B_OK) + return; + } + else + fWatcherRunning = true; + + dir.GetNodeRef(&ref); + + if (watch_node(&ref, B_WATCH_DIRECTORY, this) != B_OK) { + fWatcherRunning = false; + return; + } +} + + +void +UninstallView::MessageReceived(BMessage *msg) +{ + switch (msg->what) { + case B_NODE_MONITOR: + { + int32 opcode; + if (msg->FindInt32("opcode", &opcode) != B_OK) + break; + + fprintf(stderr, "Got an opcoded node monitor message\n"); + if (opcode == B_ENTRY_CREATED) { + fprintf(stderr, "Created?...\n"); + BString filename, name, version; + node_ref ref; + if (msg->FindString("name", &filename) != B_OK || + msg->FindInt32("device", &ref.device) != B_OK || + msg->FindInt64("node", &ref.node) != B_OK) + break; + + // TODO: This obviously is a hack + // The node watcher informs the view a bit to early, and because + // of this the data of the node is not ready at this moment. + // For this reason, we must give the filesystem some time before + // continuing. + usleep(10000); + + if (fWatcherRunning) { + name = info_get_package_name(filename.String()); + version = info_get_package_version(filename.String()); + fAppList->AddItem(new InfoItem(name.String(), version.String(), ref)); + } + else { + // This most likely means we were waiting for the packages/ dir + // to appear + if (filename == "packages") { + if (watch_node(&ref, B_WATCH_DIRECTORY, this) == B_OK) + fWatcherRunning = true; + } + } + } + else if (opcode == B_ENTRY_REMOVED) { + node_ref ref; + if (msg->FindInt32("device", &ref.device) != B_OK || + msg->FindInt64("node", &ref.node) != B_OK) + break; + + int32 i, count = fAppList->CountItems(); + InfoItem *iter; + for (i = 0;i < count;i++) { + iter = static_cast(fAppList->ItemAt(i)); + if (iter->GetNodeRef() == ref) { + if (i == fAppList->CurrentSelection()) + fDescription->SetText(T("No package selected")); + fAppList->RemoveItem(i); + delete iter; + } + } + } + else if (opcode == B_ENTRY_MOVED) { + ino_t from, to; + if (msg->FindInt64("from directory", &from) != B_OK || + msg->FindInt64("to directory", &to) != B_OK) + break; + + BDirectory packagesDir(fToPackages.Path()); + node_ref ref; + packagesDir.GetNodeRef(&ref); + + if (ref.node == to) { + // Package added + // TODO + } + else if (ref.node == from) { + // Package removed + // TODO + } + } + break; + } + case P_MSG_SELECT: + { + int32 index = fAppList->CurrentSelection(); + if (index < 0) + break; + + fprintf(stderr, "Another debug message...\n"); + + InfoItem *item = dynamic_cast(fAppList->ItemAt(index)); + if (!item) + break; + + fprintf(stderr, "Uh: %s and %s\n", item->GetName(), item->GetVersion()); + + if (fCurrentSelection.SetTo(item->GetName(), item->GetVersion()) != B_OK) + break; + + fprintf(stderr, " ...how much longer?\n"); + + fDescription->SetText(fCurrentSelection.GetDescription()); + break; + } + case P_MSG_REMOVE: + { + if (fCurrentSelection.InitCheck() != B_OK) + break; + + int32 index = fAppList->CurrentSelection(); + if (index < 0) + break; + + BAlert *notify; + if (fCurrentSelection.Uninstall() == B_OK) { + BListItem *item = static_cast(fAppList->ItemAt(index)); + fAppList->RemoveItem(index); + delete item; + + fDescription->SetText(T("No package selected")); + + notify = new BAlert("removal_success", + T("The package you selected has been successfully removed " + "from your system."), T("OK")); + } + else + notify = new BAlert("removal_failed", + T("The selected package was not removed from your system. The " + "given installed package information file might have been " + "corrupted."), T("OK"), NULL, + NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); + + notify->Go(); + } + default: + BView::MessageReceived(msg); + break; + } +} + + +void +UninstallView::_InitView() +{ + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + BRect rect = Bounds().InsetBySelf(10.0f, 10.0f); + rect.bottom = 125.0f; + rect.right -= B_V_SCROLL_BAR_WIDTH; + fAppList = new BListView(rect, "pkg_list", B_SINGLE_SELECTION_LIST, + B_FOLLOW_NONE); + fAppList->SetSelectionMessage(new BMessage(P_MSG_SELECT)); + + BScrollView *scroll = new BScrollView("list_scroll", fAppList, B_FOLLOW_NONE, + 0, false, true); + AddChild(scroll); + + rect.top = rect.bottom + 8.0f; + rect.bottom += 120.0f; + rect.right += B_V_SCROLL_BAR_WIDTH; + BBox *box = new BBox(rect, "desc_box"); + + BStringView *descLabel = new BStringView(BRect(3, 3, 10, 10), "desc_label", + T("Package description:")); + descLabel->ResizeToPreferred(); + box->AddChild(descLabel); + + BRect inside = box->Bounds().InsetBySelf(3.0f, 3.0f); + inside.top = descLabel->Frame().bottom + 10.0f; + inside.right -= B_V_SCROLL_BAR_WIDTH; + fDescription = new BTextView(inside, "description", + BRect(0, 0, inside.Width(), inside.Height()), B_FOLLOW_NONE, B_WILL_DRAW); + fDescription->MakeSelectable(true); + fDescription->MakeEditable(false); + fDescription->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + fDescription->SetText(T("No package selected.")); + + fDescScroll = new BScrollView("desc_scroll", fDescription, B_FOLLOW_NONE, + 0, false, true, B_NO_BORDER); + box->AddChild(fDescScroll); + + AddChild(box); + + fButton = new BButton(BRect(0, 0, 1, 1), "removal", T("Remove"), + new BMessage(P_MSG_REMOVE)); + fButton->ResizeToPreferred(); + + rect.top = rect.bottom + 5.0f; + rect.left = Bounds().Width() - 5.0f - fButton->Bounds().Width(); + + fButton->MoveTo(rect.LeftTop()); + AddChild(fButton); + + ResizeTo(Bounds().Width(), fButton->Frame().bottom + 10.0f); +} + + +status_t +UninstallView::_ReloadAppList() +{ + _ClearAppList(); + + if (fToPackages.InitCheck() != B_OK) + _CachePathToPackages(); + + BDirectory dir(fToPackages.Path()); + status_t ret = dir.InitCheck(); + if (ret != B_OK) + return ret; + + fprintf(stderr, "Ichi! %s\n", fToPackages.Path()); + + BEntry iter; + node_ref ref; + char filename[B_FILE_NAME_LENGTH]; + BString name, version; + while (1) { + ret = dir.GetNextEntry(&iter); + if (ret != B_OK) + break; + + fprintf(stderr, "Found one!\n"); + iter.GetName(filename); + iter.GetNodeRef(&ref); + name = info_get_package_name(filename); + version = info_get_package_version(filename); + fAppList->AddItem(new InfoItem(name.String(), version.String(), ref)); + } + + if (ret != B_ENTRY_NOT_FOUND) + return ret; + + return B_OK; +} + + +void +UninstallView::_ClearAppList() +{ + int32 i, count = fAppList->CountItems(); + BListItem *iter = 0; + + for (i = 0;i < count;i++) { + iter = static_cast(fAppList->ItemAt(0)); + fAppList->RemoveItem((int32)0); + delete iter; + } +} + + +void +UninstallView::_CachePathToPackages() +{ + if (find_directory(B_USER_CONFIG_DIRECTORY, &fToPackages) != B_OK) + return; + if (fToPackages.Append(kPackagesDir) != B_OK) + return; +} + Added: haiku/trunk/src/apps/installedpackages/UninstallView.h =================================================================== --- haiku/trunk/src/apps/installedpackages/UninstallView.h 2008-09-09 22:11:03 UTC (rev 27394) +++ haiku/trunk/src/apps/installedpackages/UninstallView.h 2008-09-10 05:36:45 UTC (rev 27395) @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2007, Haiku, Inc. + * Distributed under the terms of the MIT license. + * + * Author: + * ?ukasz 'Sil2100' Zemczak + */ +#ifndef UNINSTALLVIEW_H +#define UNINSTALLVIEW_H + +#include "InstalledPackageInfo.h" +#include +#include +#include +#include +#include +#include +#include + + +class UninstallView : public BView { + public: + UninstallView(BRect frame); + ~UninstallView(); + + void AttachedToWindow(); + void MessageReceived(BMessage *msg); + + private: + class InfoItem; + + void _InitView(); + status_t _ReloadAppList(); + void _ClearAppList(); + void _CachePathToPackages(); + + BPath fToPackages; + BListView *fAppList; + BTextView *fDescription; + BButton *fButton; + BScrollView *fDescScroll; + InstalledPackageInfo fCurrentSelection; + bool fWatcherRunning; +}; + + +#endif Added: haiku/trunk/src/apps/installedpackages/UninstallWindow.cpp =================================================================== --- haiku/trunk/src/apps/installedpackages/UninstallWindow.cpp 2008-09-09 22:11:03 UTC (rev 27394) +++ haiku/trunk/src/apps/installedpackages/UninstallWindow.cpp 2008-09-10 05:36:45 UTC (rev 27395) @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2007, Haiku, Inc. + * Distributed under the terms of the MIT license. + * + * Author: + * ?ukasz 'Sil2100' Zemczak + */ +#include "UninstallWindow.h" +#include + + +// Macro reserved for later localization +#define T(x) x + + +UninstallWindow::UninstallWindow() + : BWindow(BRect(100, 100, 600, 300), T("Installed packages"), + B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE) +{ + fBackground = new UninstallView(Bounds()); + AddChild(fBackground); + + ResizeTo(Bounds().Width(), fBackground->Bounds().Height()); +} + + +UninstallWindow::~UninstallWindow() +{ + RemoveChild(fBackground); + + delete fBackground; +} + + +bool +UninstallWindow::QuitRequested() +{ + be_app->PostMessage(B_QUIT_REQUESTED); + return true; +} + Added: haiku/trunk/src/apps/installedpackages/UninstallWindow.h =================================================================== --- haiku/trunk/src/apps/installedpackages/UninstallWindow.h 2008-09-09 22:11:03 UTC (rev 27394) +++ haiku/trunk/src/apps/installedpackages/UninstallWindow.h 2008-09-10 05:36:45 UTC (rev 27395) @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2007, Haiku, Inc. + * Distributed under the terms of the MIT license. + * + * Author: + * ?ukasz 'Sil2100' Zemczak + */ +#ifndef UNINSTALLWINDOW_H +#define UNINSTALLWINDOW_H + +#include "UninstallView.h" +#include +#include + + +class UninstallWindow : public BWindow { + public: + UninstallWindow(); + ~UninstallWindow(); + + bool QuitRequested(); + + private: + UninstallView *fBackground; +}; + + +#endif Added: haiku/trunk/src/apps/installedpackages/main.cpp =================================================================== --- haiku/trunk/src/apps/installedpackages/main.cpp 2008-09-09 22:11:03 UTC (rev 27394) +++ haiku/trunk/src/apps/installedpackages/main.cpp 2008-09-10 05:36:45 UTC (rev 27395) @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2007, Haiku, Inc. + * Distributed under the terms of the MIT license. + * + * Author: + * ?ukasz 'Sil2100' Zemczak + */ +#include "UninstallWindow.h" +#include +#include +#include +#include +#include +#include +#include + + +class UninstallApplication : public BApplication { + public: + UninstallApplication(); + ~UninstallApplication(); + + void MessageReceived(BMessage *msg); + + void AboutRequested(); + + private: + UninstallWindow *fWindow; +}; + + +UninstallApplication::UninstallApplication() + : BApplication("application/x-vnd.Haiku-InstalledPackages") +{ + fWindow = new UninstallWindow(); + fWindow->Show(); +} + + +UninstallApplication::~UninstallApplication() +{ +} + + +void +UninstallApplication::MessageReceived(BMessage *msg) +{ + switch (msg->what) { + default: + BApplication::MessageReceived(msg); + } +} + + +void +UninstallApplication::AboutRequested() +{ + BAlert *about = new BAlert("about", + "InstalledPackages\n" + "BeOS legacy .pkg package removing application for Haiku.\n\n" + "Copyright 2007,\n?ukasz 'Sil2100' Zemczak\n\n" + "Copyright (c) 2007 Haiku, Inc. \n", + "Close"); + + BTextView *view = about->TextView(); + BFont font; + view->SetStylable(true); + view->GetFont(&font); + font.SetFace(B_BOLD_FACE); + font.SetSize(font.Size() * 1.5); + view->SetFontAndColor(0, 15, &font); + + about->Go(); +} + + +int +main(void) +{ + UninstallApplication app; + app.Run(); + + return 0; +} + From stippi at mail.berlios.de Wed Sep 10 07:43:13 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Wed, 10 Sep 2008 07:43:13 +0200 Subject: [Haiku-commits] r27396 - haiku/trunk/src/add-ons/kernel/partitioning_systems/intel Message-ID: <200809100543.m8A5hD66027350@sheep.berlios.de> Author: stippi Date: 2008-09-10 07:43:09 +0200 (Wed, 10 Sep 2008) New Revision: 27396 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27396&view=rev Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMapWriter.cpp haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMapWriter.h Log: * A bit of rewording and refactoring to make it a little easier to follow and remove any duplicate code. No (intended) functional change. Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMapWriter.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMapWriter.cpp 2008-09-10 05:36:45 UTC (rev 27395) +++ haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMapWriter.cpp 2008-09-10 05:43:09 UTC (rev 27396) @@ -45,7 +45,6 @@ : fDeviceFD(deviceFD), fSessionOffset(sessionOffset), fSessionSize(sessionSize), - fPTS(NULL), fMap(NULL) { } @@ -82,19 +81,19 @@ if (clearSectors) memset(sector, 0, SECTOR_SIZE); else - error = _ReadPTS(0, pts); + error = _ReadSector(0, pts); if (error == B_OK) { error = _WritePrimary(pts); if (error == B_OK) - error = _WriteSector(0, sector); + error = _WriteSector(0, pts); } // Clear the second sector, if desired. We do that to make the partition // unrecognizable by BFS. if (error == B_OK && clearSectors) { memset(sector, 0, SECTOR_SIZE); - error = _WriteSector(SECTOR_SIZE, sector); + error = _WriteSector(SECTOR_SIZE, pts); } fMap = NULL; @@ -108,35 +107,34 @@ disk. This function ensures that the connection of the following linked list - of logical partitions will be correct. It do nothing with the connection of - previous logical partitions (call this function on previous logical + of logical partitions will be correct. It does nothing with the connection + of previous logical partitions (call this function on previous logical partition to ensure it). \param pts Pointer to \c partition_table_sector. \param partition Pointer to the logical partition. */ status_t -PartitionMapWriter::WriteLogical(partition_table_sector *pts, - const LogicalPartition *partition) +PartitionMapWriter::WriteLogical(partition_table_sector* pts, + const LogicalPartition* partition) { - status_t error = (partition ? B_OK : B_BAD_VALUE); - if (error == B_OK) { - if (pts) { - error = _WriteExtended(pts, partition, partition->Next()); - if (error == B_OK) - error = _WriteSector(partition->PTSOffset(), pts); - } else { - partition_table_sector _pts; - pts = &_pts; - error = _ReadPTS(partition->PTSOffset(), pts); - if (error == B_OK) { - error = _WriteExtended(pts, partition, partition->Next()); - if (error == B_OK) - error = _WriteSector(partition->PTSOffset(), pts); - } - } + if (partition == NULL) + return B_BAD_VALUE; + + partition_table_sector _pts; + if (pts == NULL) { + // no PTS given, use stack based PTS and read from disk first + pts = &_pts; + status_t error = _ReadSector(partition->PTSOffset(), pts); + if (error != B_OK) + return error; } - return error; + + status_t error = _WriteExtended(pts, partition, partition->Next()); + if (error != B_OK) + return error; + + return _WriteSector(partition->PTSOffset(), pts); } // WriteExtendedHead @@ -146,40 +144,41 @@ Writes the head of linked list describing logical partitions. - If the \a first_partition is not specified, it only initializes EBR and the + If the \a firstPartition is not specified, it only initializes EBR and the linked list contains no logical partitions. \param pts Pointer to \c partition_table_sector. - \param first_partition Pointer to the first logical partition. + \param firstPartition Pointer to the first logical partition. */ status_t -PartitionMapWriter::WriteExtendedHead(partition_table_sector *pts, - const LogicalPartition *first_partition) +PartitionMapWriter::WriteExtendedHead(partition_table_sector* pts, + const LogicalPartition* firstPartition) { LogicalPartition partition; - if (first_partition) - partition.SetPrimaryPartition(first_partition->GetPrimaryPartition()); - status_t error = B_OK; - if (pts) { - error = _WriteExtended(pts, &partition, first_partition); - if (error == B_OK) - error = _WriteSector(0, pts); - } else { - partition_table_sector _pts; + if (firstPartition != NULL) + partition.SetPrimaryPartition(firstPartition->GetPrimaryPartition()); + + partition_table_sector _pts; + if (pts == NULL) { + // no PTS given, use stack based PTS and read from disk first pts = &_pts; - error = _ReadPTS(0, pts); - if (error == B_OK) { - error = _WriteExtended(pts, &partition, first_partition); - if (error == B_OK) - error = _WriteSector(0, pts); - } + status_t error = _ReadSector(0, pts); + if (error != B_OK) + return error; } - return error; + + status_t error = _WriteExtended(pts, &partition, firstPartition); + if (error != B_OK) + return error; + + return _WriteSector(0, pts); } +// #pragma mark - fill a PTS in memory + // _WritePrimary status_t -PartitionMapWriter::_WritePrimary(partition_table_sector *pts) +PartitionMapWriter::_WritePrimary(partition_table_sector* pts) { if (pts == NULL) return B_BAD_VALUE; @@ -210,7 +209,7 @@ PartitionMapWriter::_WriteExtended(partition_table_sector *pts, const LogicalPartition *partition, const LogicalPartition *next) { - if (!pts || !partition) + if (pts == NULL || partition == NULL) return B_BAD_VALUE; // write the signature @@ -252,58 +251,68 @@ return B_OK; } -// _ReadPTS +// #pragma mark - to/from disk + +// _ReadSector /*! \brief Reads the sector from the disk. */ status_t -PartitionMapWriter::_ReadPTS(off_t offset, partition_table_sector *pts) +PartitionMapWriter::_ReadSector(off_t offset, partition_table_sector* pts) { - status_t error = B_OK; - if (!pts) - pts = fPTS; int32 toRead = sizeof(partition_table_sector); + // same as SECTOR_SIZE actually + // check the offset if (offset < 0 || offset + toRead > fSessionSize) { - error = B_BAD_VALUE; - TRACE(("intel: _ReadPTS(): bad offset: %Ld\n", offset)); + TRACE(("intel: _ReadSector(): bad offset: %Ld\n", offset)); + return B_BAD_VALUE; + } + // read - } else if (read_pos(fDeviceFD, fSessionOffset + offset, pts, toRead) - != toRead) { + offset += fSessionOffset; + if (read_pos(fDeviceFD, offset, pts, toRead) != toRead) { #ifndef _BOOT_MODE - error = errno; + status_t error = errno; if (error == B_OK) error = B_IO_ERROR; #else - error = B_IO_ERROR; + status_t error = B_IO_ERROR; #endif - TRACE(("intel: _ReadPTS(): reading the PTS failed: %lx\n", error)); + TRACE(("intel: _ReadSector(): reading the PTS failed: %lx\n", error)); + return error; } - return error; + + return B_OK; } // _WriteSector /*! \brief Writes the sector to the disk. */ status_t -PartitionMapWriter::_WriteSector(off_t offset, const void* pts) +PartitionMapWriter::_WriteSector(off_t offset, + const partition_table_sector* pts) { - status_t error = B_OK; + int32 toWrite = sizeof(partition_table_sector); + // same as SECTOR_SIZE actually - int32 toWrite = SECTOR_SIZE; - // check the offset if (offset < 0 || offset + toWrite > fSessionSize) { - error = B_BAD_VALUE; TRACE(("intel: _WriteSector(): bad offset: %Ld\n", offset)); + return B_BAD_VALUE; + } + + offset += fSessionOffset; + // write - } else if (write_pos(fDeviceFD, fSessionOffset + offset, pts, toWrite) - != toWrite) { - error = errno; + if (write_pos(fDeviceFD, offset, pts, toWrite) != toWrite) { + status_t error = errno; if (error == B_OK) error = B_IO_ERROR; TRACE(("intel: _WriteSector(): writing the PTS failed: %lx\n", error)); + return error; } - return error; + + return B_OK; } Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMapWriter.h =================================================================== --- haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMapWriter.h 2008-09-10 05:36:45 UTC (rev 27395) +++ haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMapWriter.h 2008-09-10 05:43:09 UTC (rev 27396) @@ -35,28 +35,34 @@ */ class PartitionMapWriter { public: - PartitionMapWriter(int deviceFD, off_t sessionOffset, off_t sessionSize); - ~PartitionMapWriter(); + PartitionMapWriter(int deviceFD, + off_t sessionOffset, off_t sessionSize); + ~PartitionMapWriter(); - status_t WriteMBR(const PartitionMap *map, bool clearSectors); - status_t WriteLogical(partition_table_sector *pts, - const LogicalPartition *partition); - status_t WriteExtendedHead(partition_table_sector *pts, - const LogicalPartition *first_partition); + status_t WriteMBR(const PartitionMap* map, + bool clearSectors); + status_t WriteLogical(partition_table_sector* pts, + const LogicalPartition* partition); + status_t WriteExtendedHead(partition_table_sector* pts, + const LogicalPartition* firstPartition); private: - status_t _WritePrimary(partition_table_sector *pts); - status_t _WriteExtended(partition_table_sector *pts, - const LogicalPartition *partition, const LogicalPartition *next); - status_t _ReadPTS(off_t offset, partition_table_sector *pts = NULL); - status_t _WriteSector(off_t offset, const void* pts = NULL); + status_t _WritePrimary(partition_table_sector* pts); + status_t _WriteExtended(partition_table_sector* pts, + const LogicalPartition* partition, + const LogicalPartition* next); + status_t _ReadSector(off_t offset, + partition_table_sector* pts); + status_t _WriteSector(off_t offset, + const partition_table_sector* pts); + private: - int fDeviceFD; - off_t fSessionOffset; - off_t fSessionSize; - partition_table_sector *fPTS; // while writing - const PartitionMap *fMap; + int fDeviceFD; + off_t fSessionOffset; + off_t fSessionSize; + + const PartitionMap* fMap; // while writing }; #endif // PARTITION_MAP_WRITER_H From stippi at mail.berlios.de Wed Sep 10 07:44:11 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Wed, 10 Sep 2008 07:44:11 +0200 Subject: [Haiku-commits] r27397 - haiku/trunk/src/add-ons/kernel/partitioning_systems/intel Message-ID: <200809100544.m8A5iBhi029622@sheep.berlios.de> Author: stippi Date: 2008-09-10 07:44:09 +0200 (Wed, 10 Sep 2008) New Revision: 27397 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27397&view=rev Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/write_support.cpp Log: * Added some TODO comments about possible problems I have spotted during review with regards to the offset range that the PartitionMapWriter is allowed to write to. Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/write_support.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/write_support.cpp 2008-09-10 05:43:09 UTC (rev 27396) +++ haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/write_support.cpp 2008-09-10 05:44:09 UTC (rev 27397) @@ -966,6 +966,7 @@ // TODO: The partition is not supposed to be locked here! PartitionMapWriter writer(fd, 0, partition->size); + // TODO: disk size? status_t error = writer.WriteMBR(map, false); if (error != B_OK) { // putting into previous state @@ -1136,6 +1137,7 @@ primary->SetOffset(validatedOffset); PartitionMapWriter writer(fd, 0, partition->size); + // TODO: disk size? error = writer.WriteMBR(map, false); if (error != B_OK) // something went wrong - this is fatal (partition has been moved) @@ -1193,6 +1195,7 @@ // TODO: The partition is not supposed to be locked at this point! PartitionMapWriter writer(fd, 0, partition->size); + // TODO: disk size? status_t error = writer.WriteMBR(map, false); if (error != B_OK) { // something went wrong - putting into previous state @@ -1229,6 +1232,7 @@ // write the sector to disk PartitionMapWriter writer(fd, 0, partitionSize); + // TODO: disk size or 2 * SECTOR_SIZE? status_t error = writer.WriteMBR(&map, true); if (error != B_OK) return error; @@ -1306,6 +1310,7 @@ // write changes to disk PartitionMapWriter writer(fd, 0, partition->size); + // TODO: disk size or 2 * SECTOR_SIZE? // TODO: The partition is not supposed to be locked at this point! status_t error = writer.WriteMBR(map, false); if (error != B_OK) { @@ -1367,6 +1372,7 @@ // write changes to disk PartitionMapWriter writer(fd, 0, partition->size); + // TODO: disk size or 2 * SECTOR_SIZE? // TODO: The partition is not supposed to be locked at this point! status_t error = writer.WriteMBR(map, false); if (error != B_OK) @@ -1835,9 +1841,9 @@ status_t error = B_OK; // move partition with its header (PTS table) off_t pts_offset = logical->Offset() - logical->PTSOffset(); - error = move_partition(fd, child->offset - pts_offset, validatedOffset - pts_offset, - child->size + pts_offset, buffer, - allocated * SECTOR_SIZE, job); + error = move_partition(fd, child->offset - pts_offset, + validatedOffset - pts_offset, child->size + pts_offset, buffer, + allocated * SECTOR_SIZE, job); delete[] buffer; if (error != B_OK) return error; @@ -1849,6 +1855,8 @@ logical->SetPTSOffset(logical->PTSOffset() + diffOffset); PartitionMapWriter writer(fd, partition->offset, partition->size); + // TODO: If partition->offset is > prev->offset, then writing + // the previous logical partition table will fail! // TODO: The partition is not supposed to be locked here! error = writer.WriteLogical(NULL, logical); if (error != B_OK) @@ -2049,6 +2057,7 @@ // write changes to disk PartitionMapWriter writer(fd, partition->offset, partition->size); + // TODO: wrong offset range, writing prev will fail // TODO: The partition is not supposed to be locked here! status_t error = writer.WriteLogical(&pts, logical); if (error != B_OK) { @@ -2126,6 +2135,8 @@ // write changes to disk PartitionMapWriter writer(fd, partition->offset, partition->size); + // TODO: Check offset range! Writing "prev/next_logical"? + // Should be parent->offset and parent->size? // TODO: The partition is not supposed to be locked here! status_t error = prev_logical ? writer.WriteLogical(NULL, prev_logical) : writer.WriteExtendedHead(NULL, next_logical); From jackburton at mail.berlios.de Wed Sep 10 11:03:01 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Wed, 10 Sep 2008 11:03:01 +0200 Subject: [Haiku-commits] r27398 - haiku/trunk/src/servers/app Message-ID: <200809100903.m8A931A6006327@sheep.berlios.de> Author: jackburton Date: 2008-09-10 11:02:59 +0200 (Wed, 10 Sep 2008) New Revision: 27398 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27398&view=rev Modified: haiku/trunk/src/servers/app/FontStyle.cpp haiku/trunk/src/servers/app/FontStyle.h Log: Implemented dummy FontStyle::IsFullAndHalfFixed(). Freetype doesn't seem to offer any api to be able to tell such a font from others Modified: haiku/trunk/src/servers/app/FontStyle.cpp =================================================================== --- haiku/trunk/src/servers/app/FontStyle.cpp 2008-09-10 05:44:09 UTC (rev 27397) +++ haiku/trunk/src/servers/app/FontStyle.cpp 2008-09-10 09:02:59 UTC (rev 27398) @@ -140,6 +140,8 @@ if (IsFixedWidth()) flags |= B_IS_FIXED; + if (IsFullAndHalfFixed()) + flags |= B_PRIVATE_FONT_IS_FULL_AND_HALF_FIXED; if (TunedCount() > 0) flags |= B_HAS_TUNED_FONT; if (HasKerning()) Modified: haiku/trunk/src/servers/app/FontStyle.h =================================================================== --- haiku/trunk/src/servers/app/FontStyle.h 2008-09-10 05:44:09 UTC (rev 27397) +++ haiku/trunk/src/servers/app/FontStyle.h 2008-09-10 09:02:59 UTC (rev 27398) @@ -74,6 +74,14 @@ */ bool IsFixedWidth() const { return fFreeTypeFace->face_flags & FT_FACE_FLAG_FIXED_WIDTH; } + +/* \fn bool FontStyle::IsFullAndHalfFixed() + \brief Determines whether the font has 2 different, fixed, widths. + \return false (for now) +*/ + bool IsFullAndHalfFixed() const + { return false; }; + /*! \fn bool FontStyle::IsScalable(void) \brief Determines whether the font can be scaled to any size From jackburton at mail.berlios.de Wed Sep 10 11:13:05 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Wed, 10 Sep 2008 11:13:05 +0200 Subject: [Haiku-commits] r27399 - haiku/trunk/src/servers/app/drawing/Painter Message-ID: <200809100913.m8A9D5Fg006925@sheep.berlios.de> Author: jackburton Date: 2008-09-10 11:13:02 +0200 (Wed, 10 Sep 2008) New Revision: 27399 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27399&view=rev Modified: haiku/trunk/src/servers/app/drawing/Painter/AGGTextRenderer.cpp haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp Log: fixed another round of gcc4 warnings Modified: haiku/trunk/src/servers/app/drawing/Painter/AGGTextRenderer.cpp =================================================================== --- haiku/trunk/src/servers/app/drawing/Painter/AGGTextRenderer.cpp 2008-09-10 09:02:59 UTC (rev 27398) +++ haiku/trunk/src/servers/app/drawing/Painter/AGGTextRenderer.cpp 2008-09-10 09:13:02 UTC (rev 27399) @@ -175,8 +175,8 @@ // it is therefor yet "untransformed" in case there is an // embedded transformation. const agg::rect_i& r = glyph->bounds; - IntRect glyphBounds(r.x1 + x, r.y1 + y - 1, - r.x2 + x + 1, r.y2 + y + 1); + IntRect glyphBounds(int32(r.x1 + x), int32(r.y1 + y - 1), + int32(r.x2 + x + 1), int32(r.y2 + y + 1)); // NOTE: "-1"/"+1" converts the glyph bounding box from pixel // indices to pixel area coordinates @@ -215,8 +215,8 @@ fRenderer.fGray8Adaptor, fRenderer.fPathAdaptor); - float falseBoldWidth = fRenderer.fContour.width(); - if (falseBoldWidth != 0.0) + int32 falseBoldWidth = (int32)fRenderer.fContour.width(); + if (falseBoldWidth != 0) glyphBounds.InsetBy(-falseBoldWidth, -falseBoldWidth); // TODO: not correct! this is later used for clipping, // but it doesn't get the rect right Modified: haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp =================================================================== --- haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp 2008-09-10 09:02:59 UTC (rev 27398) +++ haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp 2008-09-10 09:13:02 UTC (rev 27399) @@ -350,7 +350,7 @@ if (fPenSize == 1.0 && !fSubpixelPrecise) { if (fClippingRegion->Contains(a)) { agg::rgba8 dummyColor; - fPixelFormat.blend_pixel(a.x, a.y, dummyColor, 255); + fPixelFormat.blend_pixel((int)a.x, (int)a.y, dummyColor, 255); } } else { fPath.move_to(a.x, a.y); @@ -1459,17 +1459,17 @@ if (format == B_CMAP8) { if (fDrawingMode == B_OP_COPY) { _DrawBitmapNoScale32(copy_bitmap_row_cmap8_copy, 1, - srcBuffer, xOffset, yOffset, viewRect); + srcBuffer, (int32)xOffset, (int32)yOffset, viewRect); return; } else if (fDrawingMode == B_OP_OVER) { _DrawBitmapNoScale32(copy_bitmap_row_cmap8_over, 1, - srcBuffer, xOffset, yOffset, viewRect); + srcBuffer, (int32)xOffset, (int32)yOffset, viewRect); return; } } else if (format == B_RGB32) { if (fDrawingMode == B_OP_OVER) { _DrawBitmapNoScale32(copy_bitmap_row_bgr32_over, 4, - srcBuffer, xOffset, yOffset, viewRect); + srcBuffer, (int32)xOffset, (int32)yOffset, viewRect); return; } } @@ -1548,14 +1548,14 @@ if (xScale == 1.0 && yScale == 1.0) { if (fDrawingMode == B_OP_COPY) { _DrawBitmapNoScale32(copy_bitmap_row_bgr32_copy, 4, srcBuffer, - xOffset, yOffset, viewRect); + (int32)xOffset, (int32)yOffset, viewRect); return; } else if (fDrawingMode == B_OP_OVER || (fDrawingMode == B_OP_ALPHA && fAlphaSrcMode == B_PIXEL_ALPHA && fAlphaFncMode == B_ALPHA_OVERLAY)) { _DrawBitmapNoScale32(copy_bitmap_row_bgr32_alpha, 4, srcBuffer, - xOffset, yOffset, viewRect); + (int32)xOffset, (int32)yOffset, viewRect); return; } } From jackburton at mail.berlios.de Wed Sep 10 13:34:58 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Wed, 10 Sep 2008 13:34:58 +0200 Subject: [Haiku-commits] r27400 - haiku/trunk/src/kits/interface Message-ID: <200809101134.m8ABYw0e012621@sheep.berlios.de> Author: jackburton Date: 2008-09-10 13:34:56 +0200 (Wed, 10 Sep 2008) New Revision: 27400 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27400&view=rev Modified: haiku/trunk/src/kits/interface/Shelf.cpp Log: Use dynamic_cast before calling DeleteReplicant. This fixes bug #2712. I'm not sure why, though. Also call unload_add_on() as last operation (and yes, doing just that was not sufficient to fix the bug) Modified: haiku/trunk/src/kits/interface/Shelf.cpp =================================================================== --- haiku/trunk/src/kits/interface/Shelf.cpp 2008-09-10 09:13:02 UTC (rev 27399) +++ haiku/trunk/src/kits/interface/Shelf.cpp 2008-09-10 11:34:56 UTC (rev 27400) @@ -531,10 +531,12 @@ BShelf::MessageReceived(BMessage *msg) { if (msg->what == kDeleteReplicant) { - BView *replicant = NULL; - if (msg->FindPointer("_target", (void **)&replicant) == B_OK && replicant != NULL) - DeleteReplicant(replicant); - + BHandler *replicant = NULL; + if (msg->FindPointer("_target", (void **)&replicant) == B_OK) { + BView *view = dynamic_cast(replicant); + if (view != NULL) + DeleteReplicant(view); + } return; } @@ -1152,12 +1154,14 @@ delete item->dragger; } - if (loadedImage && item->image >= 0) - unload_add_on(item->image); + image_id image = item->image; delete item; + if (loadedImage && image >= 0) + unload_add_on(image); + return B_OK; } From anevilyak at mail.berlios.de Wed Sep 10 17:17:56 2008 From: anevilyak at mail.berlios.de (anevilyak at BerliOS) Date: Wed, 10 Sep 2008 17:17:56 +0200 Subject: [Haiku-commits] r27401 - in haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139: dev/mii pci Message-ID: <200809101517.m8AFHuRX002851@sheep.berlios.de> Author: anevilyak Date: 2008-09-10 17:17:56 +0200 (Wed, 10 Sep 2008) New Revision: 27401 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27401&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/dev/mii/miidevs.h haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/dev/mii/rlphy.c haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/if_rl.c haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/if_rlreg.h Log: Updated RTL8139 driver to 7.0-RELEASE version. Modified: haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/dev/mii/miidevs.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/dev/mii/miidevs.h 2008-09-10 11:34:56 UTC (rev 27400) +++ haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/dev/mii/miidevs.h 2008-09-10 15:17:56 UTC (rev 27401) @@ -1,3 +1,6 @@ -#define MII_OUI_REALTEK 0x000020 +#define MII_OUI_REALTEK 0x000020 #define MII_MODEL_REALTEK_RTL8201L 0x0020 #define MII_STR_REALTEK_RTL8201L "RTL8021L" +#define MII_OUI_ICPLUS 0x0090c3 +#define MII_MODEL_ICPLUS_IP101 0x0005 +#define MII_STR_ICPLUS_IP101 "IP101" Modified: haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/dev/mii/rlphy.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/dev/mii/rlphy.c 2008-09-10 11:34:56 UTC (rev 27400) +++ haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/dev/mii/rlphy.c 2008-09-10 15:17:56 UTC (rev 27401) @@ -31,7 +31,7 @@ */ #include -__FBSDID("$FreeBSD: src/sys/dev/mii/rlphy.c,v 1.21.2.1 2006/08/08 04:37:18 yongari Exp $"); +__FBSDID("$FreeBSD: src/sys/dev/mii/rlphy.c,v 1.31 2007/06/06 07:07:23 yongari Exp $"); /* * driver for RealTek 8139 internal PHYs @@ -57,6 +57,11 @@ #include "miibus_if.h" +struct rlphy_softc { + struct mii_softc sc_mii; /* generic PHY */ + int sc_is_RTL8201L; /* is an external RTL8201L PHY */ +}; + static int rlphy_probe(device_t); static int rlphy_attach(device_t); @@ -74,7 +79,7 @@ static driver_t rlphy_driver = { "rlphy", rlphy_methods, - sizeof(struct mii_softc) + sizeof(struct rlphy_softc) }; DRIVER_MODULE(rlphy, miibus, rlphy_driver, rlphy_devclass, 0, 0); @@ -82,63 +87,65 @@ static int rlphy_service(struct mii_softc *, struct mii_data *, int); static void rlphy_status(struct mii_softc *); +/* + * RealTek internal PHYs don't have vendor/device ID registers; + * re(4) and rl(4) fake up a return value of all zeros. + */ +static const struct mii_phydesc rlintphys[] = { + { 0, 0, "RealTek internal media interface" }, + MII_PHY_END +}; + +static const struct mii_phydesc rlphys[] = { + MII_PHY_DESC(REALTEK, RTL8201L), + MII_PHY_DESC(ICPLUS, IP101), + MII_PHY_END +}; + static int -rlphy_probe(dev) - device_t dev; +rlphy_probe(device_t dev) { - struct mii_attach_args *ma; - device_t parent; + const char *nic; + int rv; - ma = device_get_ivars(dev); - parent = device_get_parent(device_get_parent(dev)); + rv = mii_phy_dev_probe(dev, rlphys, BUS_PROBE_DEFAULT); + if (rv <= 0) + return (rv); - /* Test for RealTek 8201L PHY */ - if (MII_OUI(ma->mii_id1, ma->mii_id2) == MII_OUI_REALTEK && - MII_MODEL(ma->mii_id2) == MII_MODEL_REALTEK_RTL8201L) { - device_set_desc(dev, MII_STR_REALTEK_RTL8201L); - return(BUS_PROBE_DEFAULT); - } - - /* - * RealTek PHY doesn't have vendor/device ID registers: - * the rl driver fakes up a return value of all zeros. - */ - if (MII_OUI(ma->mii_id1, ma->mii_id2) != 0 || - MII_MODEL(ma->mii_id2) != 0) - return (ENXIO); - - /* - * Make sure the parent is an `rl' or an `re'. - */ - if (strcmp(device_get_name(parent), "rl") != 0 && - strcmp(device_get_name(parent), "re") != 0) - return (ENXIO); - - device_set_desc(dev, "RealTek internal media interface"); - - return (BUS_PROBE_DEFAULT); + nic = device_get_name(device_get_parent(device_get_parent(dev))); + if (strcmp(nic, "rl") == 0 || strcmp(nic, "re") == 0) + return (mii_phy_dev_probe(dev, rlintphys, BUS_PROBE_DEFAULT)); + return (ENXIO); } static int -rlphy_attach(dev) - device_t dev; +rlphy_attach(device_t dev) { struct mii_softc *sc; struct mii_attach_args *ma; struct mii_data *mii; + struct rlphy_softc *rsc; sc = device_get_softc(dev); ma = device_get_ivars(dev); sc->mii_dev = device_get_parent(dev); mii = device_get_softc(sc->mii_dev); + /* + * Check whether we're the RTL8201L PHY and remember so the status + * routine can query the proper register for speed detection. + */ + rsc = (struct rlphy_softc *)sc; + if (mii_phy_dev_probe(dev, rlphys, 0) == 0) + rsc->sc_is_RTL8201L++; + /* * The RealTek PHY can never be isolated, so never allow non-zero * instances! */ if (mii->mii_instance != 0) { device_printf(dev, "ignoring this PHY, non-zero instance\n"); - return(ENXIO); + return (ENXIO); } LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); @@ -153,31 +160,23 @@ #define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL) -#if 0 /* See above. */ - ADD(IFM_MAKEWORD(IFM_ETHER, IFM_NONE, 0, sc->mii_inst), - BMCR_ISO); -#endif - ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_LOOP, sc->mii_inst), - BMCR_LOOP|BMCR_S100); + MII_MEDIA_100_TX); mii_phy_reset(sc); sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask; device_printf(dev, " "); - mii_add_media(sc); + mii_phy_add_media(sc); printf("\n"); #undef ADD MIIBUS_MEDIAINIT(sc->mii_dev); - return(0); + return (0); } static int -rlphy_service(sc, mii, cmd) - struct mii_softc *sc; - struct mii_data *mii; - int cmd; +rlphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd) { struct ifmedia_entry *ife = mii->mii_media.ifm_cur; @@ -198,28 +197,7 @@ if ((mii->mii_ifp->if_flags & IFF_UP) == 0) break; - switch (IFM_SUBTYPE(ife->ifm_media)) { - case IFM_AUTO: - /* - * If we're already in auto mode, just return. - */ - if (PHY_READ(sc, MII_BMCR) & BMCR_AUTOEN) - return (0); - (void) mii_phy_auto(sc); - break; - case IFM_100_T4: - /* - * XXX Not supported as a manual setting right now. - */ - return (EINVAL); - default: - /* - * BMCR data is stored in the ifmedia entry. - */ - PHY_WRITE(sc, MII_ANAR, - mii_anar(ife->ifm_media)); - PHY_WRITE(sc, MII_BMCR, ife->ifm_data); - } + mii_phy_setmedia(sc); break; case MII_TICK: @@ -230,12 +208,6 @@ return (0); /* - * Only used for autonegotiation. - */ - if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO) - break; - - /* * The RealTek PHY's autonegotiation doesn't need to be * kicked; it continues in the background. */ @@ -251,12 +223,12 @@ } static void -rlphy_status(phy) - struct mii_softc *phy; +rlphy_status(struct mii_softc *phy) { + struct rlphy_softc *rsc =(struct rlphy_softc *)phy; struct mii_data *mii = phy->mii_pdata; + struct ifmedia_entry *ife = mii->mii_media.ifm_cur; int bmsr, bmcr, anlpar; - device_t parent; mii->mii_media_status = IFM_AVALID; mii->mii_media_active = IFM_ETHER; @@ -300,19 +272,18 @@ else if (anlpar & ANLPAR_10) mii->mii_media_active |= IFM_10_T; else - mii->mii_media_active |= IFM_NONE; + mii->mii_media_active |= IFM_NONE; return; } /* * If the other side doesn't support NWAY, then the * best we can do is determine if we have a 10Mbps or - * 100Mbps link. There's no way to know if the link + * 100Mbps link. There's no way to know if the link * is full or half duplex, so we default to half duplex * and hope that the user is clever enough to manually * change the media settings if we're wrong. */ - /* * The RealTek PHY supports non-NWAY link speed * detection, however it does not report the link @@ -331,8 +302,7 @@ * can test the 'SPEED10' bit of the MAC's media status * register. */ - parent = device_get_parent(phy->mii_dev); - if (strcmp(device_get_name(parent), "rl") != 0) { + if (rsc->sc_is_RTL8201L) { if (PHY_READ(phy, 0x0019) & 0x01) mii->mii_media_active |= IFM_100_TX; else @@ -344,7 +314,6 @@ else mii->mii_media_active |= IFM_100_TX; } - } else - mii->mii_media_active = mii_media_from_bmcr(bmcr); + mii->mii_media_active = ife->ifm_media; } Modified: haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/if_rl.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/if_rl.c 2008-09-10 11:34:56 UTC (rev 27400) +++ haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/if_rl.c 2008-09-10 15:17:56 UTC (rev 27401) @@ -31,7 +31,7 @@ */ #include -__FBSDID("$FreeBSD: src/sys/pci/if_rl.c,v 1.170 2007/07/24 01:24:03 yongari Exp $"); +__FBSDID("$FreeBSD: src/sys/pci/if_rl.c,v 1.170.2.1 2007/12/02 08:38:31 remko Exp $"); /* * RealTek 8129/8139 PCI NIC driver @@ -166,6 +166,8 @@ "Corega FEtherII CB-TXD" }, { PEPPERCON_VENDORID, PEPPERCON_DEVICEID_ROLF, RL_8139, "Peppercon AG ROL-F" }, + { PLANEX_VENDORID, PLANEX_DEVICEID_FNW3603TX, RL_8139, + "Planex FNW-3603-TX" }, { PLANEX_VENDORID, PLANEX_DEVICEID_FNW3800TX, RL_8139, "Planex FNW-3800-TX" }, { CP_VENDORID, RT_DEVICEID_8139, RL_8139, Modified: haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/if_rlreg.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/if_rlreg.h 2008-09-10 11:34:56 UTC (rev 27400) +++ haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/if_rlreg.h 2008-09-10 15:17:56 UTC (rev 27401) @@ -29,7 +29,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/sys/pci/if_rlreg.h,v 1.67 2007/07/24 01:24:03 yongari Exp $ + * $FreeBSD: src/sys/pci/if_rlreg.h,v 1.67.2.2 2007/12/15 02:57:18 yongari Exp $ */ /* @@ -156,6 +156,7 @@ #define RL_HWREV_8100E 0x30800000 #define RL_HWREV_8101E 0x34000000 #define RL_HWREV_8168_SPIN2 0x38000000 +#define RL_HWREV_8168_SPIN3 0x38400000 #define RL_HWREV_8139 0x60000000 #define RL_HWREV_8139A 0x70000000 #define RL_HWREV_8139AG 0x70800000 @@ -917,6 +918,11 @@ #define PLANEX_VENDORID 0x14ea /* + * Planex FNW-3603-TX device ID + */ +#define PLANEX_DEVICEID_FNW3603TX 0xab06 + +/* * Planex FNW-3800-TX device ID */ #define PLANEX_DEVICEID_FNW3800TX 0xab07 From sbenedetto at mail.berlios.de Wed Sep 10 18:22:23 2008 From: sbenedetto at mail.berlios.de (sbenedetto at BerliOS) Date: Wed, 10 Sep 2008 18:22:23 +0200 Subject: [Haiku-commits] r27402 - haiku/trunk/src/system/kernel/posix Message-ID: <200809101622.m8AGMNJh009977@sheep.berlios.de> Author: sbenedetto Date: 2008-09-10 18:22:23 +0200 (Wed, 10 Sep 2008) New Revision: 27402 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27402&view=rev Modified: haiku/trunk/src/system/kernel/posix/xsi_message_queue.cpp Log: * Set msg_qbytes on IPC_SET * Wake up only one thread waiting to send. Modified: haiku/trunk/src/system/kernel/posix/xsi_message_queue.cpp =================================================================== --- haiku/trunk/src/system/kernel/posix/xsi_message_queue.cpp 2008-09-10 15:17:56 UTC (rev 27401) +++ haiku/trunk/src/system/kernel/posix/xsi_message_queue.cpp 2008-09-10 16:22:23 UTC (rev 27402) @@ -133,6 +133,7 @@ fMessageQueue.msg_perm.gid = result->msg_perm.gid; fMessageQueue.msg_perm.mode = (fMessageQueue.msg_perm.mode & ~0x01ff) | (result->msg_perm.mode & 0x01ff); + fMessageQueue.msg_qbytes = result->msg_qbytes; fMessageQueue.msg_ctime = (time_t)real_time_clock(); } @@ -249,7 +250,8 @@ thread_unblock_locked(entry->thread, 0); } } else { - while (queued_thread *entry = fWaitingToSend.RemoveHead()) { + // Wake up only one thread waiting to send + if (queued_thread *entry = fWaitingToSend.RemoveHead()) { entry->queued = false; fThreadsWaitingToSend--; thread_unblock_locked(entry->thread, 0); @@ -587,6 +589,11 @@ "increase the maximum number of bytes allowed on queue\n")); return EPERM; } + if (msg.msg_qbytes == 0) { + TRACE_ERROR(("xsi_msgctl: can't set msg_qbytes to 0!\n")); + return EINVAL; + } + messageQueue->DoIpcSet(&msg); break; } From axeld at mail.berlios.de Wed Sep 10 21:24:38 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Wed, 10 Sep 2008 21:24:38 +0200 Subject: [Haiku-commits] r27403 - in haiku/trunk: headers/os/drivers src/add-ons/kernel/bus_managers/acpi Message-ID: <200809101924.m8AJOcSZ018051@sheep.berlios.de> Author: axeld Date: 2008-09-10 21:24:37 +0200 (Wed, 10 Sep 2008) New Revision: 27403 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27403&view=rev Modified: haiku/trunk/headers/os/drivers/ACPI.h haiku/trunk/src/add-ons/kernel/bus_managers/acpi/acpi_busman.c haiku/trunk/src/add-ons/kernel/bus_managers/acpi/acpi_module.c haiku/trunk/src/add-ons/kernel/bus_managers/acpi/acpi_priv.h haiku/trunk/src/add-ons/kernel/bus_managers/acpi/oshaiku.c Log: * Divided enter_sleep_state() to have a prepare_sleep_state() that accepts a wake vector (not tested at all). * Removed disabling interrupts when entering the sleep state - looks like ACPI still needs memory then. * Cleanup. Modified: haiku/trunk/headers/os/drivers/ACPI.h =================================================================== --- haiku/trunk/headers/os/drivers/ACPI.h 2008-09-10 16:22:23 UTC (rev 27402) +++ haiku/trunk/headers/os/drivers/ACPI.h 2008-09-10 19:24:37 UTC (rev 27403) @@ -1,57 +1,64 @@ -/* ACPI Bus Manger Interface - * Copyright 2005, Haiku Inc. All Rights Reserved. - * Distributed under the terms of the MIT License +/* + * Copyright 2005-2008, Haiku Inc. All Rights Reserved. + * Distributed under the terms of the MIT License */ - #ifndef _ACPI_H #define _ACPI_H + #include -#include #include + typedef struct acpi_module_info acpi_module_info; typedef struct acpi_object_type acpi_object_type; +#define B_ACPI_MODULE_NAME "bus_managers/acpi/v1" + struct acpi_module_info { - bus_manager_info binfo; - + module_info info; + /* Fixed Event Management */ - - void (*enable_fixed_event) (uint32 event); - void (*disable_fixed_event) (uint32 event); - - uint32 (*fixed_event_status) (uint32 event); - /* Returns 1 if event set, 0 otherwise */ - void (*reset_fixed_event) (uint32 event); - - status_t (*install_fixed_event_handler) (uint32 event, interrupt_handler *handler, void *data); - status_t (*remove_fixed_event_handler) (uint32 event, interrupt_handler *handler); + void (*enable_fixed_event)(uint32 event); + void (*disable_fixed_event)(uint32 event); + + uint32 (*fixed_event_status) (uint32 event); + /* Returns 1 if event set, 0 otherwise */ + void (*reset_fixed_event) (uint32 event); + + status_t (*install_fixed_event_handler)(uint32 event, + interrupt_handler *handler, void *data); + status_t (*remove_fixed_event_handler)(uint32 event, + interrupt_handler *handler); + /* Namespace Access */ - - status_t (*get_next_entry) (uint32 object_type, const char *base, char *result, size_t len, void **counter); - status_t (*get_device) (const char *hid, uint32 index, char *result); - - status_t (*get_device_hid) (const char *path, char *hid); - uint32 (*get_object_type) (const char *path); - status_t (*get_object) (const char *path, acpi_object_type **return_value); - status_t (*get_object_typed) (const char *path, acpi_object_type **return_value, uint32 object_type); - + + status_t (*get_next_entry)(uint32 objectType, const char *base, + char *result, size_t length, void **_counter); + status_t (*get_device)(const char *hid, uint32 index, char *result, + size_t resultLength); + + status_t (*get_device_hid)(const char *path, char *hid); + uint32 (*get_object_type)(const char *path); + status_t (*get_object)(const char *path, + acpi_object_type **_returnValue); + status_t (*get_object_typed)(const char *path, + acpi_object_type **_returnValue, uint32 objectType); + /* Control method execution and data acquisition */ - - status_t (*evaluate_object) (const char *object, acpi_object_type *return_value, size_t buf_len); - status_t (*evaluate_method) (const char *object, const char *method, acpi_object_type *return_value, size_t buf_len, acpi_object_type *args, int num_args); + + status_t (*evaluate_object)(const char *object, + acpi_object_type *returnValue, size_t bufferLength); + status_t (*evaluate_method)(const char *object, const char *method, + acpi_object_type *returnValue, size_t bufferLength, + acpi_object_type *args, int numArgs); + /* Power state setting */ - - status_t (*enter_sleep_state) (uint8 state); - /* Sleep state values: - 0: On (Working) - 1: Sleep - 2: Software Off - 3: Mechanical Off - 4: Hibernate - 5: Software Off */ + + status_t (*prepare_sleep_state)(uint8 state, void (*wakeFunc)(void), + size_t size); + status_t (*enter_sleep_state)(uint8 state); }; @@ -107,7 +114,7 @@ } package; struct { uint32 cpu_id; - + int pblk_address; size_t pblk_length; } processor; @@ -118,15 +125,25 @@ } data; }; -#endif +#endif // __ACTYPES_H__ -#define B_ACPI_MODULE_NAME "bus_managers/acpi/v1" +/* Sleep states */ -#define ACPI_DEVICE_HID_ITEM "acpi/hid" -#define ACPI_DEVICE_PATH_ITEM "acpi/path" -#define ACPI_DEVICE_TYPE_ITEM "acpi/type" +enum { + ACPI_POWER_STATE_ON = 0, + ACPI_POWER_STATE_SLEEP_S1, + ACPI_POWER_STATE_SLEEP_S2, + ACPI_POWER_STATE_SLEEP_S3, + ACPI_POWER_STATE_HIBERNATE, + ACPI_POWER_STATE_OFF +}; +#define ACPI_DEVICE_HID_ITEM "acpi/hid" +#define ACPI_DEVICE_PATH_ITEM "acpi/path" +#define ACPI_DEVICE_TYPE_ITEM "acpi/type" + + typedef struct acpi_device_info *acpi_device; // Interface to one ACPI device. @@ -134,13 +151,15 @@ driver_module_info info; /* Namespace Access */ - uint32 (*get_object_type) (acpi_device device); - status_t (*get_object) (acpi_device device, const char *path, acpi_object_type **return_value); - + uint32 (*get_object_type)(acpi_device device); + status_t (*get_object)(acpi_device device, const char *path, + acpi_object_type **_returnValue); + /* Control method execution and data acquisition */ - status_t (*evaluate_method) (acpi_device device, const char *method, acpi_object_type *return_value, size_t buf_len, acpi_object_type *args, int num_args); - + status_t (*evaluate_method)(acpi_device device, const char *method, + acpi_object_type *returnValue, size_t bufferLength, + acpi_object_type *args, int numArgs); } acpi_device_module_info; -#endif /* _ACPI_H */ +#endif /* _ACPI_H */ Modified: haiku/trunk/src/add-ons/kernel/bus_managers/acpi/acpi_busman.c =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/acpi/acpi_busman.c 2008-09-10 16:22:23 UTC (rev 27402) +++ haiku/trunk/src/add-ons/kernel/bus_managers/acpi/acpi_busman.c 2008-09-10 19:24:37 UTC (rev 27403) @@ -1,67 +1,73 @@ /* + * Copyright 2008, Axel D?rfler, axeld at pinc-software.de. * Copyright 2006, Bryan Varner. All rights reserved. * Copyright 2005, Nathan Whitehorn. All rights reserved. * * Distributed under the terms of the MIT License. */ + +#include +#include +#include + #include #include +#include #include -#include -#include #include -#include -#include #include "acpi.h" #include "acpixf.h" #include "acpi_priv.h" -status_t acpi_std_ops(int32 op,...); -status_t acpi_rescan_stub(void); - #define TRACE(x...) dprintf("acpi: " x) #define ERROR(x...) dprintf("acpi: " x) -extern dpc_module_info *gDPC; -void *gDPChandle = NULL; -extern pci_module_info *gPCIManager; +extern dpc_module_info* gDPC; +void* gDPCHandle = NULL; -struct acpi_module_info acpi_module = { - { - { - B_ACPI_MODULE_NAME, - B_KEEP_LOADED, - acpi_std_ops - }, - - acpi_rescan_stub - }, - - enable_fixed_event, - disable_fixed_event, - fixed_event_status, - reset_fixed_event, - install_fixed_event_handler, - remove_fixed_event_handler, - get_next_entry, - get_device, - get_device_hid, - get_object_type, - get_object, - get_object_typed, - evaluate_object, - evaluate_method, - enter_sleep_state -}; +extern pci_module_info* gPCIManager; -status_t -acpi_std_ops(int32 op,...) +static ACPI_STATUS +get_device_by_hid_callback(ACPI_HANDLE object, UINT32 depth, void* context, + void** _returnValue) { + uint32* counter = (uint32*)context; + ACPI_STATUS status; + ACPI_BUFFER buffer; + + *_returnValue = NULL; + + if (counter[0] == counter[1]) { + buffer.Length = 254; + buffer.Pointer = malloc(255); + + status = AcpiGetName(object, ACPI_FULL_PATHNAME, &buffer); + if (status != AE_OK) { + free(buffer.Pointer); + return AE_CTRL_TERMINATE; + } + + ((char*)buffer.Pointer)[buffer.Length] = '\0'; + *_returnValue = buffer.Pointer; + return AE_CTRL_TERMINATE; + } + + counter[1]++; + return AE_OK; +} + + +// #pragma mark - ACPI bus manager API + + +static status_t +acpi_std_ops(int32 op,...) +{ switch (op) { case B_MODULE_INIT: { @@ -110,7 +116,7 @@ } #endif - if (gDPC->new_dpc_queue(&gDPChandle, "acpi_task", B_NORMAL_PRIORITY) != B_OK) { + if (gDPC->new_dpc_queue(&gDPCHandle, "acpi_task", B_NORMAL_PRIORITY) != B_OK) { ERROR("AcpiInitializeSubsystem failed (new_dpc_queue() failed!)\n"); goto err; } @@ -151,7 +157,7 @@ /* Phew. Now in ACPI mode */ TRACE("ACPI initialized\n"); return B_OK; - + err: #ifndef __HAIKU__ put_module(B_DPC_MODULE_NAME); @@ -166,9 +172,9 @@ ERROR("Could not bring system out of ACPI mode. Oh well.\n"); /* This isn't so terrible. We'll just fail silently */ - if (gDPChandle != NULL) { - gDPC->delete_dpc_queue(gDPChandle); - gDPChandle = NULL; + if (gDPCHandle != NULL) { + gDPC->delete_dpc_queue(gDPCHandle); + gDPCHandle = NULL; } #ifndef __HAIKU__ @@ -187,304 +193,302 @@ } -status_t -acpi_rescan_stub(void) -{ - return B_OK; -} - - -void +void enable_fixed_event(uint32 event) { - AcpiEnableEvent(event,0); + AcpiEnableEvent(event, 0); } -void +void disable_fixed_event(uint32 event) { - AcpiDisableEvent(event,0); + AcpiDisableEvent(event, 0); } -uint32 +uint32 fixed_event_status(uint32 event) { ACPI_EVENT_STATUS status = 0; - AcpiGetEventStatus(event,&status); - return (status/* & ACPI_EVENT_FLAG_SET*/); + AcpiGetEventStatus(event, &status); + return status/* & ACPI_EVENT_FLAG_SET*/; } -void +void reset_fixed_event(uint32 event) { AcpiClearEvent(event); } -status_t -install_fixed_event_handler (uint32 event, interrupt_handler *handler, void *data) +status_t +install_fixed_event_handler(uint32 event, interrupt_handler* handler, + void *data) { - return ((AcpiInstallFixedEventHandler(event,handler,data) == AE_OK) ? B_OK : B_ERROR); + return AcpiInstallFixedEventHandler(event, (void*)handler, data) == AE_OK + ? B_OK : B_ERROR; } -status_t -remove_fixed_event_handler (uint32 event, interrupt_handler *handler) +status_t +remove_fixed_event_handler(uint32 event, interrupt_handler* handler) { - return ((AcpiRemoveFixedEventHandler(event,handler) == AE_OK) ? B_OK : B_ERROR); + return AcpiRemoveFixedEventHandler(event, (void*)handler) == AE_OK + ? B_OK : B_ERROR; } -status_t -get_next_entry (uint32 object_type, const char *base, char *result, size_t len, void **counter) +status_t +get_next_entry(uint32 objectType, const char *base, char *result, + size_t length, void **counter) { - ACPI_STATUS result_status; - ACPI_HANDLE parent,child,new_child; + ACPI_HANDLE parent, child, newChild; ACPI_BUFFER buffer; - - if ((base == NULL) || (strcmp(base,"\\") == 0)) { + ACPI_STATUS status; + + if (base == NULL || !strcmp(base, "\\")) { parent = ACPI_ROOT_OBJECT; } else { - result_status = AcpiGetHandle(NULL,base,&parent); - if (result_status != AE_OK) + status = AcpiGetHandle(NULL, (char*)base, &parent); + if (status != AE_OK) return B_ENTRY_NOT_FOUND; } - + child = *counter; - - result_status = AcpiGetNextObject(object_type,parent,child,&new_child); - if (result_status != AE_OK) + + status = AcpiGetNextObject(objectType, parent, child, &newChild); + if (status != AE_OK) return B_ENTRY_NOT_FOUND; - - *counter = new_child; - buffer.Length = len; + + *counter = newChild; + buffer.Length = length; buffer.Pointer = result; - - result_status = AcpiGetName(new_child,ACPI_FULL_PATHNAME,&buffer); - if (result_status != AE_OK) + + status = AcpiGetName(newChild, ACPI_FULL_PATHNAME, &buffer); + if (status != AE_OK) return B_NO_MEMORY; /* Corresponds to AE_BUFFER_OVERFLOW */ - + return B_OK; } -static ACPI_STATUS -get_device_by_hid_callback(ACPI_HANDLE object, UINT32 depth, void *context, void **return_val) +status_t +get_device(const char* hid, uint32 index, char* result, size_t resultLength) { - ACPI_STATUS result; - ACPI_BUFFER buffer; - uint32 *counter = (uint32 *)(context); - - *return_val = NULL; - - if (counter[0] == counter[1]) { - buffer.Length = 254; - buffer.Pointer = malloc(255); - - result = AcpiGetName(object,ACPI_FULL_PATHNAME,&buffer); - if (result != AE_OK) { - free(buffer.Pointer); - return AE_CTRL_TERMINATE; - } - - ((char*)(buffer.Pointer))[buffer.Length] = '\0'; - *return_val = buffer.Pointer; - return AE_CTRL_TERMINATE; - } - - counter[1]++; - return AE_OK; -} + ACPI_STATUS status; + uint32 counter[2] = {index, 0}; + char *buffer = NULL; + status = AcpiGetDevices((char*)hid, (void*)&get_device_by_hid_callback, + counter, (void**)&buffer); + if (status != AE_OK || buffer == NULL) + return B_ENTRY_NOT_FOUND; -status_t -get_device (const char *hid, uint32 index, char *result) -{ - ACPI_STATUS status; - uint32 counter[2] = {index,0}; - char *result2 = NULL; - - status = AcpiGetDevices((char *)hid,&get_device_by_hid_callback,counter,&result2); - if ((status != AE_OK) || (result2 == NULL)) - return B_ENTRY_NOT_FOUND; - - strcpy(result,result2); - free(result2); + strlcpy(result, buffer, resultLength); + free(buffer); return B_OK; } -status_t -get_device_hid (const char *path, char *hid) +status_t +get_device_hid(const char *path, char *hid) { ACPI_HANDLE handle; ACPI_OBJECT info; - ACPI_BUFFER info_buffer; - - if (AcpiGetHandle(NULL,path,&handle) != AE_OK) + ACPI_BUFFER infoBuffer; + + if (AcpiGetHandle(NULL, (char*)path, &handle) != AE_OK) return B_ENTRY_NOT_FOUND; - - info_buffer.Pointer = &info; - info_buffer.Length = sizeof(ACPI_OBJECT); + + infoBuffer.Pointer = &info; + infoBuffer.Length = sizeof(ACPI_OBJECT); info.String.Pointer = hid; info.String.Length = 9; info.String.Type = ACPI_TYPE_STRING; - - if (AcpiEvaluateObject(handle,"_HID",NULL,&info_buffer) != AE_OK) + + if (AcpiEvaluateObject(handle, "_HID", NULL, &infoBuffer) != AE_OK) return B_BAD_TYPE; - + if (info.Type == ACPI_TYPE_INTEGER) { - uint32 EisaId = AcpiUtDwordByteSwap (info.Integer.Value); + uint32 eisaId = AcpiUtDwordByteSwap(info.Integer.Value); - hid[0] = (char) ('@' + (((unsigned long) EisaId >> 26) & 0x1f)); - hid[1] = (char) ('@' + ((EisaId >> 21) & 0x1f)); - hid[2] = (char) ('@' + ((EisaId >> 16) & 0x1f)); - hid[3] = AcpiUtHexToAsciiChar ((ACPI_INTEGER) EisaId, 12); - hid[4] = AcpiUtHexToAsciiChar ((ACPI_INTEGER) EisaId, 8); - hid[5] = AcpiUtHexToAsciiChar ((ACPI_INTEGER) EisaId, 4); - hid[6] = AcpiUtHexToAsciiChar ((ACPI_INTEGER) EisaId, 0); + hid[0] = (char) ('@' + ((eisaId >> 26) & 0x1f)); + hid[1] = (char) ('@' + ((eisaId >> 21) & 0x1f)); + hid[2] = (char) ('@' + ((eisaId >> 16) & 0x1f)); + hid[3] = AcpiUtHexToAsciiChar((ACPI_INTEGER)eisaId, 12); + hid[4] = AcpiUtHexToAsciiChar((ACPI_INTEGER)eisaId, 8); + hid[5] = AcpiUtHexToAsciiChar((ACPI_INTEGER)eisaId, 4); + hid[6] = AcpiUtHexToAsciiChar((ACPI_INTEGER)eisaId, 0); hid[7] = 0; } - + hid[ACPI_DEVICE_ID_LENGTH] = '\0'; return B_OK; } -uint32 -get_object_type (const char *path) +uint32 +get_object_type(const char* path) { ACPI_HANDLE handle; ACPI_OBJECT_TYPE type; - - if (AcpiGetHandle(NULL,path,&handle) != AE_OK) + + if (AcpiGetHandle(NULL, (char*)path, &handle) != AE_OK) return B_ENTRY_NOT_FOUND; - - AcpiGetType(handle,&type); + + AcpiGetType(handle, &type); return type; } -status_t -get_object (const char *path, acpi_object_type **return_value) +status_t +get_object(const char* path, acpi_object_type** _returnValue) { ACPI_HANDLE handle; ACPI_BUFFER buffer; ACPI_STATUS status; - - status = AcpiGetHandle(NULL, path, &handle); - if (status != AE_OK) { + + status = AcpiGetHandle(NULL, (char*)path, &handle); + if (status != AE_OK) return B_ENTRY_NOT_FOUND; - } + buffer.Pointer = NULL; buffer.Length = ACPI_ALLOCATE_BUFFER; - + status = AcpiEvaluateObject(handle, NULL, NULL, &buffer); - - *return_value = buffer.Pointer; - return (status == AE_OK) ? B_OK : B_ERROR; + + *_returnValue = buffer.Pointer; + return status == AE_OK ? B_OK : B_ERROR; } -status_t -get_object_typed (const char *path, acpi_object_type **return_value, uint32 object_type) +status_t +get_object_typed(const char* path, acpi_object_type** _returnValue, + uint32 objectType) { ACPI_HANDLE handle; ACPI_BUFFER buffer; ACPI_STATUS status; - + status = AcpiGetHandle(NULL, path, &handle); - if (status != AE_OK) { + if (status != AE_OK) return B_ENTRY_NOT_FOUND; - } + buffer.Pointer = NULL; buffer.Length = ACPI_ALLOCATE_BUFFER; - - status = AcpiEvaluateObjectTyped(handle, NULL, NULL, &buffer, object_type); - - *return_value = buffer.Pointer; - return (status == AE_OK) ? B_OK : B_ERROR; + + status = AcpiEvaluateObjectTyped(handle, NULL, NULL, &buffer, objectType); + + *_returnValue = buffer.Pointer; + return status == AE_OK ? B_OK : B_ERROR; } -status_t -evaluate_object (const char *object, acpi_object_type *return_value, size_t buf_len) +status_t +evaluate_object(const char* object, acpi_object_type* returnValue, + size_t bufferLength) { ACPI_BUFFER buffer; ACPI_STATUS status; - - buffer.Pointer = return_value; - buffer.Length = buf_len; - - status = AcpiEvaluateObject(NULL,object,NULL,(return_value != NULL) ? &buffer : NULL); - return (status == AE_OK) ? B_OK : B_ERROR; + + buffer.Pointer = returnValue; + buffer.Length = bufferLength; + + status = AcpiEvaluateObject(NULL, object, NULL, returnValue != NULL + ? &buffer : NULL); + return status == AE_OK ? B_OK : B_ERROR; } -status_t -evaluate_method (const char *object, const char *method, acpi_object_type *return_value, - size_t buf_len, acpi_object_type *args, int num_args) +status_t +evaluate_method(const char* object, const char* method, + acpi_object_type *returnValue, size_t bufferLength, acpi_object_type *args, + int numArgs) { ACPI_BUFFER buffer; ACPI_STATUS status; - ACPI_OBJECT_LIST acpi_args; + ACPI_OBJECT_LIST acpiArgs; ACPI_HANDLE handle; - - if (AcpiGetHandle(NULL,object,&handle) != AE_OK) + + if (AcpiGetHandle(NULL, object, &handle) != AE_OK) return B_ENTRY_NOT_FOUND; - - buffer.Pointer = return_value; - buffer.Length = buf_len; - - acpi_args.Count = num_args; - acpi_args.Pointer = args; - - status = AcpiEvaluateObject(handle,method,(args != NULL) ? &acpi_args : NULL,(return_value != NULL) ? &buffer : NULL); - return (status == AE_OK) ? B_OK : B_ERROR; -} + buffer.Pointer = returnValue; + buffer.Length = bufferLength; -void -waking_vector(void) -{ - //--- This should do something --- + acpiArgs.Count = numArgs; + acpiArgs.Pointer = args; + + status = AcpiEvaluateObject(handle, method, args != NULL ? &acpiArgs : NULL, + returnValue != NULL ? &buffer : NULL); + return status == AE_OK ? B_OK : B_ERROR; } -status_t -enter_sleep_state (uint8 state) +static status_t +prepare_sleep_state(uint8 state, void (*wakeFunc)(void), size_t size) { ACPI_STATUS status; - cpu_status cpu; - physical_entry wake_vector; - - lock_memory(&waking_vector,sizeof(waking_vector),0); - get_memory_map(&waking_vector,sizeof(waking_vector),&wake_vector,1); - - status = AcpiSetFirmwareWakingVector(wake_vector.address); - if (status != AE_OK) - return B_ERROR; - + + if (state != ACPI_POWER_STATE_OFF) { + physical_entry wakeVector; + + lock_memory(&wakeFunc, size, 0); + get_memory_map(&wakeFunc, size, &wakeVector, 1); + + status = AcpiSetFirmwareWakingVector(wakeVector.address); + if (status != AE_OK) + return B_ERROR; + } + status = AcpiEnterSleepStatePrep(state); if (status != AE_OK) return B_ERROR; - - /* NOT SMP SAFE (!!!!!!!!!!!) */ - - cpu = disable_interrupts(); + + return B_OK; +} + + +static status_t +enter_sleep_state(uint8 state) +{ + ACPI_STATUS status; + status = AcpiEnterSleepState(state); - restore_interrupts(cpu); - if (status != AE_OK) return B_ERROR; - + /*status = AcpiLeaveSleepState(state); if (status != AE_OK) return B_ERROR;*/ - + return B_OK; } + +struct acpi_module_info gACPIModule = { + { + B_ACPI_MODULE_NAME, + B_KEEP_LOADED, + acpi_std_ops + }, + + enable_fixed_event, + disable_fixed_event, + fixed_event_status, + reset_fixed_event, + install_fixed_event_handler, + remove_fixed_event_handler, + get_next_entry, + get_device, + get_device_hid, + get_object_type, + get_object, + get_object_typed, + evaluate_object, + evaluate_method, + prepare_sleep_state, + enter_sleep_state +}; Modified: haiku/trunk/src/add-ons/kernel/bus_managers/acpi/acpi_module.c =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/acpi/acpi_module.c 2008-09-10 16:22:23 UTC (rev 27402) +++ haiku/trunk/src/add-ons/kernel/bus_managers/acpi/acpi_module.c 2008-09-10 19:24:37 UTC (rev 27403) @@ -43,29 +43,29 @@ if (strcmp(bus, "root")) return 0.0; - + return 1.0; } -static status_t +static status_t acpi_module_register_device(device_node *parent) { device_attr attrs[] = { { B_DEVICE_PRETTY_NAME, B_STRING_TYPE, { string: "ACPI" }}, - + { B_DEVICE_FLAGS, B_UINT32_TYPE, { ui32: B_KEEP_DRIVER_LOADED }}, {} }; io_resource *resources = NULL; - + return gDeviceManager->register_node(parent, ACPI_ROOT_MODULE_NAME, attrs, resources, NULL); } -static status_t +static status_t acpi_enumerate_child_devices(device_node *node, const char *root) { char result[255]; @@ -86,25 +86,25 @@ acpi_enumerate_child_devices(node, result); continue; } - + switch (type) { case ACPI_TYPE_DEVICE: { char hid[9] = ""; device_attr attrs[] = { // info about device { B_DEVICE_BUS, B_STRING_TYPE, { string: "acpi" }}, - + // location on ACPI bus { ACPI_DEVICE_PATH_ITEM, B_STRING_TYPE, { string: result }}, - + // info about the device { ACPI_DEVICE_HID_ITEM, B_STRING_TYPE, { string: hid }}, { ACPI_DEVICE_TYPE_ITEM, B_UINT32_TYPE, { ui32: type }}, - + // consumer specification - /*{ B_DRIVER_MAPPING, B_STRING_TYPE, { string: + /*{ B_DRIVER_MAPPING, B_STRING_TYPE, { string: "hid_%" ACPI_DEVICE_HID_ITEM "%" }}, - { B_DRIVER_MAPPING "/0", B_STRING_TYPE, { string: + { B_DRIVER_MAPPING "/0", B_STRING_TYPE, { string: "type_%" ACPI_DEVICE_TYPE_ITEM "%" }},*/ { B_DEVICE_FLAGS, B_UINT32_TYPE, { ui32: B_FIND_CHILD_ON_DEMAND|B_FIND_MULTIPLE_CHILDREN }}, { NULL } @@ -122,20 +122,20 @@ device_attr attrs[] = { // info about device { B_DEVICE_BUS, B_STRING_TYPE, { string: "acpi" }}, - + // location on ACPI bus { ACPI_DEVICE_PATH_ITEM, B_STRING_TYPE, { string: result }}, - + // info about the device { ACPI_DEVICE_TYPE_ITEM, B_UINT32_TYPE, { ui32: type }}, - + // consumer specification - /*{ B_DRIVER_MAPPING, B_STRING_TYPE, { string: + /*{ B_DRIVER_MAPPING, B_STRING_TYPE, { string: "type_%" ACPI_DEVICE_TYPE_ITEM "%" }},*/ { B_DEVICE_FLAGS, B_UINT32_TYPE, { ui32: B_FIND_CHILD_ON_DEMAND|B_FIND_MULTIPLE_CHILDREN }}, { NULL } }; - + if (gDeviceManager->register_node(node, ACPI_DEVICE_MODULE_NAME, attrs, NULL, &deviceNode) == B_OK) acpi_enumerate_child_devices(deviceNode, result); break; @@ -151,12 +151,12 @@ } -static status_t +static status_t acpi_module_register_child_devices(void *cookie) { status_t err; device_node *node = cookie; - + err = gDeviceManager->publish_device(node, "acpi/namespace", ACPI_NS_DUMP_DEVICE_MODULE_NAME); if (err != B_OK) { return err; @@ -195,11 +195,11 @@ return put_module(B_ACPI_MODULE_NAME); } - return B_BAD_VALUE; + return B_BAD_VALUE; } -static struct acpi_root_info sACPIModule = { +static struct acpi_root_info sACPIRootModule = { { { ACPI_ROOT_MODULE_NAME, @@ -230,13 +230,12 @@ get_object_typed, evaluate_object, evaluate_method, - }; _EXPORT module_info *modules[] = { - (module_info *) &acpi_module, - (module_info *) &sACPIModule, - (module_info *) &acpi_ns_dump_module, - (module_info *) &gACPIDeviceModule, + (module_info *)&gACPIModule, + (module_info *)&sACPIRootModule, + (module_info *)&acpi_ns_dump_module, + (module_info *)&gACPIDeviceModule, NULL }; Modified: haiku/trunk/src/add-ons/kernel/bus_managers/acpi/acpi_priv.h =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/acpi/acpi_priv.h 2008-09-10 16:22:23 UTC (rev 27402) +++ haiku/trunk/src/add-ons/kernel/bus_managers/acpi/acpi_priv.h 2008-09-10 19:24:37 UTC (rev 27403) @@ -1,9 +1,7 @@ /* * Copyright 2006, J?r?me Duval. All rights reserved. - * * Distributed under the terms of the MIT License. */ - #ifndef __ACPI_PRIV_H__ #define __ACPI_PRIV_H__ @@ -24,70 +22,80 @@ extern device_manager_info *gDeviceManager; - - // ACPI root. typedef struct acpi_root_info { driver_module_info info; - + /* Fixed Event Management */ - - void (*enable_fixed_event) (uint32 event); - void (*disable_fixed_event) (uint32 event); - - uint32 (*fixed_event_status) (uint32 event); - /* Returns 1 if event set, 0 otherwise */ - void (*reset_fixed_event) (uint32 event); - - status_t (*install_fixed_event_handler) (uint32 event, interrupt_handler *handler, void *data); - status_t (*remove_fixed_event_handler) (uint32 event, interrupt_handler *handler); + void (*enable_fixed_event) (uint32 event); + void (*disable_fixed_event) (uint32 event); + + uint32 (*fixed_event_status) (uint32 event); + /* Returns 1 if event set, 0 otherwise */ + void (*reset_fixed_event) (uint32 event); + + status_t (*install_fixed_event_handler)(uint32 event, + interrupt_handler *handler, void *data); + status_t (*remove_fixed_event_handler)(uint32 event, + interrupt_handler *handler); + /* Namespace Access */ - - status_t (*get_next_entry) (uint32 object_type, const char *base, char *result, size_t len, void **counter); - status_t (*get_device) (const char *hid, uint32 index, char *result); - - status_t (*get_device_hid) (const char *path, char *hid); - uint32 (*get_object_type) (const char *path); - status_t (*get_object) (const char *path, acpi_object_type **return_value); - status_t (*get_object_typed) (const char *path, acpi_object_type **return_value, uint32 object_type); - + [... truncated: 272 lines follow ...] From axeld at mail.berlios.de Wed Sep 10 21:50:08 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Wed, 10 Sep 2008 21:50:08 +0200 Subject: [Haiku-commits] r27404 - in haiku/trunk: headers/private/kernel/arch/x86 src/system/kernel/arch/x86 Message-ID: <200809101950.m8AJo8Up021257@sheep.berlios.de> Author: axeld Date: 2008-09-10 21:50:08 +0200 (Wed, 10 Sep 2008) New Revision: 27404 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27404&view=rev Added: haiku/trunk/src/system/kernel/arch/x86/arch_cpu.cpp Removed: haiku/trunk/src/system/kernel/arch/x86/arch_cpu.c Modified: haiku/trunk/headers/private/kernel/arch/x86/arch_cpu.h haiku/trunk/src/system/kernel/arch/x86/Jamfile haiku/trunk/src/system/kernel/arch/x86/apm.cpp Log: * Added acpi_shutdown() method. If the ACPI bus manager is installed, this will be used now. Tested only with VMware so far. * apm_shutdown() is now called with interrupts turned on. * Renamed arch_cpu.c to arch_cpu.cpp. * Minor cleanup. Modified: haiku/trunk/headers/private/kernel/arch/x86/arch_cpu.h =================================================================== --- haiku/trunk/headers/private/kernel/arch/x86/arch_cpu.h 2008-09-10 19:24:37 UTC (rev 27403) +++ haiku/trunk/headers/private/kernel/arch/x86/arch_cpu.h 2008-09-10 19:50:08 UTC (rev 27404) @@ -222,7 +222,7 @@ typedef struct arch_cpu_info { // saved cpu info enum x86_vendors vendor; - enum x86_feature_type feature[FEATURE_NUM]; + uint32 feature[FEATURE_NUM]; char model_name[49]; const char *vendor_name; int type; Modified: haiku/trunk/src/system/kernel/arch/x86/Jamfile =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/Jamfile 2008-09-10 19:24:37 UTC (rev 27403) +++ haiku/trunk/src/system/kernel/arch/x86/Jamfile 2008-09-10 19:50:08 UTC (rev 27404) @@ -14,7 +14,7 @@ KernelMergeObject kernel_arch_x86.o : arch_commpage.cpp - arch_cpu.c + arch_cpu.cpp arch_debug.cpp arch_debug_console.c arch_elf.c Modified: haiku/trunk/src/system/kernel/arch/x86/apm.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/apm.cpp 2008-09-10 19:24:37 UTC (rev 27403) +++ haiku/trunk/src/system/kernel/arch/x86/apm.cpp 2008-09-10 19:50:08 UTC (rev 27404) @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Copyright 2006-2008, Axel D?rfler, axeld at pinc-software.de. All rights reserved. * Distributed under the terms of the MIT License. */ @@ -256,7 +256,12 @@ if (!sAPMEnabled) return B_NOT_SUPPORTED; - return apm_set_state(APM_ALL_DEVICES, APM_POWER_STATE_OFF); + cpu_status state = disable_interrupts(); + + status_t status = apm_set_state(APM_ALL_DEVICES, APM_POWER_STATE_OFF); + + restore_interrupts(state); + return status; } Deleted: haiku/trunk/src/system/kernel/arch/x86/arch_cpu.c Copied: haiku/trunk/src/system/kernel/arch/x86/arch_cpu.cpp (from rev 27402, haiku/trunk/src/system/kernel/arch/x86/arch_cpu.c) =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/arch_cpu.c 2008-09-10 16:22:23 UTC (rev 27402) +++ haiku/trunk/src/system/kernel/arch/x86/arch_cpu.cpp 2008-09-10 19:50:08 UTC (rev 27404) @@ -0,0 +1,765 @@ +/* + * Copyright 2002-2008, Axel D?rfler, axeld at pinc-software.de. + * Distributed under the terms of the MIT License. + * + * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. + * Distributed under the terms of the NewOS License. + */ + + +#include + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "interrupts.h" + + +#define DUMP_FEATURE_STRING 1 + + +/* cpu vendor info */ +struct cpu_vendor_info { + const char *vendor; + const char *ident_string[2]; +}; + +static const struct cpu_vendor_info vendor_info[VENDOR_NUM] = { + { "Intel", { "GenuineIntel" } }, + { "AMD", { "AuthenticAMD" } }, + { "Cyrix", { "CyrixInstead" } }, + { "UMC", { "UMC UMC UMC" } }, + { "NexGen", { "NexGenDriven" } }, + { "Centaur", { "CentaurHauls" } }, + { "Rise", { "RiseRiseRise" } }, + { "Transmeta", { "GenuineTMx86", "TransmetaCPU" } }, + { "NSC", { "Geode by NSC" } }, +}; + +#define CR0_CACHE_DISABLE (1UL << 30) +#define CR0_NOT_WRITE_THROUGH (1UL << 29) +#define CR0_FPU_EMULATION (1UL << 2) +#define CR0_MONITOR_FPU (1UL << 1) + +#define CR4_OS_FXSR (1UL << 9) +#define CR4_OS_XMM_EXCEPTION (1UL << 10) + +struct set_mtrr_parameter { + int32 index; + uint64 base; + uint64 length; + uint8 type; +}; + + +extern "C" void reboot(void); + // from arch_x86.S + +void (*gX86SwapFPUFunc)(void *oldState, const void *newState); +bool gHasSSE = false; + +static uint32 sCpuRendezvous; +static uint32 sCpuRendezvous2; + +segment_descriptor *gGDT = NULL; + +/* Some specials for the double fault handler */ +//static struct tss sDoubleFaultTSS; +static uint32 sDoubleFaultStack[10240]; + +static x86_cpu_module_info *sCpuModule; + + +extern "C" void memcpy_generic(void* dest, const void* source, size_t count); +extern int memcpy_generic_end; + +x86_optimized_functions gOptimizedFunctions = { + memcpy_generic, + &memcpy_generic_end +}; + + +static status_t +acpi_shutdown(void) +{ + acpi_module_info* acpi; + if (get_module(B_ACPI_MODULE_NAME, (module_info**)&acpi) != B_OK) + return B_NOT_SUPPORTED; + + status_t status = acpi->enter_sleep_state(ACPI_POWER_STATE_OFF); + if (status == B_OK) + status = acpi->enter_sleep_state(ACPI_POWER_STATE_OFF); + + put_module(B_ACPI_MODULE_NAME); + return status; +} + + +/*! Disable CPU caches, and invalidate them. */ +static void +disable_caches() +{ + x86_write_cr0((x86_read_cr0() | CR0_CACHE_DISABLE) & ~CR0_NOT_WRITE_THROUGH); + wbinvd(); + arch_cpu_global_TLB_invalidate(); +} + + +/*! Invalidate CPU caches, and enable them. */ +static void +enable_caches() +{ + wbinvd(); + arch_cpu_global_TLB_invalidate(); + x86_write_cr0(x86_read_cr0() & ~(CR0_CACHE_DISABLE | CR0_NOT_WRITE_THROUGH)); +} + + +static void +set_mtrr(void *_parameter, int cpu) +{ + struct set_mtrr_parameter *parameter = (struct set_mtrr_parameter *)_parameter; + + // wait until all CPUs have arrived here + smp_cpu_rendezvous(&sCpuRendezvous, cpu); + + disable_caches(); + + sCpuModule->set_mtrr(parameter->index, parameter->base, parameter->length, + parameter->type); + + enable_caches(); + + // wait until all CPUs have arrived here + smp_cpu_rendezvous(&sCpuRendezvous2, cpu); +} + + +static void +init_mtrrs(void *_unused, int cpu) +{ + // wait until all CPUs have arrived here + smp_cpu_rendezvous(&sCpuRendezvous, cpu); + + disable_caches(); + + sCpuModule->init_mtrrs(); + + enable_caches(); + + // wait until all CPUs have arrived here + smp_cpu_rendezvous(&sCpuRendezvous2, cpu); +} + + +uint32 +x86_count_mtrrs(void) +{ + if (sCpuModule == NULL) + return 0; + + return sCpuModule->count_mtrrs(); +} + + +void +x86_set_mtrr(uint32 index, uint64 base, uint64 length, uint8 type) +{ + struct set_mtrr_parameter parameter; + parameter.index = index; + parameter.base = base; + parameter.length = length; + parameter.type = type; + + sCpuRendezvous = sCpuRendezvous2 = 0; + call_all_cpus(&set_mtrr, ¶meter); +} + + +status_t +x86_get_mtrr(uint32 index, uint64 *_base, uint64 *_length, uint8 *_type) +{ + // the MTRRs are identical on all CPUs, so it doesn't matter + // on which CPU this runs + return sCpuModule->get_mtrr(index, _base, _length, _type); +} + + +static void +init_sse(void) +{ + if (!x86_check_feature(IA32_FEATURE_SSE, FEATURE_COMMON) + || !x86_check_feature(IA32_FEATURE_FXSR, FEATURE_COMMON)) { + // we don't have proper SSE support + return; + } + + // enable OS support for SSE + x86_write_cr4(x86_read_cr4() | CR4_OS_FXSR | CR4_OS_XMM_EXCEPTION); + x86_write_cr0(x86_read_cr0() & ~(CR0_FPU_EMULATION | CR0_MONITOR_FPU)); + + gX86SwapFPUFunc = i386_fxsave_swap; + gHasSSE = true; +} + + +static void +load_tss(int cpu) +{ + short seg = ((TSS_BASE_SEGMENT + cpu) << 3) | DPL_KERNEL; + asm("movw %0, %%ax;" + "ltr %%ax;" : : "r" (seg) : "eax"); +} + + +static void +init_double_fault(int cpuNum) +{ + /* set up the double fault tss */ + /* TODO: Axel - fix SMP support */ + struct tss *tss = &gCPU[cpuNum].arch.double_fault_tss; + + memset(tss, 0, sizeof(struct tss)); + tss->sp0 = (uint32)sDoubleFaultStack + sizeof(sDoubleFaultStack); + tss->ss0 = KERNEL_DATA_SEG; + read_cr3(tss->cr3); + // copy the current cr3 to the double fault cr3 + tss->eip = (uint32)&double_fault; + tss->es = KERNEL_DATA_SEG; + tss->cs = KERNEL_CODE_SEG; + tss->ss = KERNEL_DATA_SEG; + tss->esp = tss->sp0; + tss->ds = KERNEL_DATA_SEG; + tss->fs = KERNEL_DATA_SEG; + tss->gs = KERNEL_DATA_SEG; + tss->ldt_seg_selector = 0; + tss->io_map_base = sizeof(struct tss); + + // add TSS descriptor for this new TSS + set_tss_descriptor(&gGDT[DOUBLE_FAULT_TSS_BASE_SEGMENT + cpuNum], + (addr_t)tss, sizeof(struct tss)); +} + + +#if DUMP_FEATURE_STRING +static void +dump_feature_string(int currentCPU, cpu_ent *cpu) +{ + char features[256]; + features[0] = 0; + + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_FPU) + strlcat(features, "fpu ", sizeof(features)); + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_VME) + strlcat(features, "vme ", sizeof(features)); + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_DE) + strlcat(features, "de ", sizeof(features)); + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_PSE) + strlcat(features, "pse ", sizeof(features)); + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_TSC) + strlcat(features, "tsc ", sizeof(features)); + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_MSR) + strlcat(features, "msr ", sizeof(features)); + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_PAE) + strlcat(features, "pae ", sizeof(features)); + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_MCE) + strlcat(features, "mce ", sizeof(features)); + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_CX8) + strlcat(features, "cx8 ", sizeof(features)); + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_APIC) + strlcat(features, "apic ", sizeof(features)); + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_SEP) + strlcat(features, "sep ", sizeof(features)); + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_MTRR) + strlcat(features, "mtrr ", sizeof(features)); + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_PGE) + strlcat(features, "pge ", sizeof(features)); + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_MCA) + strlcat(features, "mca ", sizeof(features)); + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_CMOV) + strlcat(features, "cmov ", sizeof(features)); + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_PAT) + strlcat(features, "pat ", sizeof(features)); + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_PSE36) + strlcat(features, "pse36 ", sizeof(features)); + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_PSN) + strlcat(features, "psn ", sizeof(features)); + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_CLFSH) + strlcat(features, "clfsh ", sizeof(features)); + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_DS) + strlcat(features, "ds ", sizeof(features)); + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_ACPI) + strlcat(features, "acpi ", sizeof(features)); + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_MMX) + strlcat(features, "mmx ", sizeof(features)); + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_FXSR) + strlcat(features, "fxsr ", sizeof(features)); + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_SSE) + strlcat(features, "sse ", sizeof(features)); + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_SSE2) + strlcat(features, "sse2 ", sizeof(features)); + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_SS) + strlcat(features, "ss ", sizeof(features)); + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_HTT) + strlcat(features, "htt ", sizeof(features)); + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_TM) + strlcat(features, "tm ", sizeof(features)); + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_PBE) + strlcat(features, "pbe ", sizeof(features)); + if (cpu->arch.feature[FEATURE_EXT] & IA32_FEATURE_EXT_SSE3) + strlcat(features, "sse3 ", sizeof(features)); + if (cpu->arch.feature[FEATURE_EXT] & IA32_FEATURE_EXT_MONITOR) + strlcat(features, "monitor ", sizeof(features)); + if (cpu->arch.feature[FEATURE_EXT] & IA32_FEATURE_EXT_DSCPL) + strlcat(features, "dscpl ", sizeof(features)); + if (cpu->arch.feature[FEATURE_EXT] & IA32_FEATURE_EXT_EST) + strlcat(features, "est ", sizeof(features)); + if (cpu->arch.feature[FEATURE_EXT] & IA32_FEATURE_EXT_TM2) + strlcat(features, "tm2 ", sizeof(features)); + if (cpu->arch.feature[FEATURE_EXT] & IA32_FEATURE_EXT_CNXTID) + strlcat(features, "cnxtid ", sizeof(features)); + if (cpu->arch.feature[FEATURE_EXT_AMD] & IA32_FEATURE_AMD_EXT_SYSCALL) + strlcat(features, "syscall ", sizeof(features)); + if (cpu->arch.feature[FEATURE_EXT_AMD] & IA32_FEATURE_AMD_EXT_NX) + strlcat(features, "nx ", sizeof(features)); + if (cpu->arch.feature[FEATURE_EXT_AMD] & IA32_FEATURE_AMD_EXT_MMXEXT) + strlcat(features, "mmxext ", sizeof(features)); + if (cpu->arch.feature[FEATURE_EXT_AMD] & IA32_FEATURE_AMD_EXT_FFXSR) + strlcat(features, "ffxsr ", sizeof(features)); + if (cpu->arch.feature[FEATURE_EXT_AMD] & IA32_FEATURE_AMD_EXT_LONG) + strlcat(features, "long ", sizeof(features)); + if (cpu->arch.feature[FEATURE_EXT_AMD] & IA32_FEATURE_AMD_EXT_3DNOWEXT) + strlcat(features, "3dnowext ", sizeof(features)); + if (cpu->arch.feature[FEATURE_EXT_AMD] & IA32_FEATURE_AMD_EXT_3DNOW) + strlcat(features, "3dnow ", sizeof(features)); + + dprintf("CPU %d: features: %s\n", currentCPU, features); +} +#endif // DUMP_FEATURE_STRING + + +static int +detect_cpu(int currentCPU) +{ + cpu_ent *cpu = get_cpu_struct(); + char vendorString[17]; + cpuid_info cpuid; + + // clear out the cpu info data + cpu->arch.vendor = VENDOR_UNKNOWN; + cpu->arch.vendor_name = "UNKNOWN VENDOR"; + cpu->arch.feature[FEATURE_COMMON] = 0; + cpu->arch.feature[FEATURE_EXT] = 0; + cpu->arch.feature[FEATURE_EXT_AMD] = 0; + cpu->arch.model_name[0] = 0; + + // print some fun data + get_current_cpuid(&cpuid, 0); + + // build the vendor string + memset(vendorString, 0, sizeof(vendorString)); + memcpy(vendorString, cpuid.eax_0.vendor_id, sizeof(cpuid.eax_0.vendor_id)); + + // get the family, model, stepping + get_current_cpuid(&cpuid, 1); + cpu->arch.type = cpuid.eax_1.type; + cpu->arch.family = cpuid.eax_1.family; + cpu->arch.extended_family = cpuid.eax_1.extended_family; + cpu->arch.model = cpuid.eax_1.model; + cpu->arch.extended_model = cpuid.eax_1.extended_model; + cpu->arch.stepping = cpuid.eax_1.stepping; + dprintf("CPU %d: type %d family %d extended_family %d model %d " + "extended_model %d stepping %d, string '%s'\n", + currentCPU, cpu->arch.type, cpu->arch.family, + cpu->arch.extended_family, cpu->arch.model, + cpu->arch.extended_model, cpu->arch.stepping, vendorString); + + // figure out what vendor we have here + + for (int32 i = 0; i < VENDOR_NUM; i++) { + if (vendor_info[i].ident_string[0] + && !strcmp(vendorString, vendor_info[i].ident_string[0])) { + cpu->arch.vendor = (x86_vendors)i; + cpu->arch.vendor_name = vendor_info[i].vendor; + break; + } + if (vendor_info[i].ident_string[1] + && !strcmp(vendorString, vendor_info[i].ident_string[1])) { + cpu->arch.vendor = (x86_vendors)i; + cpu->arch.vendor_name = vendor_info[i].vendor; + break; + } + } + + // see if we can get the model name + get_current_cpuid(&cpuid, 0x80000000); + if (cpuid.eax_0.max_eax >= 0x80000004) { + // build the model string (need to swap ecx/edx data before copying) + unsigned int temp; + memset(cpu->arch.model_name, 0, sizeof(cpu->arch.model_name)); + get_current_cpuid(&cpuid, 0x80000002); + temp = cpuid.regs.edx; cpuid.regs.edx = cpuid.regs.ecx; cpuid.regs.ecx = temp; + memcpy(cpu->arch.model_name, cpuid.as_chars, sizeof(cpuid.as_chars)); + get_current_cpuid(&cpuid, 0x80000003); + temp = cpuid.regs.edx; cpuid.regs.edx = cpuid.regs.ecx; cpuid.regs.ecx = temp; + memcpy(cpu->arch.model_name + 16, cpuid.as_chars, sizeof(cpuid.as_chars)); + get_current_cpuid(&cpuid, 0x80000004); + temp = cpuid.regs.edx; cpuid.regs.edx = cpuid.regs.ecx; cpuid.regs.ecx = temp; + memcpy(cpu->arch.model_name + 32, cpuid.as_chars, sizeof(cpuid.as_chars)); + + // some cpus return a right-justified string + int32 i = 0; + while (cpu->arch.model_name[i] == ' ') + i++; + if (i > 0) { + memmove(cpu->arch.model_name, &cpu->arch.model_name[i], + strlen(&cpu->arch.model_name[i]) + 1); + } + + dprintf("CPU %d: vendor '%s' model name '%s'\n", + currentCPU, cpu->arch.vendor_name, cpu->arch.model_name); + } else { + strcpy(cpu->arch.model_name, "unknown"); + } + + // load feature bits + get_current_cpuid(&cpuid, 1); + cpu->arch.feature[FEATURE_COMMON] = cpuid.eax_1.features; // edx + cpu->arch.feature[FEATURE_EXT] = cpuid.eax_1.extended_features; // ecx + if (cpu->arch.vendor == VENDOR_AMD) { + get_current_cpuid(&cpuid, 0x80000001); + cpu->arch.feature[FEATURE_EXT_AMD] = cpuid.regs.edx; // edx + } + +#if DUMP_FEATURE_STRING + dump_feature_string(currentCPU, cpu); +#endif + + return 0; +} + + +bool +x86_check_feature(uint32 feature, enum x86_feature_type type) +{ + cpu_ent *cpu = get_cpu_struct(); + +#if 0 + int i; + dprintf("x86_check_feature: feature 0x%x, type %d\n", feature, type); + for (i = 0; i < FEATURE_NUM; i++) { + dprintf("features %d: 0x%x\n", i, cpu->arch.feature[i]); + } +#endif + + return (cpu->arch.feature[type] & feature) != 0; +} + + +void* +x86_get_double_fault_stack(int32 cpu, size_t* _size) +{ + *_size = sizeof(sDoubleFaultStack); + return sDoubleFaultStack; +} + + +// #pragma mark - + + +status_t +arch_cpu_preboot_init_percpu(kernel_args *args, int cpu) +{ + x86_write_cr0(x86_read_cr0() & ~(CR0_FPU_EMULATION | CR0_MONITOR_FPU)); + gX86SwapFPUFunc = i386_fnsave_swap; + + return B_OK; +} + + +status_t +arch_cpu_init_percpu(kernel_args *args, int cpu) +{ + detect_cpu(cpu); + + // load the TSS for this cpu + // note the main cpu gets initialized in arch_cpu_init_post_vm() + if (cpu != 0) + load_tss(cpu); + + return 0; +} + +status_t +arch_cpu_init(kernel_args *args) +{ + __x86_setup_system_time(args->arch_args.system_time_cv_factor); + + return B_OK; +} + + +status_t +arch_cpu_init_post_vm(kernel_args *args) +{ + uint32 i; + + // account for the segment descriptors + + gGDT = (segment_descriptor *)args->arch_args.vir_gdt; + create_area("gdt", (void **)&gGDT, B_EXACT_ADDRESS, B_PAGE_SIZE, + B_ALREADY_WIRED, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); + + // currently taken out of the build, because it's not yet used (and assumes + // (a fixed number of used GDT entries) + //i386_selector_init(gGDT); // pass the new gdt + + // setup task-state segments + for (i = 0; i < args->num_cpus; i++) { + // initialize the regular and double fault tss stored in the per-cpu + // structure + memset(&gCPU[i].arch.tss, 0, sizeof(struct tss)); + gCPU[i].arch.tss.ss0 = KERNEL_DATA_SEG; + gCPU[i].arch.tss.io_map_base = sizeof(struct tss); + + // add TSS descriptor for this new TSS + set_tss_descriptor(&gGDT[TSS_BASE_SEGMENT + i], + (addr_t)&gCPU[i].arch.tss, sizeof(struct tss)); + + // initialize the double fault tss + init_double_fault(i); + } + + // set the current hardware task on cpu 0 + load_tss(0); + + x86_set_task_gate(8, DOUBLE_FAULT_TSS_BASE_SEGMENT << 3); + + // setup TLS descriptors (one for every CPU) + + for (i = 0; i < args->num_cpus; i++) { + set_segment_descriptor(&gGDT[TLS_BASE_SEGMENT + i], 0, TLS_SIZE, + DT_DATA_WRITEABLE, DPL_USER); + } + + // setup SSE2/3 support + init_sse(); + + return B_OK; +} + + +status_t +arch_cpu_init_post_modules(kernel_args *args) +{ + // initialize CPU module + + void *cookie = open_module_list("cpu"); + + while (true) { + char name[B_FILE_NAME_LENGTH]; + size_t nameLength = sizeof(name); + + if (read_next_module_name(cookie, name, &nameLength) != B_OK + || get_module(name, (module_info **)&sCpuModule) == B_OK) + break; + } + + close_module_list(cookie); + + // initialize MTRRs if available + if (x86_count_mtrrs() > 0) { + sCpuRendezvous = sCpuRendezvous2 = 0; + call_all_cpus(&init_mtrrs, NULL); + } + + // get optimized functions from the CPU module + if (sCpuModule != NULL && sCpuModule->get_optimized_functions != NULL) { + x86_optimized_functions functions; + memset(&functions, 0, sizeof(functions)); + + sCpuModule->get_optimized_functions(&functions); + + if (functions.memcpy != NULL) { + gOptimizedFunctions.memcpy = functions.memcpy; + gOptimizedFunctions.memcpy_end = functions.memcpy_end; + } + } + + // put the optimized functions into the commpage + fill_commpage_entry(COMMPAGE_ENTRY_X86_MEMCPY, gOptimizedFunctions.memcpy, + (addr_t)gOptimizedFunctions.memcpy_end + - (addr_t)gOptimizedFunctions.memcpy); + + return B_OK; +} + + +void +i386_set_tss_and_kstack(addr_t kstack) +{ + get_cpu_struct()->arch.tss.sp0 = kstack; +} + +void +arch_cpu_global_TLB_invalidate(void) +{ + uint32 flags = x86_read_cr4(); + + if (flags & IA32_CR4_GLOBAL_PAGES) { + // disable and reenable the global pages to flush all TLBs regardless + // of the global page bit + x86_write_cr4(flags & ~IA32_CR4_GLOBAL_PAGES); + x86_write_cr4(flags | IA32_CR4_GLOBAL_PAGES); + } else + arch_cpu_user_TLB_invalidate(); +} + + +void +arch_cpu_invalidate_TLB_range(addr_t start, addr_t end) +{ + int32 num_pages = end / B_PAGE_SIZE - start / B_PAGE_SIZE; + while (num_pages-- >= 0) { + invalidate_TLB(start); + start += B_PAGE_SIZE; + } +} + + +void +arch_cpu_invalidate_TLB_list(addr_t pages[], int num_pages) +{ + int i; + for (i = 0; i < num_pages; i++) { + invalidate_TLB(pages[i]); + } +} + +ssize_t +arch_cpu_user_strlcpy(char *to, const char *from, size_t size, addr_t *faultHandler) +{ + int fromLength = 0; + addr_t oldFaultHandler = *faultHandler; + + // this check is to trick the gcc4 compiler and have it keep the error label + if (to == NULL && size > 0) + goto error; + + *faultHandler = (addr_t)&&error; + + if (size > 0) { + to[--size] = '\0'; + // copy + for ( ; size; size--, fromLength++, to++, from++) { + if ((*to = *from) == '\0') + break; + } + } + // count any leftover from chars + while (*from++ != '\0') { + fromLength++; + } + + *faultHandler = oldFaultHandler; + return fromLength; + +error: + *faultHandler = oldFaultHandler; + return B_BAD_ADDRESS; +} + + +status_t +arch_cpu_user_memset(void *s, char c, size_t count, addr_t *faultHandler) +{ + char *xs = (char *)s; + addr_t oldFaultHandler = *faultHandler; + + // this check is to trick the gcc4 compiler and have it keep the error label + if (s == NULL) + goto error; + + *faultHandler = (addr_t)&&error; + + while (count--) + *xs++ = c; + + *faultHandler = oldFaultHandler; + return 0; + +error: + *faultHandler = oldFaultHandler; + return B_BAD_ADDRESS; +} + + +status_t +arch_cpu_shutdown(bool rebootSystem) +{ + if (!rebootSystem) { + status_t status = acpi_shutdown(); + if (status != B_OK) + status = apm_shutdown(); + + return status; + } + + cpu_status state = disable_interrupts(); + + // try to reset the system using the keyboard controller + out8(0xfe, 0x64); + + // Give some time to the controller to do its job (0.5s) + snooze(500000); + + // if that didn't help, try it this way + reboot(); + + restore_interrupts(state); + return B_ERROR; +} + + +void +arch_cpu_idle(void) +{ + asm("hlt"); +} + + +void +arch_cpu_sync_icache(void *address, size_t length) +{ + // instruction cache is always consistent on x86 +} + + +void +arch_cpu_memory_read_barrier(void) +{ + asm volatile ("lock;" : : : "memory"); + asm volatile ("addl $0,0(%%esp);" : : : "memory"); +} + + +void +arch_cpu_memory_write_barrier(void) +{ + asm volatile ("lock;" : : : "memory"); + asm volatile ("addl $0,0(%%esp);" : : : "memory"); +} + From stippi at mail.berlios.de Wed Sep 10 22:29:51 2008 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Wed, 10 Sep 2008 22:29:51 +0200 Subject: [Haiku-commits] r27405 - haiku/trunk/headers/os Message-ID: <200809102029.m8AKTpVM027590@sheep.berlios.de> Author: stippi Date: 2008-09-10 22:29:50 +0200 (Wed, 10 Sep 2008) New Revision: 27405 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27405&view=rev Modified: haiku/trunk/headers/os/BeBuild.h Log: "_IMPORT" was not defined, but most (all?) BeOS software that could be compiled for PPC would give compiler errors if this is not defined (to nothing). For the MetroWerks compiler, one needed to explicitely import/export classes and methods, but GCC does not need it. Modified: haiku/trunk/headers/os/BeBuild.h =================================================================== --- haiku/trunk/headers/os/BeBuild.h 2008-09-10 19:50:08 UTC (rev 27404) +++ haiku/trunk/headers/os/BeBuild.h 2008-09-10 20:29:50 UTC (rev 27405) @@ -21,11 +21,13 @@ # define _PRINTFLIKE(_format_, _args_) \ __attribute__((format(__printf__, _format_, _args_))) # define _EXPORT +# define _IMPORT #else # define _UNUSED(argument) argument # error Define _PACKED for your compiler # define _PRINTFLIKE(format, args) # define _EXPORT +# define _IMPORT #endif #endif /* _BE_BUILD_H */ From stippi at mail.berlios.de Wed Sep 10 22:34:11 2008 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Wed, 10 Sep 2008 22:34:11 +0200 Subject: [Haiku-commits] r27406 - in haiku/trunk: headers/os/interface src/kits/interface Message-ID: <200809102034.m8AKYBfj028135@sheep.berlios.de> Author: stippi Date: 2008-09-10 22:34:10 +0200 (Wed, 10 Sep 2008) New Revision: 27406 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27406&view=rev Modified: haiku/trunk/headers/os/interface/ScrollBar.h haiku/trunk/src/kits/interface/ScrollBar.cpp Log: Implemented BSize returning layout methods. Modified: haiku/trunk/headers/os/interface/ScrollBar.h =================================================================== --- haiku/trunk/headers/os/interface/ScrollBar.h 2008-09-10 20:29:50 UTC (rev 27405) +++ haiku/trunk/headers/os/interface/ScrollBar.h 2008-09-10 20:34:10 UTC (rev 27406) @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2006, Haiku, Inc. + * Copyright (c) 2001-2008, Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT license. * * Authors: @@ -71,6 +71,10 @@ virtual void AllDetached(); virtual status_t GetSupportedSuites(BMessage *data); + virtual BSize MinSize(); + virtual BSize MaxSize(); + virtual BSize PreferredSize(); + virtual status_t Perform(perform_code d, void *arg); #if DISABLES_ON_WINDOW_DEACTIVATION @@ -106,6 +110,8 @@ const BRect& updateRect, bool enabled, bool down); + BSize _MinSize() const; + float fMin; float fMax; float fSmallStep; Modified: haiku/trunk/src/kits/interface/ScrollBar.cpp =================================================================== --- haiku/trunk/src/kits/interface/ScrollBar.cpp 2008-09-10 20:29:50 UTC (rev 27405) +++ haiku/trunk/src/kits/interface/ScrollBar.cpp 2008-09-10 20:34:10 UTC (rev 27406) @@ -12,6 +12,7 @@ #include +#include #include #include #include @@ -1083,6 +1084,37 @@ } +BSize +BScrollBar::MinSize() +{ + return BLayoutUtils::ComposeSize(ExplicitMinSize(), _MinSize()); +} + + +BSize +BScrollBar::MaxSize() +{ + BSize maxSize = _MinSize(); + if (fOrientation == B_HORIZONTAL) + maxSize.width = B_SIZE_UNLIMITED; + else + maxSize.height = B_SIZE_UNLIMITED; + return BLayoutUtils::ComposeSize(ExplicitMaxSize(), maxSize); +} + + +BSize +BScrollBar::PreferredSize() +{ + BSize preferredSize = _MinSize(); + if (fOrientation == B_HORIZONTAL) + preferredSize.width = 2 * preferredSize.width; + else + preferredSize.height = 2 * preferredSize.height; + return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), preferredSize); +} + + status_t BScrollBar::Perform(perform_code d, void* arg) { @@ -1643,3 +1675,20 @@ EndLineArray(); } + +BSize +BScrollBar::_MinSize() const +{ + BSize minSize; + if (fOrientation == B_HORIZONTAL) { + minSize.width = 2 * B_V_SCROLL_BAR_WIDTH + + 2 * fPrivateData->fScrollBarInfo.min_knob_size; + minSize.height = B_H_SCROLL_BAR_HEIGHT; + } else { + minSize.width = B_V_SCROLL_BAR_WIDTH; + minSize.height = 2 * B_H_SCROLL_BAR_HEIGHT + + 2 * fPrivateData->fScrollBarInfo.min_knob_size; + } + return minSize; +} + From stippi at mail.berlios.de Wed Sep 10 23:07:33 2008 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Wed, 10 Sep 2008 23:07:33 +0200 Subject: [Haiku-commits] r27407 - in haiku/trunk: headers/os/interface src/kits/interface Message-ID: <200809102107.m8AL7X34000622@sheep.berlios.de> Author: stippi Date: 2008-09-10 23:07:32 +0200 (Wed, 10 Sep 2008) New Revision: 27407 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27407&view=rev Modified: haiku/trunk/headers/os/interface/ScrollBar.h haiku/trunk/src/kits/interface/ScrollBar.cpp Log: Added layout friendly constructor (untested). Modified: haiku/trunk/headers/os/interface/ScrollBar.h =================================================================== --- haiku/trunk/headers/os/interface/ScrollBar.h 2008-09-10 20:34:10 UTC (rev 27406) +++ haiku/trunk/headers/os/interface/ScrollBar.h 2008-09-10 21:07:32 UTC (rev 27407) @@ -27,12 +27,15 @@ class BScrollBar : public BView { - public: - BScrollBar(BRect frame, const char *name, BView *target, +public: + BScrollBar(BRect frame, const char* name, + BView* target, float min, float max, + orientation direction); + BScrollBar(const char* name, BView* target, float min, float max, orientation direction); - BScrollBar(BMessage *data); + BScrollBar(BMessage* data); virtual ~BScrollBar(); - static BArchivable *Instantiate(BMessage *data); + static BArchivable *Instantiate(BMessage* data); virtual status_t Archive(BMessage *data, bool deep = true) const; virtual void AttachedToWindow(); Modified: haiku/trunk/src/kits/interface/ScrollBar.cpp =================================================================== --- haiku/trunk/src/kits/interface/ScrollBar.cpp 2008-09-10 20:34:10 UTC (rev 27406) +++ haiku/trunk/src/kits/interface/ScrollBar.cpp 2008-09-10 21:07:32 UTC (rev 27407) @@ -207,6 +207,31 @@ } +BScrollBar::BScrollBar(const char* name, BView *target, + float min, float max, orientation direction) + : BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS), + fMin(min), + fMax(max), + fSmallStep(1), + fLargeStep(10), + fValue(0), + fProportion(0.0), + fTarget(NULL), + fOrientation(direction), + fTargetName(NULL) +{ + SetViewColor(B_TRANSPARENT_COLOR); + + fPrivateData = new BScrollBar::Private(this); + + SetTarget(target); + SetEventMask(B_NO_POINTER_HISTORY); + + _UpdateThumbFrame(); + _UpdateArrowButtons(); +} + + BScrollBar::BScrollBar(BMessage* data) : BView(data), fTarget(NULL), @@ -1108,9 +1133,9 @@ { BSize preferredSize = _MinSize(); if (fOrientation == B_HORIZONTAL) - preferredSize.width = 2 * preferredSize.width; + preferredSize.width *= 2; else - preferredSize.height = 2 * preferredSize.height; + preferredSize.height *= 2; return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), preferredSize); } From axeld at mail.berlios.de Wed Sep 10 23:49:41 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Wed, 10 Sep 2008 23:49:41 +0200 Subject: [Haiku-commits] r27408 - haiku/trunk/src/add-ons/kernel/file_systems/iso9660 Message-ID: <200809102149.m8ALnffv004672@sheep.berlios.de> Author: axeld Date: 2008-09-10 23:49:40 +0200 (Wed, 10 Sep 2008) New Revision: 27408 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27408&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/iso9660/iso9660.c haiku/trunk/src/add-ons/kernel/file_systems/iso9660/kernel_interface.cpp Log: * dirent::d_reclen was set incorrectly, causing bug #2699. * Removed unneeded "block_out" variable in ISOReadDirEnt(). * Minor cleanup. Modified: haiku/trunk/src/add-ons/kernel/file_systems/iso9660/iso9660.c =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/iso9660/iso9660.c 2008-09-10 21:07:32 UTC (rev 27407) +++ haiku/trunk/src/add-ons/kernel/file_systems/iso9660/iso9660.c 2008-09-10 21:49:40 UTC (rev 27408) @@ -315,45 +315,37 @@ } -/** Reads in a single directory entry and fills in the values in the - * dirent struct. Uses the cookie to keep track of the current block - * and position within the block. Also uses the cookie to determine when - * it has reached the end of the directory file. - * - * NOTE: If your file sytem seems to work ok from the command line, but - * the tracker doesn't seem to like it, check what you do here closely; - * in particular, if the d_ino in the stat struct isn't correct, the tracker - * will not display the entry. - */ - +/*! Reads in a single directory entry and fills in the values in the + dirent struct. Uses the cookie to keep track of the current block + and position within the block. Also uses the cookie to determine when + it has reached the end of the directory file. +*/ int -ISOReadDirEnt(nspace *ns, dircookie *cookie, struct dirent *dirent, size_t bufsize) +ISOReadDirEnt(nspace *ns, dircookie *cookie, struct dirent *dirent, + size_t bufsize) { - off_t totalRead = cookie->pos + ((cookie->block - cookie->startBlock) * - ns->logicalBlkSize[FS_DATA_FORMAT]); + off_t totalRead = cookie->pos + ((cookie->block - cookie->startBlock) + * ns->logicalBlkSize[FS_DATA_FORMAT]); off_t cacheBlock; char *blockData; int result = B_NO_ERROR; int bytesRead = 0; - bool block_out = false; TRACE(("ISOReadDirEnt - ENTER\n")); // If we're at the end of the data in a block, move to the next block. - while (1) { - blockData = (char *)block_cache_get_etc(ns->fBlockCache, cookie->block, 0, - ns->logicalBlkSize[FS_DATA_FORMAT]); - block_out = true; + while (true) { + blockData = (char *)block_cache_get_etc(ns->fBlockCache, cookie->block, + 0, ns->logicalBlkSize[FS_DATA_FORMAT]); if (blockData != NULL && *(blockData + cookie->pos) == 0) { - //NULL data, move to next block. + // NULL data, move to next block. block_cache_put(ns->fBlockCache, cookie->block); - block_out = false; + blockData = NULL; totalRead += ns->logicalBlkSize[FS_DATA_FORMAT] - cookie->pos; cookie->pos = 0; cookie->block++; - } - else + } else break; if (totalRead >= cookie->totalSize) @@ -363,37 +355,39 @@ cacheBlock = cookie->block; if (blockData != NULL && totalRead < cookie->totalSize) { vnode node; + result = InitNode(&node, blockData + cookie->pos, &bytesRead, + ns->joliet_level); + if (result == B_NO_ERROR) { + int nameBufSize = (bufsize - (2 * sizeof(dev_t) + 2* sizeof(ino_t) + + sizeof(unsigned short))); - if ((result = InitNode(&node, blockData + cookie->pos, &bytesRead, ns->joliet_level)) == - B_NO_ERROR) - { - int nameBufSize = (bufsize - (2 * sizeof(dev_t) + 2* sizeof(ino_t) + - sizeof(unsigned short))); - dirent->d_ino = (cookie->block << 30) + (cookie->pos & 0xFFFFFFFF); - dirent->d_reclen = node.fileIDLen; + dirent->d_reclen = sizeof(struct dirent) + node.fileIDLen + 1; if (node.fileIDLen <= nameBufSize) { // need to do some size checking here. - strncpy(dirent->d_name, node.fileIDString, node.fileIDLen +1); - TRACE(("ISOReadDirEnt - success, name is %s\n", dirent->d_name)); + strlcpy(dirent->d_name, node.fileIDString, node.fileIDLen + 1); + TRACE(("ISOReadDirEnt - success, name is %s\n", + dirent->d_name)); } else { - TRACE(("ISOReadDirEnt - ERROR, name %s does not fit in buffer of size %d\n", node.fileIDString, nameBufSize)); + TRACE(("ISOReadDirEnt - ERROR, name %s does not fit in buffer " + "of size %d\n", node.fileIDString, nameBufSize)); result = EINVAL; } cookie->pos += bytesRead; } - } else { + } else { if (totalRead >= cookie->totalSize) result = ENOENT; else result = ENOMEM; } - if (block_out) + if (blockData != NULL) block_cache_put(ns->fBlockCache, cacheBlock); - TRACE(("ISOReadDirEnt - EXIT, result is %s, vnid is %Lu\n", strerror(result), dirent->d_ino)); + TRACE(("ISOReadDirEnt - EXIT, result is %s, vnid is %Lu\n", + strerror(result), dirent->d_ino)); return result; } Modified: haiku/trunk/src/add-ons/kernel/file_systems/iso9660/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/iso9660/kernel_interface.cpp 2008-09-10 21:07:32 UTC (rev 27407) +++ haiku/trunk/src/add-ons/kernel/file_systems/iso9660/kernel_interface.cpp 2008-09-10 21:49:40 UTC (rev 27408) @@ -570,8 +570,8 @@ static status_t -fs_read_dir(fs_volume *_vol, fs_vnode *_node, void *_cookie, struct dirent *buffer, - size_t bufferSize, uint32 *num) +fs_read_dir(fs_volume *_vol, fs_vnode *_node, void *_cookie, + struct dirent *buffer, size_t bufferSize, uint32 *num) { nspace *ns = (nspace *)_vol->private_volume; dircookie *dirCookie = (dircookie *)_cookie; From mmlr at mail.berlios.de Wed Sep 10 23:52:40 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Wed, 10 Sep 2008 23:52:40 +0200 Subject: [Haiku-commits] r27409 - in haiku/trunk: headers/os/device src/add-ons/kernel/drivers/bus/usb src/kits/device Message-ID: <200809102152.m8ALqeMb005185@sheep.berlios.de> Author: mmlr Date: 2008-09-10 23:52:32 +0200 (Wed, 10 Sep 2008) New Revision: 27409 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27409&view=rev Modified: haiku/trunk/headers/os/device/USBKit.h haiku/trunk/src/add-ons/kernel/drivers/bus/usb/usb_raw.cpp haiku/trunk/src/add-ons/kernel/drivers/bus/usb/usb_raw.h haiku/trunk/src/kits/device/USBConfiguration.cpp haiku/trunk/src/kits/device/USBDevice.cpp haiku/trunk/src/kits/device/USBEndpoint.cpp haiku/trunk/src/kits/device/USBInterface.cpp haiku/trunk/src/kits/device/USBRoster.cpp Log: * Extend the usb_raw interface by alternate interface aware getters for interfaces, endpoints and generic descriptors. * Add getter for active interface index and simplify the count operation as it isn't misused to also get interface descriptors anymore. * Refactor out some common code into helper functions. * Adapt the USBKit to the changed/new interface. * Change how alternate interfaces are exposed by USBKit by providing normal BUSBInterface objects for alternate interfaces that can easily be examined and used. * Make BUSBInterface class aware of its alternate index and use the alternate aware usb_raw functionallity to build the endpoint and descriptor lists. * Add ActiveAlternateIndex() to find out what alternate is currently active. * Style cleanup of the USBKit classes, use std::nothrow everywhere and check all allocations. Simplify some code by removing optimization where the benefit is questionable. Modified: haiku/trunk/headers/os/device/USBKit.h =================================================================== --- haiku/trunk/headers/os/device/USBKit.h 2008-09-10 21:49:40 UTC (rev 27408) +++ haiku/trunk/headers/os/device/USBKit.h 2008-09-10 21:52:32 UTC (rev 27409) @@ -52,7 +52,7 @@ virtual void _ReservedUSBRoster4(); virtual void _ReservedUSBRoster5(); - void *fLooper; + void * fLooper; uint32 fReserved[10]; }; @@ -77,7 +77,7 @@ void Unset(); // Returns the location on the bus represented as hub/device sequence - const char *Location() const; + const char * Location() const; bool IsHub() const; // These are direct accessors to descriptor fields @@ -94,11 +94,12 @@ // descriptor data. The strings are decoded to normal 0 terminated // c strings and are cached and owned by the object. // If a string is not available an empty string is returned. - const char *ManufacturerString() const; - const char *ProductString() const; - const char *SerialNumberString() const; + const char * ManufacturerString() const; + const char * ProductString() const; + const char * SerialNumberString() const; - const usb_device_descriptor *Descriptor() const; + const usb_device_descriptor * + Descriptor() const; // GetStringDescriptor() can be used to retrieve the raw // usb_string_descriptor with a given index. The strings contained @@ -111,7 +112,7 @@ // 0-terminated c string for a given string index. Note that this // will allocate the string as "new char[];" and needs to be deleted // like "delete[] string;" by the caller. - char *DecodeStringDescriptor(uint32 index) const; + char * DecodeStringDescriptor(uint32 index) const; size_t GetDescriptor(uint8 type, uint8 index, uint16 languageID, void *data, @@ -124,9 +125,9 @@ // Use the returned object as an argument to SetConfiguration() to // change the active configuration of a device. uint32 CountConfigurations() const; - const BUSBConfiguration *ConfigurationAt(uint32 index) const; + const BUSBConfiguration * ConfigurationAt(uint32 index) const; - const BUSBConfiguration *ActiveConfiguration() const; + const BUSBConfiguration * ActiveConfiguration() const; status_t SetConfiguration( const BUSBConfiguration *configuration); @@ -143,16 +144,16 @@ virtual void _ReservedUSBDevice4(); virtual void _ReservedUSBDevice5(); - char *fPath; + char * fPath; int fRawFD; usb_device_descriptor fDescriptor; - BUSBConfiguration **fConfigurations; + BUSBConfiguration ** fConfigurations; uint32 fActiveConfiguration; -mutable char *fManufacturerString; -mutable char *fProductString; -mutable char *fSerialNumberString; +mutable char * fManufacturerString; +mutable char * fProductString; +mutable char * fSerialNumberString; uint32 fReserved[10]; }; @@ -171,14 +172,14 @@ // configuration is located at the index returned by Index() within // that parent device. uint32 Index() const; - const BUSBDevice *Device() const; + const BUSBDevice * Device() const; // Gets a describing string of this configuration if available. // Otherwise an empty string is returned. - const char *ConfigurationString() const; + const char * ConfigurationString() const; - const usb_configuration_descriptor - *Descriptor() const; + const usb_configuration_descriptor * + Descriptor() const; // With CountInterfaces() and InterfaceAt() you can iterate through // the child interfaces of this configuration. It is the only valid @@ -186,7 +187,7 @@ // Note that the interface objects retrieved using InterfaceAt() will // be invalid and deleted as soon as this configuration gets deleted. uint32 CountInterfaces() const; - const BUSBInterface *InterfaceAt(uint32 index) const; + const BUSBInterface * InterfaceAt(uint32 index) const; private: friend class BUSBDevice; @@ -194,14 +195,14 @@ uint32 index, int rawFD); ~BUSBConfiguration(); - BUSBDevice *fDevice; + BUSBDevice * fDevice; uint32 fIndex; int fRawFD; usb_configuration_descriptor fDescriptor; - BUSBInterface **fInterfaces; + BUSBInterface ** fInterfaces; -mutable char *fConfigurationString; +mutable char * fConfigurationString; uint32 fReserved[10]; }; @@ -215,12 +216,14 @@ public: // Configuration() returns the parent configuration of this interface. // This interface is located at the index returned by Index() in that - // parent configuration. + // parent configuration and represents the alternate interface returned + // by AlternateIndex(). // Device() is a convenience function to directly reach the parent // device of this interface instead of going through the configuration. uint32 Index() const; - const BUSBConfiguration *Configuration() const; - const BUSBDevice *Device() const; + uint32 AlternateIndex() const; + const BUSBConfiguration * Configuration() const; + const BUSBDevice * Device() const; // These are accessors to descriptor fields. InterfaceString() tries // to return a describing string of this interface. If no string is @@ -228,10 +231,10 @@ uint8 Class() const; uint8 Subclass() const; uint8 Protocol() const; - const char *InterfaceString() const; + const char * InterfaceString() const; - const usb_interface_descriptor - *Descriptor() const; + const usb_interface_descriptor * + Descriptor() const; // Use OtherDescriptorAt() to get generic descriptors of an interface. // These are usually vendor or device specific extensions. @@ -244,7 +247,7 @@ // valid way to get BUSBEndpoint object. Note that these objects will // get invalid and deleted as soon as the parent interface is deleted. uint32 CountEndpoints() const; - const BUSBEndpoint *EndpointAt(uint32 index) const; + const BUSBEndpoint * EndpointAt(uint32 index) const; // Using CountAlternates() you can retrieve the number of alternate // interfaces for this interface. Note that this interface itself @@ -252,40 +255,48 @@ // that you are currently using the sole interface present. // AlternateAt() returns the interface descriptor of the alternate // interface with the specified index. Using that you can peek at the - // information contained in the descriptor without having to switch - // to this alternate interface. Note that the alternate index set in - // the interface descriptor returned is not necessarily the same index - // you used to get the descriptor. Always use the zero based index you - // used to get the information with and not the values of the returned - // descriptor as the stack will handle that translation internally. - // The interface descriptor returned was allocated by new and is yours. - // You need to delete it when you're done with it. + // attributes of that alternate (including endpoints) without having to + // switch to this alternate interface. + // Note that you cannot use any endpoint you retrieve through an + // interface you get through AlternateAt(). Even if you switch to that + // alternate later on, you cannot use an interface returned by + // AlternateAt(). Instead switch to that alternate using the interface + // you got from the configuration and then use this switched interface + // to enumerate the endpoints. + // ActiveAlternateIndex() returns the index of the currently active + // alternate interface. // With SetAlternate() you can switch this BUSBInterface object to the // alternate interface at the specified index. Note that all endpoints // retrieved through EndpointAt() will become invalid and will be // deleted as soon as you set an alternate interface (even if the // resulting interface is the same you were using before). uint32 CountAlternates() const; - usb_interface_descriptor *AlternateAt(uint32 alternateIndex); + uint32 ActiveAlternateIndex() const; + const BUSBInterface * AlternateAt(uint32 alternateIndex) const; status_t SetAlternate(uint32 alternateIndex); private: friend class BUSBConfiguration; BUSBInterface(BUSBConfiguration *config, - uint32 index, int rawFD); + uint32 index, uint32 alternate, + int rawFD); ~BUSBInterface(); void _UpdateDescriptorAndEndpoints(); - BUSBConfiguration *fConfiguration; + BUSBConfiguration * fConfiguration; uint32 fIndex; + uint32 fAlternate; int fRawFD; usb_interface_descriptor fDescriptor; - BUSBEndpoint **fEndpoints; + BUSBEndpoint ** fEndpoints; -mutable char *fInterfaceString; +mutable uint32 fAlternateCount; +mutable BUSBInterface ** fAlternates; +mutable char * fInterfaceString; + uint32 fReserved[10]; }; @@ -302,9 +313,9 @@ // reach the parent configuration or device of this endpoint instead // of going through the parent objects. uint32 Index() const; - const BUSBInterface *Interface() const; - const BUSBConfiguration *Configuration() const; - const BUSBDevice *Device() const; + const BUSBInterface * Interface() const; + const BUSBConfiguration * Configuration() const; + const BUSBDevice * Device() const; // These methods can be used to check for endpoint characteristics. bool IsBulk() const; @@ -318,8 +329,8 @@ uint16 MaxPacketSize() const; uint8 Interval() const; - const usb_endpoint_descriptor - *Descriptor() const; + const usb_endpoint_descriptor * + Descriptor() const; // These methods initiate transfers to or from the endpoint. All // transfers are synchronous and the actually transfered amount of @@ -343,13 +354,14 @@ // send the corresponding requests. bool IsStalled() const; status_t ClearStall() const; + private: friend class BUSBInterface; BUSBEndpoint(BUSBInterface *interface, uint32 index, int rawFD); ~BUSBEndpoint(); - BUSBInterface *fInterface; + BUSBInterface * fInterface; uint32 fIndex; int fRawFD; Modified: haiku/trunk/src/add-ons/kernel/drivers/bus/usb/usb_raw.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/bus/usb/usb_raw.cpp 2008-09-10 21:49:40 UTC (rev 27408) +++ haiku/trunk/src/add-ons/kernel/drivers/bus/usb/usb_raw.cpp 2008-09-10 21:52:32 UTC (rev 27409) @@ -124,6 +124,58 @@ // +static const usb_configuration_info * +usb_raw_get_configuration(raw_device *device, uint32 configIndex, + status_t *status) +{ + const usb_configuration_info *result = gUSBModule->get_nth_configuration( + device->device, configIndex); + if (result == NULL) { + *status = B_USB_RAW_STATUS_INVALID_CONFIGURATION; + return NULL; + } + + return result; +} + + +static const usb_interface_info * +usb_raw_get_interface(raw_device *device, uint32 configIndex, + uint32 interfaceIndex, uint32 alternateIndex, status_t *status) +{ + const usb_configuration_info *configurationInfo + = usb_raw_get_configuration(device, configIndex, status); + if (configurationInfo == NULL) + return NULL; + + if (interfaceIndex >= configurationInfo->interface_count) { + *status = B_USB_RAW_STATUS_INVALID_INTERFACE; + return NULL; + } + + const usb_interface_info *result = NULL; + if (alternateIndex == B_USB_RAW_ACTIVE_ALTERNATE) + result = configurationInfo->interface[interfaceIndex].active; + else { + const usb_interface_list *interfaceList = + &configurationInfo->interface[interfaceIndex]; + if (alternateIndex >= interfaceList->alt_count) { + *status = B_USB_RAW_STATUS_INVALID_INTERFACE; + return NULL; + } + + result = &interfaceList->alt[alternateIndex]; + } + + return result; +} + + +// +//#pragma mark - +// + + static status_t usb_raw_open(const char *name, uint32 flags, void **cookie) { @@ -211,11 +263,12 @@ { TRACE((DRIVER_NAME": ioctl\n")); raw_device *device = (raw_device *)cookie; - usb_raw_command *command = (usb_raw_command *)buffer; - if (device->device == 0) return B_DEV_NOT_READY; + usb_raw_command *command = (usb_raw_command *)buffer; + command->version.status = B_USB_RAW_STATUS_ABORTED; + switch (op) { case B_USB_RAW_COMMAND_GET_VERSION: { command->version.status = B_USB_RAW_PROTOCOL_VERSION; @@ -225,10 +278,8 @@ case B_USB_RAW_COMMAND_GET_DEVICE_DESCRIPTOR: { const usb_device_descriptor *deviceDescriptor = gUSBModule->get_device_descriptor(device->device); - if (!deviceDescriptor) { - command->device.status = B_USB_RAW_STATUS_ABORTED; + if (!deviceDescriptor) return B_OK; - } memcpy(command->device.descriptor, deviceDescriptor, sizeof(usb_device_descriptor)); @@ -238,12 +289,10 @@ case B_USB_RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR: { const usb_configuration_info *configurationInfo = - gUSBModule->get_nth_configuration(device->device, - command->config.config_index); - if (!configurationInfo) { - command->config.status = B_USB_RAW_STATUS_INVALID_CONFIGURATION; + usb_raw_get_configuration(device, command->config.config_index, + &command->config.status); + if (configurationInfo == NULL) return B_OK; - } memcpy(command->config.descriptor, configurationInfo->descr, sizeof(usb_configuration_descriptor)); @@ -251,155 +300,142 @@ return B_OK; } - case B_USB_RAW_COMMAND_GET_INTERFACE_DESCRIPTOR: { + case B_USB_RAW_COMMAND_GET_ALT_INTERFACE_COUNT: + case B_USB_RAW_COMMAND_GET_ACTIVE_ALT_INTERFACE_INDEX: { const usb_configuration_info *configurationInfo = - gUSBModule->get_nth_configuration(device->device, - command->interface.config_index); - if (!configurationInfo) { - command->interface.status = B_USB_RAW_STATUS_INVALID_CONFIGURATION; + usb_raw_get_configuration(device, + command->alternate.config_index, + &command->alternate.status); + if (configurationInfo == NULL) return B_OK; - } - if (command->interface.interface_index >= configurationInfo->interface_count) { - command->interface.status = B_USB_RAW_STATUS_INVALID_INTERFACE; + if (command->alternate.interface_index + >= configurationInfo->interface_count) { + command->alternate.status = B_USB_RAW_STATUS_INVALID_INTERFACE; return B_OK; } - const usb_interface_info *interfaceInfo = - configurationInfo->interface[command->interface.interface_index].active; - if (!interfaceInfo) { - command->interface.status = B_USB_RAW_STATUS_ABORTED; - return B_OK; + const usb_interface_list *interfaceList + = &configurationInfo->interface[ + command->alternate.interface_index]; + if (op == B_USB_RAW_COMMAND_GET_ALT_INTERFACE_COUNT) { + command->alternate.alternate_info = interfaceList->alt_count; + } else { + for (size_t i = 0; i < interfaceList->alt_count; i++) { + if (&interfaceList->alt[i] == interfaceList->active) { + command->alternate.alternate_info = i; + break; + } + } } - memcpy(command->interface.descriptor, interfaceInfo->descr, - sizeof(usb_interface_descriptor)); - command->interface.status = B_USB_RAW_STATUS_SUCCESS; - return B_OK; - } - - case B_USB_RAW_COMMAND_GET_ALT_INTERFACE_COUNT: { - const usb_configuration_info *configurationInfo = - gUSBModule->get_nth_configuration(device->device, - command->alternate.config_index); - if (!configurationInfo) { - command->alternate.status = B_USB_RAW_STATUS_INVALID_CONFIGURATION; - return B_OK; - } - - if (command->alternate.interface_index >= configurationInfo->interface_count) { - command->alternate.status = B_USB_RAW_STATUS_INVALID_INTERFACE; - return B_OK; - } - - *command->alternate.alternate_count - = configurationInfo->interface[command->alternate.interface_index].alt_count; command->alternate.status = B_USB_RAW_STATUS_SUCCESS; return B_OK; } - case B_USB_RAW_COMMAND_GET_ALT_INTERFACE_DESCRIPTOR: { - const usb_configuration_info *configurationInfo = - gUSBModule->get_nth_configuration(device->device, - command->alternate.config_index); - if (!configurationInfo) { - command->alternate.status = B_USB_RAW_STATUS_INVALID_CONFIGURATION; - return B_OK; + case B_USB_RAW_COMMAND_GET_INTERFACE_DESCRIPTOR: + case B_USB_RAW_COMMAND_GET_INTERFACE_DESCRIPTOR_ETC: { + const usb_interface_info *interfaceInfo = NULL; + if (op == B_USB_RAW_COMMAND_GET_INTERFACE_DESCRIPTOR) { + interfaceInfo = usb_raw_get_interface(device, + command->interface.config_index, + command->interface.interface_index, + B_USB_RAW_ACTIVE_ALTERNATE, + &command->interface.status); + } else { + interfaceInfo = usb_raw_get_interface(device, + command->interface_etc.config_index, + command->interface_etc.interface_index, + command->interface_etc.alternate_index, + &command->interface_etc.status); } - if (command->alternate.interface_index >= configurationInfo->interface_count) { - command->alternate.status = B_USB_RAW_STATUS_INVALID_INTERFACE; + if (interfaceInfo == NULL) return B_OK; - } - const usb_interface_list *interfaceList = - &configurationInfo->interface[command->alternate.interface_index]; - if (command->alternate.alternate_index >= interfaceList->alt_count) { - command->alternate.status = B_USB_RAW_STATUS_INVALID_INTERFACE; - return B_OK; - } - - memcpy(command->alternate.descriptor, - &interfaceList->alt[command->alternate.alternate_index], + memcpy(command->interface.descriptor, interfaceInfo->descr, sizeof(usb_interface_descriptor)); - command->alternate.status = B_USB_RAW_STATUS_SUCCESS; + command->interface.status = B_USB_RAW_STATUS_SUCCESS; return B_OK; } - case B_USB_RAW_COMMAND_GET_ENDPOINT_DESCRIPTOR: { - const usb_configuration_info *configurationInfo = - gUSBModule->get_nth_configuration(device->device, - command->endpoint.config_index); - if (!configurationInfo) { - command->endpoint.status = B_USB_RAW_STATUS_INVALID_CONFIGURATION; - return B_OK; + case B_USB_RAW_COMMAND_GET_ENDPOINT_DESCRIPTOR: + case B_USB_RAW_COMMAND_GET_ENDPOINT_DESCRIPTOR_ETC: { + uint32 endpointIndex = 0; + const usb_interface_info *interfaceInfo = NULL; + if (op == B_USB_RAW_COMMAND_GET_ENDPOINT_DESCRIPTOR) { + interfaceInfo = usb_raw_get_interface(device, + command->endpoint.config_index, + command->endpoint.interface_index, + B_USB_RAW_ACTIVE_ALTERNATE, + &command->endpoint.status); + endpointIndex = command->endpoint.endpoint_index; + } else { + interfaceInfo = usb_raw_get_interface(device, + command->endpoint_etc.config_index, + command->endpoint_etc.interface_index, + command->endpoint_etc.alternate_index, + &command->endpoint_etc.status); + endpointIndex = command->endpoint_etc.endpoint_index; } - if (command->endpoint.interface_index >= configurationInfo->interface_count) { - command->endpoint.status = B_USB_RAW_STATUS_INVALID_INTERFACE; + if (!interfaceInfo) return B_OK; - } - const usb_interface_info *interfaceInfo = - configurationInfo->interface[command->endpoint.interface_index].active; - if (!interfaceInfo) { - command->endpoint.status = B_USB_RAW_STATUS_ABORTED; - return B_OK; - } - - if (command->endpoint.endpoint_index >= interfaceInfo->endpoint_count) { + if (endpointIndex >= interfaceInfo->endpoint_count) { command->endpoint.status = B_USB_RAW_STATUS_INVALID_ENDPOINT; return B_OK; } memcpy(command->endpoint.descriptor, - interfaceInfo->endpoint[command->endpoint.endpoint_index].descr, + interfaceInfo->endpoint[endpointIndex].descr, sizeof(usb_endpoint_descriptor)); command->endpoint.status = B_USB_RAW_STATUS_SUCCESS; return B_OK; } - case B_USB_RAW_COMMAND_GET_GENERIC_DESCRIPTOR: { - const usb_configuration_info *configurationInfo = - gUSBModule->get_nth_configuration(device->device, - command->generic.config_index); - if (!configurationInfo) { - command->generic.status = B_USB_RAW_STATUS_INVALID_CONFIGURATION; - return B_OK; + case B_USB_RAW_COMMAND_GET_GENERIC_DESCRIPTOR: + case B_USB_RAW_COMMAND_GET_GENERIC_DESCRIPTOR_ETC: { + uint32 genericIndex = 0; + size_t genericLength = 0; + const usb_interface_info *interfaceInfo = NULL; + if (op == B_USB_RAW_COMMAND_GET_GENERIC_DESCRIPTOR) { + interfaceInfo = usb_raw_get_interface(device, + command->generic.config_index, + command->generic.interface_index, + B_USB_RAW_ACTIVE_ALTERNATE, + &command->generic.status); + genericIndex = command->generic.generic_index; + genericLength = command->generic.length; + } else { + interfaceInfo = usb_raw_get_interface(device, + command->generic_etc.config_index, + command->generic_etc.interface_index, + command->generic_etc.alternate_index, + &command->generic_etc.status); + genericIndex = command->generic_etc.generic_index; + genericLength = command->generic_etc.length; } - if (command->generic.interface_index >= configurationInfo->interface_count) { - command->generic.status = B_USB_RAW_STATUS_INVALID_INTERFACE; + if (!interfaceInfo) return B_OK; - } - const usb_interface_info *interfaceInfo = - configurationInfo->interface[command->generic.interface_index].active; - if (!interfaceInfo) { - command->generic.status = B_USB_RAW_STATUS_ABORTED; + if (genericIndex >= interfaceInfo->generic_count) { + command->endpoint.status = B_USB_RAW_STATUS_INVALID_ENDPOINT; return B_OK; } - if (command->generic.generic_index >= interfaceInfo->generic_count) { - // ToDo: add B_USB_RAW_STATUS_INVALID_GENERIC - command->generic.status = B_USB_RAW_STATUS_INVALID_ENDPOINT; + usb_descriptor *descriptor = interfaceInfo->generic[genericIndex]; + if (!descriptor) return B_OK; - } - usb_descriptor *descriptor = interfaceInfo->generic[command->generic.generic_index]; - if (!descriptor) { - command->generic.status = B_USB_RAW_STATUS_ABORTED; - return B_OK; - } + memcpy(command->generic.descriptor, descriptor, + min_c(genericLength, descriptor->generic.length)); - if (descriptor->generic.length > command->generic.length) { + if (descriptor->generic.length > genericLength) command->generic.status = B_USB_RAW_STATUS_NO_MEMORY; - return B_OK; - } - - memcpy(command->generic.descriptor, descriptor, - descriptor->generic.length); - command->generic.status = B_USB_RAW_STATUS_SUCCESS; + else + command->generic.status = B_USB_RAW_STATUS_SUCCESS; return B_OK; } @@ -485,12 +521,10 @@ case B_USB_RAW_COMMAND_SET_CONFIGURATION: { const usb_configuration_info *configurationInfo = - gUSBModule->get_nth_configuration(device->device, - command->config.config_index); - if (!configurationInfo) { - command->config.status = B_USB_RAW_STATUS_INVALID_CONFIGURATION; + usb_raw_get_configuration(device, command->config.config_index, + &command->config.status); + if (configurationInfo == NULL) return B_OK; - } if (gUSBModule->set_configuration(device->device, configurationInfo) < B_OK) { @@ -504,27 +538,27 @@ case B_USB_RAW_COMMAND_SET_ALT_INTERFACE: { const usb_configuration_info *configurationInfo = - gUSBModule->get_nth_configuration(device->device, - command->alternate.config_index); - if (!configurationInfo) { - command->alternate.status = B_USB_RAW_STATUS_INVALID_CONFIGURATION; + usb_raw_get_configuration(device, + command->alternate.config_index, + &command->alternate.status); + if (configurationInfo == NULL) return B_OK; - } - if (command->alternate.interface_index >= configurationInfo->interface_count) { + if (command->alternate.interface_index + >= configurationInfo->interface_count) { command->alternate.status = B_USB_RAW_STATUS_INVALID_INTERFACE; return B_OK; } const usb_interface_list *interfaceList = &configurationInfo->interface[command->alternate.interface_index]; - if (command->alternate.alternate_index >= interfaceList->alt_count) { + if (command->alternate.alternate_info >= interfaceList->alt_count) { command->alternate.status = B_USB_RAW_STATUS_INVALID_INTERFACE; return B_OK; } if (gUSBModule->set_alt_interface(device->device, - &interfaceList->alt[command->alternate.alternate_index]) < B_OK) { + &interfaceList->alt[command->alternate.alternate_info]) < B_OK) { command->alternate.status = B_USB_RAW_STATUS_FAILED; return B_OK; } Modified: haiku/trunk/src/add-ons/kernel/drivers/bus/usb/usb_raw.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/bus/usb/usb_raw.h 2008-09-10 21:49:40 UTC (rev 27408) +++ haiku/trunk/src/add-ons/kernel/drivers/bus/usb/usb_raw.h 2008-09-10 21:52:32 UTC (rev 27409) @@ -9,6 +9,7 @@ #include #define B_USB_RAW_PROTOCOL_VERSION 0x0015 +#define B_USB_RAW_ACTIVE_ALTERNATE 0xffffffff typedef enum { B_USB_RAW_COMMAND_GET_VERSION = 0x1000, @@ -20,7 +21,10 @@ B_USB_RAW_COMMAND_GET_STRING_DESCRIPTOR, B_USB_RAW_COMMAND_GET_GENERIC_DESCRIPTOR, B_USB_RAW_COMMAND_GET_ALT_INTERFACE_COUNT, - B_USB_RAW_COMMAND_GET_ALT_INTERFACE_DESCRIPTOR, + B_USB_RAW_COMMAND_GET_ACTIVE_ALT_INTERFACE_INDEX, + B_USB_RAW_COMMAND_GET_INTERFACE_DESCRIPTOR_ETC, + B_USB_RAW_COMMAND_GET_ENDPOINT_DESCRIPTOR_ETC, + B_USB_RAW_COMMAND_GET_GENERIC_DESCRIPTOR_ETC, B_USB_RAW_COMMAND_SET_CONFIGURATION = 0x3000, B_USB_RAW_COMMAND_SET_FEATURE, @@ -72,6 +76,13 @@ struct { status_t status; + uint32 alternate_info; + uint32 config_index; + uint32 interface_index; + } alternate; + + struct { + status_t status; usb_interface_descriptor *descriptor; uint32 config_index; uint32 interface_index; @@ -79,12 +90,11 @@ struct { status_t status; - uint32 *alternate_count; usb_interface_descriptor *descriptor; uint32 config_index; uint32 interface_index; uint32 alternate_index; - } alternate; + } interface_etc; struct { status_t status; @@ -96,10 +106,12 @@ struct { status_t status; - usb_string_descriptor *descriptor; - uint32 string_index; - size_t length; - } string; + usb_endpoint_descriptor *descriptor; + uint32 config_index; + uint32 interface_index; + uint32 alternate_index; + uint32 endpoint_index; + } endpoint_etc; struct { status_t status; @@ -112,6 +124,23 @@ struct { status_t status; + usb_descriptor *descriptor; + uint32 config_index; + uint32 interface_index; + uint32 alternate_index; + uint32 generic_index; + size_t length; + } generic_etc; + + struct { + status_t status; + usb_string_descriptor *descriptor; + uint32 string_index; + size_t length; + } string; + + struct { + status_t status; uint8 type; uint8 index; uint16 language_id; Modified: haiku/trunk/src/kits/device/USBConfiguration.cpp =================================================================== --- haiku/trunk/src/kits/device/USBConfiguration.cpp 2008-09-10 21:49:40 UTC (rev 27408) +++ haiku/trunk/src/kits/device/USBConfiguration.cpp 2008-09-10 21:52:32 UTC (rev 27409) @@ -1,5 +1,5 @@ /* - * Copyright 2007, Haiku Inc. All rights reserved. + * Copyright 2007-2008, Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -10,6 +10,7 @@ #include #include #include +#include BUSBConfiguration::BUSBConfiguration(BUSBDevice *device, uint32 index, int rawFD) @@ -26,18 +27,26 @@ sizeof(command)) || command.config.status != B_USB_RAW_STATUS_SUCCESS) memset(&fDescriptor, 0, sizeof(fDescriptor)); - fInterfaces = new BUSBInterface *[fDescriptor.number_interfaces]; - for (uint32 i = 0; i < fDescriptor.number_interfaces; i++) - fInterfaces[i] = new BUSBInterface(this, i, fRawFD); + fInterfaces = new(std::nothrow) BUSBInterface *[ + fDescriptor.number_interfaces]; + if (fInterfaces == NULL) + return; + + for (uint32 i = 0; i < fDescriptor.number_interfaces; i++) { + fInterfaces[i] = new(std::nothrow) BUSBInterface(this, i, + B_USB_RAW_ACTIVE_ALTERNATE, fRawFD); + } } BUSBConfiguration::~BUSBConfiguration() { delete[] fConfigurationString; - for (int32 i = 0; i < fDescriptor.number_interfaces; i++) - delete fInterfaces[i]; - delete[] fInterfaces; + if (fInterfaces != NULL) { + for (int32 i = 0; i < fDescriptor.number_interfaces; i++) + delete fInterfaces[i]; + delete[] fInterfaces; + } } @@ -64,11 +73,10 @@ if (fConfigurationString) return fConfigurationString; - fConfigurationString = Device()->DecodeStringDescriptor(fDescriptor.configuration); - if (!fConfigurationString) { - fConfigurationString = new char[1]; - fConfigurationString[0] = 0; - } + fConfigurationString = Device()->DecodeStringDescriptor( + fDescriptor.configuration); + if (fConfigurationString == NULL) + return ""; return fConfigurationString; } @@ -91,7 +99,7 @@ const BUSBInterface * BUSBConfiguration::InterfaceAt(uint32 index) const { - if (index >= fDescriptor.number_interfaces) + if (index >= fDescriptor.number_interfaces || fInterfaces == NULL) return NULL; return fInterfaces[index]; Modified: haiku/trunk/src/kits/device/USBDevice.cpp =================================================================== --- haiku/trunk/src/kits/device/USBDevice.cpp 2008-09-10 21:49:40 UTC (rev 27408) +++ haiku/trunk/src/kits/device/USBDevice.cpp 2008-09-10 21:52:32 UTC (rev 27409) @@ -1,5 +1,5 @@ /* - * Copyright 2007, Haiku Inc. All rights reserved. + * Copyright 2007-2008, Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -8,9 +8,10 @@ #include #include +#include #include #include -#include +#include BUSBDevice::BUSBDevice(const char *path) @@ -69,10 +70,16 @@ return B_ERROR; } - fConfigurations = new BUSBConfiguration *[fDescriptor.num_configurations]; - for (uint32 i = 0; i < fDescriptor.num_configurations; i++) - fConfigurations[i] = new BUSBConfiguration(this, i, fRawFD); + fConfigurations = new(std::nothrow) BUSBConfiguration *[ + fDescriptor.num_configurations]; + if (fConfigurations == NULL) + return B_NO_MEMORY; + for (uint32 i = 0; i < fDescriptor.num_configurations; i++) { + fConfigurations[i] = new(std::nothrow) BUSBConfiguration(this, i, + fRawFD); + } + return B_OK; } @@ -92,10 +99,14 @@ delete[] fSerialNumberString; fManufacturerString = fProductString = fSerialNumberString = NULL; - for (int32 i = 0; i < fDescriptor.num_configurations; i++) - delete fConfigurations[i]; + if (fConfigurations != NULL) { + for (int32 i = 0; i < fDescriptor.num_configurations; i++) + delete fConfigurations[i]; - delete[] fConfigurations; + delete[] fConfigurations; + fConfigurations = NULL; + } + memset(&fDescriptor, 0, sizeof(fDescriptor)); } @@ -183,10 +194,8 @@ return fManufacturerString; fManufacturerString = DecodeStringDescriptor(fDescriptor.manufacturer); - if (!fManufacturerString) { - fManufacturerString = new char[1]; - fManufacturerString[0] = 0; - } + if (fManufacturerString == NULL) + return ""; return fManufacturerString; } @@ -202,10 +211,8 @@ return fProductString; fProductString = DecodeStringDescriptor(fDescriptor.product); - if (!fProductString) { - fProductString = new char[1]; - fProductString[0] = 0; - } + if (fProductString == NULL) + return ""; return fProductString; } @@ -221,10 +228,8 @@ return fSerialNumberString; fSerialNumberString = DecodeStringDescriptor(fDescriptor.serial_number); - if (!fSerialNumberString) { - fSerialNumberString = new char[1]; - fSerialNumberString[0] = 0; - } + if (fSerialNumberString == NULL) + return ""; return fSerialNumberString; } @@ -272,7 +277,10 @@ // pseudo convert unicode string stringLength = (stringLength - 2) / 2; - char *result = new char[stringLength + 1]; + char *result = new(std::nothrow) char[stringLength + 1]; + if (result == NULL) + return NULL; + for (size_t i = 0; i < stringLength; i++) result[i] = stringDescriptor->string[i * 2]; result[stringLength] = 0; @@ -312,7 +320,7 @@ const BUSBConfiguration * BUSBDevice::ConfigurationAt(uint32 index) const { - if (index >= fDescriptor.num_configurations) + if (index >= fDescriptor.num_configurations && fConfigurations != NULL) return NULL; return fConfigurations[index]; @@ -322,6 +330,9 @@ const BUSBConfiguration * BUSBDevice::ActiveConfiguration() const { + if (fConfigurations == NULL) + return NULL; + return fConfigurations[fActiveConfiguration]; } Modified: haiku/trunk/src/kits/device/USBEndpoint.cpp =================================================================== --- haiku/trunk/src/kits/device/USBEndpoint.cpp 2008-09-10 21:49:40 UTC (rev 27408) +++ haiku/trunk/src/kits/device/USBEndpoint.cpp 2008-09-10 21:52:32 UTC (rev 27409) @@ -1,5 +1,5 @@ /* - * Copyright 2007, Haiku Inc. All rights reserved. + * Copyright 2007-2008, Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -18,11 +18,12 @@ fRawFD(rawFD) { usb_raw_command command; - command.endpoint.descriptor = &fDescriptor; - command.endpoint.config_index = fInterface->Configuration()->Index(); - command.endpoint.interface_index = fInterface->Index(); [... truncated: 407 lines follow ...] From mmlr at mail.berlios.de Thu Sep 11 00:14:02 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Thu, 11 Sep 2008 00:14:02 +0200 Subject: [Haiku-commits] r27410 - haiku/trunk/src/bin Message-ID: <200809102214.m8AME2va008536@sheep.berlios.de> Author: mmlr Date: 2008-09-11 00:14:00 +0200 (Thu, 11 Sep 2008) New Revision: 27410 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27410&view=rev Modified: haiku/trunk/src/bin/usb_dev_info.cpp Log: * Add alternate interface printing to usb_dev_info, which is now pretty straight forward using the new USBKit interface. * Make the output indents a bit more natural and wider to make things more readable. * Minor cleanup. Modified: haiku/trunk/src/bin/usb_dev_info.cpp =================================================================== --- haiku/trunk/src/bin/usb_dev_info.cpp 2008-09-10 21:52:32 UTC (rev 27409) +++ haiku/trunk/src/bin/usb_dev_info.cpp 2008-09-10 22:14:00 UTC (rev 27410) @@ -3,7 +3,7 @@ * Copyright 2000, Be Incorporated. All rights reserved. * * Modified for Haiku by Fran?ois Revol and Michael Lotz. - * Copyright 2007, Haiku Inc. All rights reserved. + * Copyright 2007-2008, Haiku Inc. All rights reserved. */ #include @@ -16,41 +16,48 @@ if (!interface) return; - printf(" Class .............. 0x%02x\n", interface->Class()); - printf(" Subclass ........... 0x%02x\n", interface->Subclass()); - printf(" Protocol ........... 0x%02x\n", interface->Protocol()); - printf(" Interface String ... \"%s\"\n", interface->InterfaceString()); + printf(" Class .............. 0x%02x\n", + interface->Class()); + printf(" Subclass ........... 0x%02x\n", + interface->Subclass()); + printf(" Protocol ........... 0x%02x\n", + interface->Protocol()); + printf(" Interface String ... \"%s\"\n", + interface->InterfaceString()); for (uint32 i = 0; i < interface->CountEndpoints(); i++) { const BUSBEndpoint *endpoint = interface->EndpointAt(i); if (!endpoint) continue; - printf(" [Endpoint %lu]\n", i); - printf(" MaxPacketSize .... %d\n", endpoint->MaxPacketSize()); - printf(" Interval ......... %d\n", endpoint->Interval()); + printf(" [Endpoint %lu]\n", i); + printf(" MaxPacketSize .... %d\n", + endpoint->MaxPacketSize()); + printf(" Interval ......... %d\n", + endpoint->Interval()); if (endpoint->IsControl()) - printf(" Type ............. Control\n"); + printf(" Type ............. Control\n"); else if (endpoint->IsBulk()) - printf(" Type ............. Bulk\n"); + printf(" Type ............. Bulk\n"); else if (endpoint->IsIsochronous()) - printf(" Type ............. Isochronous\n"); + printf(" Type ............. Isochronous\n"); else if (endpoint->IsInterrupt()) - printf(" Type ............. Interrupt\n"); + printf(" Type ............. Interrupt\n"); if(endpoint->IsInput()) - printf(" Direction ........ Input\n"); + printf(" Direction ........ Input\n"); else - printf(" Direction ........ Output\n"); + printf(" Direction ........ Output\n"); } char buffer[256]; usb_descriptor *generic = (usb_descriptor *)buffer; for (uint32 i = 0; interface->OtherDescriptorAt(i, generic, 256) == B_OK; i++) { - printf(" [Descriptor %lu]\n", i); - printf(" Type ............. 0x%02x\n", generic->generic.descriptor_type); - printf(" Data ............. "); + printf(" [Descriptor %lu]\n", i); + printf(" Type ............. 0x%02x\n", + generic->generic.descriptor_type); + printf(" Data ............. "); // the length includes the length and descriptor_type field for(int32 j = 0; j < generic->generic.length - 2; j++) printf("%02x ", generic->generic.data[j]); @@ -65,10 +72,18 @@ if (!configuration) return; - printf(" Configuration String . \"%s\"\n", configuration->ConfigurationString()); + printf(" Configuration String . \"%s\"\n", + configuration->ConfigurationString()); for (uint32 i = 0; i < configuration->CountInterfaces(); i++) { - printf(" [Interface %lu]\n", i); - DumpInterface(configuration->InterfaceAt(i)); + printf(" [Interface %lu]\n", i); + const BUSBInterface *interface = configuration->InterfaceAt(i); + + for (uint32 j = 0; j < interface->CountAlternates(); j++) { + const BUSBInterface *alternate = interface->AlternateAt(j); + printf(" [Alternate %lu%s]\n", j, + j == interface->AlternateIndex() ? " active" : ""); + DumpInterface(alternate); + } } } @@ -77,20 +92,20 @@ DumpInfo(BUSBDevice &device) { printf("[Device]\n"); - printf("Class .................. 0x%02x\n", device.Class()); - printf("Subclass ............... 0x%02x\n", device.Subclass()); - printf("Protocol ............... 0x%02x\n", device.Protocol()); - printf("Max Endpoint 0 Packet .. %d\n", device.MaxEndpoint0PacketSize()); - printf("USB Version ............ 0x%04x\n", device.USBVersion()); - printf("Vendor ID .............. 0x%04x\n", device.VendorID()); - printf("Product ID ............. 0x%04x\n", device.ProductID()); - printf("Product Version ........ 0x%04x\n", device.Version()); - printf("Manufacturer String .... \"%s\"\n", device.ManufacturerString()); - printf("Product String ......... \"%s\"\n", device.ProductString()); - printf("Serial Number .......... \"%s\"\n", device.SerialNumberString()); + printf(" Class .................. 0x%02x\n", device.Class()); + printf(" Subclass ............... 0x%02x\n", device.Subclass()); + printf(" Protocol ............... 0x%02x\n", device.Protocol()); + printf(" Max Endpoint 0 Packet .. %d\n", device.MaxEndpoint0PacketSize()); + printf(" USB Version ............ 0x%04x\n", device.USBVersion()); + printf(" Vendor ID .............. 0x%04x\n", device.VendorID()); + printf(" Product ID ............. 0x%04x\n", device.ProductID()); + printf(" Product Version ........ 0x%04x\n", device.Version()); + printf(" Manufacturer String .... \"%s\"\n", device.ManufacturerString()); + printf(" Product String ......... \"%s\"\n", device.ProductString()); + printf(" Serial Number .......... \"%s\"\n", device.SerialNumberString()); for (uint32 i = 0; i < device.CountConfigurations(); i++) { - printf(" [Configuration %lu]\n", i); + printf(" [Configuration %lu]\n", i); DumpConfiguration(device.ConfigurationAt(i)); } } From jackburton at mail.berlios.de Thu Sep 11 09:24:42 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Thu, 11 Sep 2008 09:24:42 +0200 Subject: [Haiku-commits] r27411 - haiku/trunk/src/system/kernel/arch/x86 Message-ID: <200809110724.m8B7Og97014534@sheep.berlios.de> Author: jackburton Date: 2008-09-11 09:24:40 +0200 (Thu, 11 Sep 2008) New Revision: 27411 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27411&view=rev Modified: haiku/trunk/src/system/kernel/arch/x86/arch_cpu.cpp Log: fix gcc4 build Modified: haiku/trunk/src/system/kernel/arch/x86/arch_cpu.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/arch_cpu.cpp 2008-09-10 22:14:00 UTC (rev 27410) +++ haiku/trunk/src/system/kernel/arch/x86/arch_cpu.cpp 2008-09-11 07:24:40 UTC (rev 27411) @@ -600,7 +600,7 @@ } // put the optimized functions into the commpage - fill_commpage_entry(COMMPAGE_ENTRY_X86_MEMCPY, gOptimizedFunctions.memcpy, + fill_commpage_entry(COMMPAGE_ENTRY_X86_MEMCPY, (const void *)gOptimizedFunctions.memcpy, (addr_t)gOptimizedFunctions.memcpy_end - (addr_t)gOptimizedFunctions.memcpy); From jackburton at mail.berlios.de Thu Sep 11 09:57:10 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Thu, 11 Sep 2008 09:57:10 +0200 Subject: [Haiku-commits] r27412 - haiku/trunk/src/system/kernel/arch/x86/timers Message-ID: <200809110757.m8B7vAbf019072@sheep.berlios.de> Author: jackburton Date: 2008-09-11 09:57:08 +0200 (Thu, 11 Sep 2008) New Revision: 27412 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27412&view=rev Modified: haiku/trunk/src/system/kernel/arch/x86/timers/x86_hpet.c Log: fixed gcc4 warnings Modified: haiku/trunk/src/system/kernel/arch/x86/timers/x86_hpet.c =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/timers/x86_hpet.c 2008-09-11 07:24:40 UTC (rev 27411) +++ haiku/trunk/src/system/kernel/arch/x86/timers/x86_hpet.c 2008-09-11 07:57:08 UTC (rev 27412) @@ -41,7 +41,7 @@ static int32 -hpet_timer_interrupt(struct hpet_timer *timer) +hpet_timer_interrupt(void *arg) { return timer_interrupt(); } @@ -141,7 +141,7 @@ } } - TRACE(("hpet_init: HPET is at %x. Vendor ID: %x.\n", sHPETRegs, HPET_GET_VENDOR_ID(sHPETRegs))); + TRACE(("hpet_init: HPET is at %p. Vendor ID: %lx.\n", sHPETRegs, HPET_GET_VENDOR_ID(sHPETRegs))); /* There is no hpet legacy support, so error out on init */ if (!HPET_IS_LEGACY_CAPABLE(sHPETRegs)) { @@ -151,7 +151,7 @@ hpet_set_legacy(sHPETRegs, true); TRACE(("hpet_init: HPET does%s support legacy mode.\n", HPET_IS_LEGACY_CAPABLE(sHPETRegs) ? "" : " not")); - TRACE(("hpet_init: HPET supports %d timers, and is %s bits wide.\n", HPET_GET_NUM_TIMERS(sHPETRegs) + 1, HPET_IS_64BIT(sHPETRegs) ? "64" : "32")); + TRACE(("hpet_init: HPET supports %lu timers, and is %s bits wide.\n", HPET_GET_NUM_TIMERS(sHPETRegs) + 1, HPET_IS_64BIT(sHPETRegs) ? "64" : "32")); if (HPET_GET_NUM_TIMERS(sHPETRegs) < 2) { dprintf("hpet_init: HPET does not have at least 3 timers. Skipping.\n"); From jackburton at mail.berlios.de Thu Sep 11 14:02:36 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Thu, 11 Sep 2008 14:02:36 +0200 Subject: [Haiku-commits] r27413 - haiku/trunk/src/kits/app Message-ID: <200809111202.m8BC2aNb004105@sheep.berlios.de> Author: jackburton Date: 2008-09-11 14:02:33 +0200 (Thu, 11 Sep 2008) New Revision: 27413 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27413&view=rev Modified: haiku/trunk/src/kits/app/Application.cpp Log: be_app could be NULL in BApplication's destructor, if the BApplication didn't initialize itself fully on construction. This fixes a crash when launching some already running application (i.e. print_server) Modified: haiku/trunk/src/kits/app/Application.cpp =================================================================== --- haiku/trunk/src/kits/app/Application.cpp 2008-09-11 07:57:08 UTC (rev 27412) +++ haiku/trunk/src/kits/app/Application.cpp 2008-09-11 12:02:33 UTC (rev 27413) @@ -233,10 +233,14 @@ #ifndef RUN_WITHOUT_APP_SERVER // tell app_server we're quitting... - BPrivate::AppServerLink link; - link.StartMessage(B_QUIT_REQUESTED); - link.Flush(); - + if (be_app) { + // be_app can be NULL here if the application fails to initialize + // correctly. For example, if it's already running and it's set to + // exclusive launch. + BPrivate::AppServerLink link; + link.StartMessage(B_QUIT_REQUESTED); + link.Flush(); + } delete_port(fServerLink->SenderPort()); delete_port(fServerLink->ReceiverPort()); delete fServerLink; From axeld at mail.berlios.de Thu Sep 11 14:25:05 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 11 Sep 2008 14:25:05 +0200 Subject: [Haiku-commits] r27414 - in haiku/trunk/src: kits/storage system/libroot/posix/sys Message-ID: <200809111225.m8BCP5X9006202@sheep.berlios.de> Author: axeld Date: 2008-09-11 14:25:05 +0200 (Thu, 11 Sep 2008) New Revision: 27414 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27414&view=rev Modified: haiku/trunk/src/kits/storage/Directory.cpp haiku/trunk/src/system/libroot/posix/sys/mkdir.c Log: * BDirectory::CreateDirectory() and CreateSymlink() now both use __gUmask to correct the permission mask. This fixes bug #2670. * Minor cleanup. Modified: haiku/trunk/src/kits/storage/Directory.cpp =================================================================== --- haiku/trunk/src/kits/storage/Directory.cpp 2008-09-11 12:02:33 UTC (rev 27413) +++ haiku/trunk/src/kits/storage/Directory.cpp 2008-09-11 12:25:05 UTC (rev 27414) @@ -24,7 +24,10 @@ #include -// constructor +extern mode_t __gUmask; + // declared in sys/umask.c + + //! Creates an uninitialized BDirectory object. BDirectory::BDirectory() : @@ -32,9 +35,9 @@ { } -// copy constructor -//! Creates a copy of the supplied BDirectory. -/*! \param dir the BDirectory object to be copied + +/*! \brief Creates a copy of the supplied BDirectory. + \param dir the BDirectory object to be copied */ BDirectory::BDirectory(const BDirectory &dir) : @@ -43,7 +46,7 @@ *this = dir; } -// constructor + /*! \brief Creates a BDirectory and initializes it to the directory referred to by the supplied entry_ref. \param ref the entry_ref referring to the directory @@ -55,7 +58,7 @@ SetTo(ref); } -// constructor + /*! \brief Creates a BDirectory and initializes it to the directory referred to by the supplied node_ref. \param nref the node_ref referring to the directory @@ -67,7 +70,7 @@ SetTo(nref); } -// constructor + /*! \brief Creates a BDirectory and initializes it to the directory referred to by the supplied BEntry. \param entry the BEntry referring to the directory @@ -79,7 +82,7 @@ SetTo(entry); } -// constructor + /*! \brief Creates a BDirectory and initializes it to the directory referred to by the supplied path name. \param path the directory's path name @@ -91,7 +94,7 @@ SetTo(path); } -// constructor + /*! \brief Creates a BDirectory and initializes it to the directory referred to by the supplied path name relative to the specified BDirectory. \param dir the BDirectory, relative to which the directory's path name is @@ -105,8 +108,7 @@ SetTo(dir, path); } -// destructor -//! Frees all allocated resources. + /*! If the BDirectory is properly initialized, the directory's file descriptor is closed. */ @@ -120,7 +122,7 @@ close_fd(); } -// SetTo + /*! \brief Re-initializes the BDirectory to the directory referred to by the supplied entry_ref. \param ref the entry_ref referring to the directory @@ -157,7 +159,7 @@ return B_OK; } -// SetTo + /*! \brief Re-initializes the BDirectory to the directory referred to by the supplied node_ref. \param nref the node_ref referring to the directory @@ -185,7 +187,7 @@ return error; } -// SetTo + /*! \brief Re-initializes the BDirectory to the directory referred to by the supplied BEntry. \param entry the BEntry referring to the directory @@ -227,7 +229,7 @@ return B_OK; } -// SetTo + /*! \brief Re-initializes the BDirectory to the directory referred to by the supplied path name. \param path the directory's path name @@ -266,7 +268,7 @@ return B_OK; } -// SetTo + /*! \brief Re-initializes the BDirectory to the directory referred to by the supplied path name relative to the specified BDirectory. \param dir the BDirectory, relative to which the directory's path name is @@ -323,9 +325,9 @@ return B_OK; } -// GetEntry -//! Returns a BEntry referring to the directory represented by this object. -/*! If the initialization of \a entry fails, it is Unset(). + +/*! \brief Returns a BEntry referring to the directory represented by this object. + If the initialization of \a entry fails, it is Unset(). \param entry a pointer to the entry that shall be set to refer to the directory \return @@ -349,7 +351,7 @@ return entry->SetTo(this, ".", false); } -// IsRootDirectory + /*! \brief Returns whether the directory represented by this BDirectory is a root directory of a volume. \return @@ -369,7 +371,7 @@ return result; } -// FindEntry + /*! \brief Finds an entry referred to by a path relative to the directory represented by this BDirectory. \a path may be absolute. If the BDirectory is not properly initialized, @@ -418,7 +420,7 @@ return error; } -// Contains + /*! \brief Returns whether this directory or any of its subdirectories at any level contain the entry referred to by the supplied path name. Only entries that match the node flavor specified by \a nodeFlags are @@ -463,7 +465,7 @@ return Contains(&entry, nodeFlags); } -// Contains + /*! \brief Returns whether this directory or any of its subdirectories at any level contain the entry referred to by the supplied BEntry. Only entries that match the node flavor specified by \a nodeFlags are @@ -510,7 +512,6 @@ } -// GetStatFor /*! \brief Returns the stat structure of the entry referred to by the supplied path name. \param path the entry's path name. May be relative to this directory or @@ -536,19 +537,18 @@ return B_BAD_VALUE; if (InitCheck() != B_OK) return B_NO_INIT; - status_t error = B_OK; - if (path) { - if (strlen(path) == 0) + + if (path != NULL) { + if (path[0] == '\0') return B_ENTRY_NOT_FOUND; - error = _kern_read_stat(fDirFd, path, false, st, sizeof(struct stat)); - } else - error = GetStat(st); - return error; + return _kern_read_stat(fDirFd, path, false, st, sizeof(struct stat)); + } + return GetStat(st); } -// GetNextEntry -//! Returns the BDirectory's next entry as a BEntry. -/*! Unlike GetNextDirents() this method ignores the entries "." and "..". + +/*! \brief Returns the BDirectory's next entry as a BEntry. + Unlike GetNextDirents() this method ignores the entries "." and "..". \param entry a pointer to a BEntry to be initialized to the found entry \param traverse specifies whether to follow it, if the found entry is a symbolic link. @@ -578,9 +578,9 @@ return error; } -// GetNextRef -//! Returns the BDirectory's next entry as an entry_ref. -/*! Unlike GetNextDirents() this method ignores the entries "." and "..". + +/*! \brief Returns the BDirectory's next entry as an entry_ref. + Unlike GetNextDirents() this method ignores the entries "." and "..". \param ref a pointer to an entry_ref to be filled in with the data of the found entry \param traverse specifies whether to follow it, if the found entry @@ -612,7 +612,7 @@ error = B_ENTRY_NOT_FOUND; } else { next = (!strcmp(entry.d_name, ".") - || !strcmp(entry.d_name, "..")); + || !strcmp(entry.d_name, "..")); } } if (error == B_OK) { @@ -624,9 +624,9 @@ return error; } -// GetNextDirents -//! Returns the BDirectory's next entries as dirent structures. -/*! Unlike GetNextEntry() and GetNextRef(), this method returns also + +/*! \brief Returns the BDirectory's next entries as dirent structures. + Unlike GetNextEntry() and GetNextRef(), this method returns also the entries "." and "..". \param buf a pointer to a buffer to be filled with dirent structures of the found entries @@ -655,9 +655,9 @@ return _kern_read_dir(fDirFd, buf, bufSize, count); } -// Rewind -//! Rewinds the directory iterator. -/*! \return + +/*! \brief Rewinds the directory iterator. + \return - \c B_OK: Everything went fine. - \c B_PERMISSION_DENIED: Directory permissions didn't allow operation. - \c B_NO_MEMORY: Insufficient memory for operation. @@ -675,9 +675,9 @@ return _kern_rewind_dir(fDirFd); } -// CountEntries -//! Returns the number of entries in this directory. -/*! CountEntries() uses the directory iterator also used by GetNextEntry(), + +/*! \brief Returns the number of entries in this directory. + CountEntries() uses the directory iterator also used by GetNextEntry(), GetNextRef() and GetNextDirents(). It does a Rewind(), iterates through the entries and Rewind()s again. The entries "." and ".." are not counted. \return @@ -708,9 +708,9 @@ return (error == B_OK ? count : error); } -// CreateDirectory -//! Creates a new directory. -/*! If an entry with the supplied name does already exist, the method fails. + +/*! \brief Creates a new directory. + If an entry with the supplied name does already exist, the method fails. \param path the new directory's path name. May be relative to this directory or absolute. \param dir a pointer to a BDirectory to be initialized to the newly @@ -732,23 +732,26 @@ { if (!path) return B_BAD_VALUE; + // create the dir status_t error = _kern_create_dir(fDirFd, path, - S_IRWXU | S_IRWXG | S_IRWXO); + (S_IRWXU | S_IRWXG | S_IRWXO) & ~__gUmask); if (error != B_OK) return error; - if (!dir) + + if (dir == NULL) return B_OK; + // init the supplied BDirectory if (InitCheck() != B_OK || BPrivate::Storage::is_absolute_path(path)) return dir->SetTo(path); - else - return dir->SetTo(this, path); + + return dir->SetTo(this, path); } -// CreateFile -//! Creates a new file. -/*! If a file with the supplied name does already exist, the method fails, + +/*! \brief Creates a new file. + If a file with the supplied name does already exist, the method fails, unless it is passed \c false to \a failIfExists -- in that case the file is truncated to zero size. The new BFile will operate in \c B_READ_WRITE mode. @@ -782,7 +785,7 @@ uint32 openMode = B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE | (failIfExists ? B_FAIL_IF_EXISTS : 0); BFile tmpFile; - BFile *realFile = (file ? file : &tmpFile); + BFile *realFile = file ? file : &tmpFile; status_t error = B_OK; if (InitCheck() == B_OK && !BPrivate::Storage::is_absolute_path(path)) error = realFile->SetTo(this, path, openMode); @@ -793,9 +796,9 @@ return error; } -// CreateSymLink -//! Creates a new symbolic link. -/*! If an entry with the supplied name does already exist, the method fails. + +/*! \brief Creates a new symbolic link. + If an entry with the supplied name does already exist, the method fails. \param path the new symbolic link's path name. May be relative to this directory or absolute. \param linkToPath the path the symbolic link shall point to. @@ -815,27 +818,30 @@ */ status_t BDirectory::CreateSymLink(const char *path, const char *linkToPath, - BSymLink *link) + BSymLink *link) { if (!path || !linkToPath) return B_BAD_VALUE; + // create the symlink status_t error = _kern_create_symlink(fDirFd, path, linkToPath, - S_IRWXU | S_IRWXG | S_IRWXO); + (S_IRWXU | S_IRWXG | S_IRWXO) & ~__gUmask); if (error != B_OK) return error; - if (!link) + + if (link == NULL) return B_OK; + // init the supplied BSymLink if (InitCheck() != B_OK || BPrivate::Storage::is_absolute_path(path)) return link->SetTo(path); - else - return link->SetTo(this, path); + + return link->SetTo(this, path); } -// = -//! Assigns another BDirectory to this BDirectory. -/*! If the other BDirectory is uninitialized, this one wi'll be too. Otherwise + +/*! \brief Assigns another BDirectory to this BDirectory. + If the other BDirectory is uninitialized, this one wi'll be too. Otherwise it will refer to the same directory, unless an error occurs. \param dir the original BDirectory \return a reference to this BDirectory @@ -860,7 +866,7 @@ void BDirectory::_ErectorDirectory5() {} void BDirectory::_ErectorDirectory6() {} -// close_fd + //! Closes the BDirectory's file descriptor. void BDirectory::close_fd() @@ -872,8 +878,9 @@ BNode::close_fd(); } -//! Returns the BDirectory's file descriptor. -/*! To be used instead of accessing the BDirectory's private \c fDirFd member + +/*! \brief Returns the BDirectory's file descriptor. + To be used instead of accessing the BDirectory's private \c fDirFd member directly. \return the file descriptor, or -1, if not properly initialized. */ @@ -884,11 +891,11 @@ } -// C functions +// #pragma mark - C functions -// create_directory -//! Creates all missing directories along a given path. -/*! \param path the directory path name. + +/*! \brief Creates all missing directories along a given path. + \param path the directory path name. \param mode a permission specification, which shall be used for the newly created directories. \return Modified: haiku/trunk/src/system/libroot/posix/sys/mkdir.c =================================================================== --- haiku/trunk/src/system/libroot/posix/sys/mkdir.c 2008-09-11 12:02:33 UTC (rev 27413) +++ haiku/trunk/src/system/libroot/posix/sys/mkdir.c 2008-09-11 12:25:05 UTC (rev 27414) @@ -1,5 +1,5 @@ -/* - * Copyright 2002-2008, Axel D?rfler, axeld at pinc-software.de. All rights reserved. +/* + * Copyright 2002-2008, Axel D?rfler, axeld at pinc-software.de. * Distributed under the terms of the MIT License. */ From revol at free.fr Thu Sep 11 14:40:09 2008 From: revol at free.fr (=?windows-1252?q?Fran=E7ois?= Revol) Date: Thu, 11 Sep 2008 14:40:09 +0200 CEST Subject: [Haiku-commits] =?windows-1252?q?r27414_-_in_haiku/trunk/src=3A_k?= =?windows-1252?q?its/storage_system/libroot/posix/sys?= In-Reply-To: <200809111225.m8BCP5X9006202@sheep.berlios.de> Message-ID: <1976021422-BeMail@laptop> > Log: > * BDirectory::CreateDirectory() and CreateSymlink() now both use > __gUmask to > correct the permission mask. This fixes bug #2670. > * Minor cleanup. Btw, is umask inherited on exec() ? Seems it's copied on fork() as it's just a global, but it should also be inherited on exec(), and I suppose load_image() as well. Fran?ois. From sbenedetto at mail.berlios.de Thu Sep 11 16:42:13 2008 From: sbenedetto at mail.berlios.de (sbenedetto at BerliOS) Date: Thu, 11 Sep 2008 16:42:13 +0200 Subject: [Haiku-commits] r27415 - haiku/trunk/src/system/kernel/posix Message-ID: <200809111442.m8BEgD4u020360@sheep.berlios.de> Author: sbenedetto Date: 2008-09-11 16:42:13 +0200 (Thu, 11 Sep 2008) New Revision: 27415 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27415&view=rev Modified: haiku/trunk/src/system/kernel/posix/xsi_message_queue.cpp Log: * If the receving buffer if bigger than the message, truncate the length copied to the one of the message * Fix comparison * Clean up Modified: haiku/trunk/src/system/kernel/posix/xsi_message_queue.cpp =================================================================== --- haiku/trunk/src/system/kernel/posix/xsi_message_queue.cpp 2008-09-11 12:25:05 UTC (rev 27414) +++ haiku/trunk/src/system/kernel/posix/xsi_message_queue.cpp 2008-09-11 14:42:13 UTC (rev 27415) @@ -78,6 +78,9 @@ status_t copy_to_user_buffer(void *_message, ssize_t _length) { + if (_length > length) + _length = length; + if (user_memcpy(_message, &type, sizeof(long)) != B_OK || user_memcpy((void *)((char *)_message + sizeof(long)), message, _length) != B_OK) @@ -788,7 +791,7 @@ return ENOMSG; } else { // Message received correctly (so far) - if ((ssize_t)messageSize > message->length + if ((ssize_t)messageSize < message->length && !(messageFlags & MSG_NOERROR)) { TRACE_ERROR(("xsi_msgrcv: message too big!\n")); // Put the message back inside. Since we hold the @@ -855,6 +858,7 @@ } bool notSent = true; + status_t result = B_OK; while (notSent) { bool goToSleep = messageQueue->Insert(message); @@ -867,8 +871,7 @@ uint32 sequenceNumber = messageQueue->SequenceNumber(); TRACE(("xsi_msgsnd: thread %d going to sleep\n", (int)thread->id)); - status_t result - = messageQueue->BlockAndUnlock(thread, &messageQueueLocker); + result = messageQueue->BlockAndUnlock(thread, &messageQueueLocker); TRACE(("xsi_msgsnd: thread %d back to life\n", (int)thread->id)); messageQueueHashLocker.Lock(); @@ -895,7 +898,8 @@ } else if (goToSleep) { // We did not send the message and we can't wait delete message; - return EAGAIN; + notSent = false; + result = EAGAIN; } else { // Message delivered correctly TRACE(("xsi_msgsnd: message sent correctly\n")); @@ -903,5 +907,5 @@ } } - return B_OK; + return result; } From sbenedetto at mail.berlios.de Thu Sep 11 16:52:35 2008 From: sbenedetto at mail.berlios.de (sbenedetto at BerliOS) Date: Thu, 11 Sep 2008 16:52:35 +0200 Subject: [Haiku-commits] r27416 - in haiku/trunk: headers/posix/sys src/system/libroot/posix/sys Message-ID: <200809111452.m8BEqZ0A021275@sheep.berlios.de> Author: sbenedetto Date: 2008-09-11 16:52:35 +0200 (Thu, 11 Sep 2008) New Revision: 27416 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27416&view=rev Added: haiku/trunk/headers/posix/sys/msg.h haiku/trunk/src/system/libroot/posix/sys/xsi_msg_queue.cpp Log: * Adding sys/msg.h header and relative syscalls Added: haiku/trunk/headers/posix/sys/msg.h =================================================================== --- haiku/trunk/headers/posix/sys/msg.h 2008-09-11 14:42:13 UTC (rev 27415) +++ haiku/trunk/headers/posix/sys/msg.h 2008-09-11 14:52:35 UTC (rev 27416) @@ -0,0 +1,44 @@ +/* + * Copyright 2008, Haiku Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _SYS_MSG_H +#define _SYS_MSG_H + +#include +#include +#include + +typedef unsigned long msgqnum_t; +typedef unsigned long msglen_t; + +/* No error if big message */ +#define MSG_NOERROR 010000 + +struct msqid_ds { + struct ipc_perm msg_perm; /* Operation permission structure */ + msgqnum_t msg_qnum; /* Number of messages currently on queue */ + msglen_t msg_qbytes; /* Max number of bytes allowed on queue */ + pid_t msg_lspid; /* PID of last msgsnd */ + pid_t msg_lrpid; /* PID of last msgrcv */ + time_t msg_stime; /* Time of last msgsnd */ + time_t msg_rtime; /* Time of last msgrcv */ + time_t msg_ctime; /* Time of last change */ +}; + +/* Structure used to send/receive a message */ +struct msgbuf { + long mtype; /* message type */ + char mtext[1]; /* message text */ +}; + +__BEGIN_DECLS + +int msgctl(int, int, struct msqid_ds *); +int msgget(key_t, int); +ssize_t msgrcv(int, void *, size_t, long, int); +int msgsnd(int, const void *, size_t, int); + +__END_DECLS + +#endif /* _SYS_MSG_H */ Added: haiku/trunk/src/system/libroot/posix/sys/xsi_msg_queue.cpp =================================================================== --- haiku/trunk/src/system/libroot/posix/sys/xsi_msg_queue.cpp 2008-09-11 14:42:13 UTC (rev 27415) +++ haiku/trunk/src/system/libroot/posix/sys/xsi_msg_queue.cpp 2008-09-11 14:52:35 UTC (rev 27416) @@ -0,0 +1,51 @@ +/* + * Copyright 2008, Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Salvatore Benedetto + */ + +#include + +#include +#include +#include +#include + +#include + +#include +#include + + +int +msgctl(int messageQueueID, int command, struct msqid_ds *buffer) +{ + RETURN_AND_SET_ERRNO(_kern_xsi_msgctl(messageQueueID, command, buffer)); +} + + +int +msgget(key_t key, int messageQueueFlags) +{ + RETURN_AND_SET_ERRNO(_kern_xsi_msgget(key, messageQueueFlags)); +} + + +ssize_t +msgrcv(int messageQueueID, void *messagePointer, size_t messageSize, + long messageType, int messageFlags) +{ + RETURN_AND_SET_ERRNO(_kern_xsi_msgrcv(messageQueueID, messagePointer, + messageSize, messageType, messageFlags)); +} + + +int +msgsnd(int messageQueueID, const void *messagePointer, size_t messageSize, + int messageFlags) +{ + RETURN_AND_SET_ERRNO(_kern_xsi_msgsnd(messageQueueID, messagePointer, + messageSize, messageFlags)); +} From sbenedetto at mail.berlios.de Thu Sep 11 17:03:02 2008 From: sbenedetto at mail.berlios.de (sbenedetto at BerliOS) Date: Thu, 11 Sep 2008 17:03:02 +0200 Subject: [Haiku-commits] r27417 - in haiku/trunk: headers/private/kernel/posix headers/private/system src/system/kernel Message-ID: <200809111503.m8BF32km022545@sheep.berlios.de> Author: sbenedetto Date: 2008-09-11 17:03:01 +0200 (Thu, 11 Sep 2008) New Revision: 27417 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27417&view=rev Modified: haiku/trunk/headers/private/kernel/posix/xsi_message_queue.h haiku/trunk/headers/private/system/syscalls.h haiku/trunk/src/system/kernel/main.cpp haiku/trunk/src/system/kernel/syscalls.cpp Log: * Adding msg{rcv,snd,get,ctl} syscalls to the system * Add message queue init function call to main.cpp Modified: haiku/trunk/headers/private/kernel/posix/xsi_message_queue.h =================================================================== --- haiku/trunk/headers/private/kernel/posix/xsi_message_queue.h 2008-09-11 14:52:35 UTC (rev 27416) +++ haiku/trunk/headers/private/kernel/posix/xsi_message_queue.h 2008-09-11 15:03:01 UTC (rev 27417) @@ -15,6 +15,8 @@ __BEGIN_DECLS +extern void xsi_msg_init(); + /* user calls */ int _user_xsi_msgctl(int messageQueueID, int command, struct msqid_ds *buffer); int _user_xsi_msgget(key_t key, int messageQueueFlags); Modified: haiku/trunk/headers/private/system/syscalls.h =================================================================== --- haiku/trunk/headers/private/system/syscalls.h 2008-09-11 14:52:35 UTC (rev 27416) +++ haiku/trunk/headers/private/system/syscalls.h 2008-09-11 15:03:01 UTC (rev 27417) @@ -24,6 +24,7 @@ struct fd_set; struct fs_info; struct iovec; +struct msqid_ds; struct net_stat; struct pollfd; struct rlimit; @@ -101,6 +102,16 @@ extern status_t _kern_xsi_semop(int semID, struct sembuf *semOps, size_t numSemOps); +/* POSIX XSI message queue syscalls */ +extern int _kern_xsi_msgctl(int messageQueueID, int command, + struct msqid_ds *buffer); +extern int _kern_xsi_msgget(key_t key, int messageQueueFlags); +extern ssize_t _kern_xsi_msgrcv(int messageQueueID, void *messagePointer, + size_t messageSize, long messageType, int messageFlags); +extern int _kern_xsi_msgsnd(int messageQueueID, + const void *messagePointer, size_t messageSize, + int messageFlags); + /* team & thread syscalls */ extern thread_id _kern_load_image(const char* const* flatArgs, size_t flatArgsSize, int32 argCount, int32 envCount, Modified: haiku/trunk/src/system/kernel/main.cpp =================================================================== --- haiku/trunk/src/system/kernel/main.cpp 2008-09-11 14:52:35 UTC (rev 27416) +++ haiku/trunk/src/system/kernel/main.cpp 2008-09-11 15:03:01 UTC (rev 27417) @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -170,6 +171,7 @@ TRACE("init POSIX semaphores\n"); realtime_sem_init(); xsi_sem_init(); + xsi_msg_init(); TRACE("init VM threads\n"); vm_init_post_thread(&sKernelArgs); Modified: haiku/trunk/src/system/kernel/syscalls.cpp =================================================================== --- haiku/trunk/src/system/kernel/syscalls.cpp 2008-09-11 14:52:35 UTC (rev 27416) +++ haiku/trunk/src/system/kernel/syscalls.cpp 2008-09-11 15:03:01 UTC (rev 27417) @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include From sbenedetto at mail.berlios.de Thu Sep 11 17:06:47 2008 From: sbenedetto at mail.berlios.de (sbenedetto at BerliOS) Date: Thu, 11 Sep 2008 17:06:47 +0200 Subject: [Haiku-commits] r27418 - in haiku/trunk/src/system: kernel/posix libroot/posix/sys Message-ID: <200809111506.m8BF6lOx022745@sheep.berlios.de> Author: sbenedetto Date: 2008-09-11 17:06:47 +0200 (Thu, 11 Sep 2008) New Revision: 27418 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27418&view=rev Modified: haiku/trunk/src/system/kernel/posix/Jamfile haiku/trunk/src/system/libroot/posix/sys/Jamfile Log: * forgot to commit Jamfiles Modified: haiku/trunk/src/system/kernel/posix/Jamfile =================================================================== --- haiku/trunk/src/system/kernel/posix/Jamfile 2008-09-11 15:03:01 UTC (rev 27417) +++ haiku/trunk/src/system/kernel/posix/Jamfile 2008-09-11 15:06:47 UTC (rev 27418) @@ -4,6 +4,7 @@ KernelMergeObject kernel_posix.o : realtime_sem.cpp + xsi_message_queue.cpp xsi_semaphore.cpp : $(TARGET_KERNEL_PIC_CCFLAGS) Modified: haiku/trunk/src/system/libroot/posix/sys/Jamfile =================================================================== --- haiku/trunk/src/system/libroot/posix/sys/Jamfile 2008-09-11 15:03:01 UTC (rev 27417) +++ haiku/trunk/src/system/libroot/posix/sys/Jamfile 2008-09-11 15:06:47 UTC (rev 27418) @@ -24,5 +24,6 @@ uname.c utimes.c wait.c + xsi_msg_queue.cpp xsi_sem.cpp ; From sbenedetto at mail.berlios.de Thu Sep 11 17:08:20 2008 From: sbenedetto at mail.berlios.de (sbenedetto at BerliOS) Date: Thu, 11 Sep 2008 17:08:20 +0200 Subject: [Haiku-commits] r27419 - haiku/trunk/src/tests/system/libroot/posix Message-ID: <200809111508.m8BF8K2u023002@sheep.berlios.de> Author: sbenedetto Date: 2008-09-11 17:08:18 +0200 (Thu, 11 Sep 2008) New Revision: 27419 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27419&view=rev Added: haiku/trunk/src/tests/system/libroot/posix/xsi_msg_queue_test1.cpp Modified: haiku/trunk/src/tests/system/libroot/posix/Jamfile Log: * Adding unit test for xsi message queue Modified: haiku/trunk/src/tests/system/libroot/posix/Jamfile =================================================================== --- haiku/trunk/src/tests/system/libroot/posix/Jamfile 2008-09-11 15:06:47 UTC (rev 27418) +++ haiku/trunk/src/tests/system/libroot/posix/Jamfile 2008-09-11 15:08:18 UTC (rev 27419) @@ -60,6 +60,10 @@ : init_rld_after_fork_test.cpp ; +SimpleTest xsi_msg_queue_test1 + : xsi_msg_queue_test1.cpp +; + SimpleTest xsi_sem_test1 : xsi_sem_test1.cpp ; Added: haiku/trunk/src/tests/system/libroot/posix/xsi_msg_queue_test1.cpp =================================================================== --- haiku/trunk/src/tests/system/libroot/posix/xsi_msg_queue_test1.cpp 2008-09-11 15:06:47 UTC (rev 27418) +++ haiku/trunk/src/tests/system/libroot/posix/xsi_msg_queue_test1.cpp 2008-09-11 15:08:18 UTC (rev 27419) @@ -0,0 +1,241 @@ +/* + * Copyright 2008, Salvatore Benedetto, salvatore.benedetto at gmail.com. + * Distributed under the terms of the MIT License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "TestUnitUtils.h" + +#define KEY ((key_t)12345) + +static status_t +remove_msg_queue(int msgID) +{ + return msgctl(msgID, IPC_RMID, 0); +} + +struct message { + long type; + char text[20]; +}; + + +static void +test_msgget() +{ + TEST_SET("msgget({IPC_PRIVATE, key})"); + + const char* currentTest = NULL; + + // Open private set with IPC_PRIVATE + TEST("msgget(IPC_PRIVATE) - private"); + int msgID = msgget(IPC_PRIVATE, S_IRUSR | S_IWUSR); + assert_posix_bool_success(msgID != -1); + + // Destroy private msg_queue + TEST("msgctl(IPC_RMID) - private"); + status_t status = remove_msg_queue(msgID); + assert_posix_bool_success(status != -1); + + // Open non-private non-existing set with IPC_CREAT + TEST("msgget(KEY, IPC_CREAT) non-existing"); + msgID = msgget(KEY, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR + | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); + assert_posix_bool_success(status != -1); + + // Re-open non-private existing without IPC_CREAT + TEST("msgget(KEY) re-open existing without IPC_CREAT"); + int returnID = msgget(KEY, 0); + assert_equals(msgID, returnID); + + // Re-open non-private existing with IPC_CREAT + TEST("msgget(IPC_CREATE) re-open existing with IPC_CREAT"); + returnID = msgget(KEY, IPC_CREAT | IPC_EXCL); + assert_posix_bool_success(errno == EEXIST); + + // Destroy non-private msg_queue + TEST("msgctl(IPC_RMID)"); + status = remove_msg_queue(msgID); + assert_posix_bool_success(status != -1); + + // Open non-private non-existing without IPC_CREAT + TEST("msgget(IPC_CREATE) non-existing without IPC_CREAT"); + msgID = msgget(KEY, IPC_EXCL | S_IRUSR | S_IWUSR + | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); + assert_posix_bool_success(errno == ENOENT); + + // Destroy non-existing msg_queue + TEST("msgctl()"); + status = remove_msg_queue(msgID); + assert_posix_bool_success(errno == EINVAL); + + TEST("done"); +} + + +static void +test_msgctl() +{ + TEST_SET("msgctl({IPC_STAT, IPC_SET, IPC_RMID})"); + + const char* currentTest = NULL; + + // Open non-private non-existing set with IPC_CREAT + TEST("msgget(IPC_CREATE) non-existing"); + int msgID = msgget(KEY, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR + | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); + assert_posix_bool_success(msgID != -1); + + // IPC_SET + TEST("msgctl(IPC_SET)"); + struct msqid_ds msg_queue; + memset(&msg_queue, 0, sizeof(struct msqid_ds)); + msg_queue.msg_perm.uid = getuid() + 3; + msg_queue.msg_perm.gid = getgid() + 3; + msg_queue.msg_perm.mode = 0666; + msg_queue.msg_qbytes = 512; + status_t status = msgctl(msgID, IPC_SET, &msg_queue); + assert_posix_bool_success(status != 1); + + // IPC_STAT set + TEST("msgctl(IPC_STAT)"); + memset(&msg_queue, 0, sizeof(struct msqid_ds)); + status = msgctl(msgID, IPC_STAT, &msg_queue); + assert_posix_bool_success(status != 1); + TEST("msgctl(IPC_STAT): number of bytes"); + assert_equals((msglen_t)msg_queue.msg_qbytes, (msglen_t)512); + TEST("msgctl(IPC_STAT): uid"); + assert_equals(msg_queue.msg_perm.uid, getuid() + 3); + TEST("msgctl(IPC_STAT): gid"); + assert_equals(msg_queue.msg_perm.gid, getgid() + 3); + + // Destroy non-private msg_queue + TEST("msgctl(IPC_RMID)"); + status = remove_msg_queue(msgID); + assert_posix_bool_success(status != 1); + + TEST("done"); +} + + +static void +test_msgsnd() +{ + TEST_SET("msgsnd({EAGAIN, send})"); + + const char* currentTest = NULL; + + // Open non-private non-existing set with IPC_CREAT + TEST("msgget(IPC_CREATE) non-existing"); + int msgID = msgget(KEY, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR + | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); + assert_posix_bool_success(msgID != -1); + + // Send simple message + TEST("msgsnd(simple message)"); + struct message msg; + msg.type = 0; + strcpy(msg.text, "Message to send\n"); + status_t status = msgsnd((key_t)msgID, (void *)&msg, 20, 0); + assert_posix_bool_success(status != 1); + + // IPC_SET + TEST("msgctl(IPC_SET) - set limit to 512"); + struct msqid_ds msg_queue; + memset(&msg_queue, 0, sizeof(struct msqid_ds)); + msg_queue.msg_perm.uid = getuid() + 3; + msg_queue.msg_perm.gid = getgid() + 3; + msg_queue.msg_perm.mode = 0666; + msg_queue.msg_qbytes = 512; + status = msgctl(msgID, IPC_SET, &msg_queue); + assert_posix_bool_success(status != 1); + + // Send big message IPC_NOWAIT + TEST("msgsnd(IPC_NOWAIT)"); + msgsnd((key_t)msgID, (void *)&msg, 500, IPC_NOWAIT); + assert_posix_bool_success(errno == EAGAIN); + + // Destroy non-private msg_queue + TEST("msgctl(IPC_RMID)"); + status = remove_msg_queue(msgID); + assert_posix_bool_success(status != 1); + + TEST("done"); +} + + +static void +test_msgrcv() +{ + TEST_SET("msgrcv({IPC_STAT, IPC_SET, IPC_RMID})"); + + const char* currentTest = NULL; + + // Open non-private non-existing set with IPC_CREAT + TEST("msgget(IPC_CREATE) non-existing"); + int msgID = msgget(KEY, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR + | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); + assert_posix_bool_success(msgID != -1); + + // Receive simple message + TEST("msgrcv(IPC_NOWAIT)"); + struct message msg; + memset(&msg, 0, sizeof(struct message)); + msgrcv((key_t)msgID, (void *)&msg, 20, 0, IPC_NOWAIT); + assert_posix_bool_success(errno == ENOMSG); + + pid_t child = fork(); + if (child == 0) { + // Send a simple message + TEST("msgsnd(simple message)"); + struct message smsg; + msg.type = 0; + strcpy(msg.text, "Message to send\n"); + status_t status = msgsnd((key_t)msgID, (void *)&smsg, 20, 0); + assert_posix_bool_success(status != 1); + exit(0); + } + + wait_for_child(child); + TEST("msgrcv(E2BIG)"); + msgrcv((key_t)msgID, (void *)&msg, 10, 0, IPC_NOWAIT); + assert_posix_bool_success(errno == E2BIG); + + TEST("msgrcv(MSG_NOERROR)"); + status_t status + = msgrcv((key_t)msgID, (void *)&msg, 10, 0, IPC_NOWAIT | MSG_NOERROR); + assert_posix_bool_success(status != -1); + + // Destroy non-private msg_queue + TEST("msgctl(IPC_RMID)"); + status = remove_msg_queue(msgID); + assert_posix_bool_success(status != 1); + + TEST("done"); +} + + +int +main() +{ + test_msgget(); + test_msgctl(); + test_msgsnd(); + test_msgrcv(); + + printf("\nAll tests OK\n"); +} From sbenedetto at mail.berlios.de Thu Sep 11 17:10:40 2008 From: sbenedetto at mail.berlios.de (sbenedetto at BerliOS) Date: Thu, 11 Sep 2008 17:10:40 +0200 Subject: [Haiku-commits] r27420 - haiku/trunk/src/system/kernel/posix Message-ID: <200809111510.m8BFAeSF023259@sheep.berlios.de> Author: sbenedetto Date: 2008-09-11 17:10:40 +0200 (Thu, 11 Sep 2008) New Revision: 27420 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27420&view=rev Modified: haiku/trunk/src/system/kernel/posix/xsi_semaphore.cpp Log: * Order members alphabetically. No functional changes Modified: haiku/trunk/src/system/kernel/posix/xsi_semaphore.cpp =================================================================== --- haiku/trunk/src/system/kernel/posix/xsi_semaphore.cpp 2008-09-11 15:08:18 UTC (rev 27419) +++ haiku/trunk/src/system/kernel/posix/xsi_semaphore.cpp 2008-09-11 15:10:40 UTC (rev 27420) @@ -517,16 +517,16 @@ } private: + int fID; // semaphore set id bool fInitOK; - int fID; // semaphore set id time_t fLastSemctlTime; // sem_ctime time_t fLastSemopTime; // sem_otime + mutex fLock; // private lock ushort fNumberOfSemaphores; // sem_nsems struct ipc_perm fPermissions; // sem_perm + XsiSemaphore *fSemaphores; // array of semaphores uint32 fSequenceNumber; // used as a second id - XsiSemaphore *fSemaphores; // array of semaphores UndoList fUndoList; // undo list requests - mutex fLock; // private lock ::HashTableLink fLink; }; From revol at free.fr Thu Sep 11 20:38:42 2008 From: revol at free.fr (=?windows-1252?q?Fran=E7ois?= Revol) Date: Thu, 11 Sep 2008 20:38:42 +0200 CEST Subject: [Haiku-commits] =?windows-1252?q?r27417_-_in_haiku/trunk=3A_heade?= =?windows-1252?q?rs/private/kernel/posix_headers/private/system_src/syste?= =?windows-1252?q?m/kernel?= In-Reply-To: <200809111503.m8BF32km022545@sheep.berlios.de> Message-ID: <1502727756-BeMail@laptop> > Author: sbenedetto > Date: 2008-09-11 17:03:01 +0200 (Thu, 11 Sep 2008) > New Revision: 27417 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27417&view=rev > > Modified: > haiku/trunk/headers/private/kernel/posix/xsi_message_queue.h > haiku/trunk/headers/private/system/syscalls.h > haiku/trunk/src/system/kernel/main.cpp > haiku/trunk/src/system/kernel/syscalls.cpp > Log: > * Adding msg{rcv,snd,get,ctl} syscalls to the system > * Add message queue init function call to main.cpp I was wondering if it could be possible to use a single syscall for those, or maybe (do we have it already) a generic syscall, and possibly put all those in a separate module ? Just thinking about optimizations for embedded stuff :) Fran?ois. From emitrax at gmail.com Thu Sep 11 21:07:36 2008 From: emitrax at gmail.com (Salvatore Benedetto) Date: Thu, 11 Sep 2008 19:07:36 +0000 Subject: [Haiku-commits] r27417 - in haiku/trunk: headers/private/kernel/posix headers/private/system src/system/kernel In-Reply-To: <1502727756-BeMail@laptop> References: <200809111503.m8BF32km022545@sheep.berlios.de> <1502727756-BeMail@laptop> Message-ID: 2008/9/11 Fran?ois Revol : >> Author: sbenedetto >> Date: 2008-09-11 17:03:01 +0200 (Thu, 11 Sep 2008) >> New Revision: 27417 >> ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27417&view=rev >> >> Modified: >> haiku/trunk/headers/private/kernel/posix/xsi_message_queue.h >> haiku/trunk/headers/private/system/syscalls.h >> haiku/trunk/src/system/kernel/main.cpp >> haiku/trunk/src/system/kernel/syscalls.cpp >> Log: >> * Adding msg{rcv,snd,get,ctl} syscalls to the system >> * Add message queue init function call to main.cpp > > I was wondering if it could be possible to use a single syscall for > those, or maybe (do we have it already) a generic syscall, and possibly > put all those in a separate module ? I don't know if there is a generic one already. > > Just thinking about optimizations for embedded stuff :) Let's just focus on desktop :-) Regards, -- Salvatore Benedetto (a.k.a. emitrax) Student of Computer Engineer University of Pisa www.haiku-os.it From axeld at pinc-software.de Thu Sep 11 22:41:24 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Thu, 11 Sep 2008 22:41:24 +0200 CEST Subject: [Haiku-commits] r27420 - haiku/trunk/src/system/kernel/posix In-Reply-To: <200809111510.m8BFAeSF023259@sheep.berlios.de> Message-ID: <47387449641-BeMail@zon> sbenedetto at BerliOS wrote: > private: > + int fID; // semaphore > set id > bool fInitOK; > - int fID; // semaphore > set id > time_t fLastSemctlTime; // sem_ctime > time_t fLastSemopTime; // sem_otime > + mutex fLock; // private lock > ushort fNumberOfSemaphores; // sem_nsems > struct ipc_perm fPermissions; // sem_perm > + XsiSemaphore *fSemaphores; // array of > semaphores > uint32 fSequenceNumber; // used as a > second id > - XsiSemaphore *fSemaphores; // array of > semaphores > UndoList fUndoList; // undo list > requests > - mutex fLock; // private lock Alphabetical ordering doesn't really make sense, though. For example, it would be better to move the ushort to the bool value, so that you only lose a single padding byte, not 5. There might be other possible improvements, too (depending on the contents of the structs). Bye, Axel. From axeld at pinc-software.de Thu Sep 11 22:43:05 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Thu, 11 Sep 2008 22:43:05 +0200 CEST Subject: [Haiku-commits] =?utf-8?q?r27417_-_in_haiku/trunk=3A_headers/priv?= =?utf-8?q?ate/kernel/posix_headers/private/system_src/system/kernel?= In-Reply-To: Message-ID: <47488474196-BeMail@zon> "Salvatore Benedetto" wrote: > > I was wondering if it could be possible to use a single syscall for > > those, or maybe (do we have it already) a generic syscall, and > > possibly > > put all those in a separate module ? > I don't know if there is a generic one already. We do have a generic one. > > Just thinking about optimizations for embedded stuff :) > Let's just focus on desktop :-) Unless you want to be binary compatible, why not just leave it out when compiling then? Besides, Salvatore is right, too. Bye, Axel. From emitrax at gmail.com Thu Sep 11 23:25:39 2008 From: emitrax at gmail.com (Salvatore Benedetto) Date: Thu, 11 Sep 2008 23:25:39 +0200 Subject: [Haiku-commits] r27420 - haiku/trunk/src/system/kernel/posix In-Reply-To: <47387449641-BeMail@zon> References: <200809111510.m8BFAeSF023259@sheep.berlios.de> <47387449641-BeMail@zon> Message-ID: 2008/9/11 Axel D?rfler : > sbenedetto at BerliOS wrote: >> private: >> + int fID; // semaphore >> set id >> bool fInitOK; >> - int fID; // semaphore >> set id >> time_t fLastSemctlTime; // sem_ctime >> time_t fLastSemopTime; // sem_otime >> + mutex fLock; // private lock >> ushort fNumberOfSemaphores; // sem_nsems >> struct ipc_perm fPermissions; // sem_perm >> + XsiSemaphore *fSemaphores; // array of >> semaphores >> uint32 fSequenceNumber; // used as a >> second id >> - XsiSemaphore *fSemaphores; // array of >> semaphores >> UndoList fUndoList; // undo list >> requests >> - mutex fLock; // private lock > > Alphabetical ordering doesn't really make sense, though. For example, > it would be better to move the ushort to the bool value, so that you > only lose a single padding byte, not 5. I did not take that in consideration. Regards, -- Salvatore Benedetto (a.k.a. emitrax) Student of Computer Engineer University of Pisa www.haiku-os.it From emitrax at gmail.com Thu Sep 11 23:28:20 2008 From: emitrax at gmail.com (Salvatore Benedetto) Date: Thu, 11 Sep 2008 23:28:20 +0200 Subject: [Haiku-commits] r27420 - haiku/trunk/src/system/kernel/posix In-Reply-To: <47387449641-BeMail@zon> References: <200809111510.m8BFAeSF023259@sheep.berlios.de> <47387449641-BeMail@zon> Message-ID: 2008/9/11 Axel D?rfler : > sbenedetto at BerliOS wrote: >> private: >> + int fID; // semaphore >> set id >> bool fInitOK; >> - int fID; // semaphore >> set id >> time_t fLastSemctlTime; // sem_ctime >> time_t fLastSemopTime; // sem_otime >> + mutex fLock; // private lock >> ushort fNumberOfSemaphores; // sem_nsems >> struct ipc_perm fPermissions; // sem_perm >> + XsiSemaphore *fSemaphores; // array of >> semaphores >> uint32 fSequenceNumber; // used as a >> second id >> - XsiSemaphore *fSemaphores; // array of >> semaphores >> UndoList fUndoList; // undo list >> requests >> - mutex fLock; // private lock > > Alphabetical ordering doesn't really make sense, though. For example, > it would be better to move the ushort to the bool value, so that you > only lose a single padding byte, not 5. > There might be other possible improvements, too (depending on the > contents of the structs). > BTW: are there no compiler optimization for this? > Bye, > Axel. > > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > -- Salvatore Benedetto (a.k.a. emitrax) Student of Computer Engineer University of Pisa www.haiku-os.it From anevilyak at gmail.com Thu Sep 11 23:29:29 2008 From: anevilyak at gmail.com (Rene Gollent) Date: Thu, 11 Sep 2008 16:29:29 -0500 Subject: [Haiku-commits] r27420 - haiku/trunk/src/system/kernel/posix In-Reply-To: References: <200809111510.m8BFAeSF023259@sheep.berlios.de> <47387449641-BeMail@zon> Message-ID: On Thu, Sep 11, 2008 at 4:28 PM, Salvatore Benedetto wrote: > BTW: are there no compiler optimization for this? I might be wrong, but I believe the compiler deliberately avoids this for bin compat reasons. Regards, Rene From korli at mail.berlios.de Fri Sep 12 00:14:56 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Fri, 12 Sep 2008 00:14:56 +0200 Subject: [Haiku-commits] r27421 - haiku/trunk/src/bin/coreutils/src Message-ID: <200809112214.m8BMEu8f028453@sheep.berlios.de> Author: korli Date: 2008-09-12 00:14:55 +0200 (Fri, 12 Sep 2008) New Revision: 27421 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27421&view=rev Modified: haiku/trunk/src/bin/coreutils/src/Jamfile Log: fixed ls to be ls and not dir (bug #2646) added dir Modified: haiku/trunk/src/bin/coreutils/src/Jamfile =================================================================== --- haiku/trunk/src/bin/coreutils/src/Jamfile 2008-09-11 15:10:40 UTC (rev 27420) +++ haiku/trunk/src/bin/coreutils/src/Jamfile 2008-09-11 22:14:55 UTC (rev 27421) @@ -110,7 +110,7 @@ BinCommand "[" : lbracket.c : libfetish.a : $(coreutils_rsrc) ; BinCommand ls : - ls.c ls-dir.c : libfetish.a : $(coreutils_rsrc) ; + ls.c ls-ls.c : libfetish.a : $(coreutils_rsrc) ; BinCommand rm : rm.c remove.c : libfetish.a libroot.so : $(coreutils_rsrc) ; @@ -139,6 +139,9 @@ BinCommand vdir : [ FGristFiles ls.o ] ls-vdir.c : libfetish.a : $(coreutils_rsrc) ; +BinCommand dir : + [ FGristFiles ls.o ] ls-dir.c : libfetish.a : $(coreutils_rsrc) ; + BinCommand install : install.c [ FGristFiles copy.o cp-hash.o ] : libfetish.a : $(coreutils_rsrc) ; From anevilyak at gmail.com Fri Sep 12 00:16:59 2008 From: anevilyak at gmail.com (Rene Gollent) Date: Thu, 11 Sep 2008 17:16:59 -0500 Subject: [Haiku-commits] r27421 - haiku/trunk/src/bin/coreutils/src In-Reply-To: <200809112214.m8BMEu8f028453@sheep.berlios.de> References: <200809112214.m8BMEu8f028453@sheep.berlios.de> Message-ID: On Thu, Sep 11, 2008 at 5:14 PM, korli at BerliOS wrote: > - ls.c ls-dir.c : libfetish.a : $(coreutils_rsrc) ; > + ls.c ls-ls.c : libfetish.a : $(coreutils_rsrc) ; Do I want to know what libfetish is? :-) Regards, Rene From korli at mail.berlios.de Fri Sep 12 00:23:21 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Fri, 12 Sep 2008 00:23:21 +0200 Subject: [Haiku-commits] r27422 - haiku/trunk/src/system/libroot/posix/glibc/misc Message-ID: <200809112223.m8BMNLxh029520@sheep.berlios.de> Author: korli Date: 2008-09-12 00:23:21 +0200 (Fri, 12 Sep 2008) New Revision: 27422 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27422&view=rev Added: haiku/trunk/src/system/libroot/posix/glibc/misc/insremque.c Modified: haiku/trunk/src/system/libroot/posix/glibc/misc/Jamfile Log: added insque and remque Modified: haiku/trunk/src/system/libroot/posix/glibc/misc/Jamfile =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/misc/Jamfile 2008-09-11 22:14:55 UTC (rev 27421) +++ haiku/trunk/src/system/libroot/posix/glibc/misc/Jamfile 2008-09-11 22:23:21 UTC (rev 27422) @@ -14,6 +14,7 @@ MergeObject posix_gnu_misc.o : dirname.c + insremque.c tsearch.c efgcvt.c efgcvt_r.c Added: haiku/trunk/src/system/libroot/posix/glibc/misc/insremque.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/misc/insremque.c 2008-09-11 22:14:55 UTC (rev 27421) +++ haiku/trunk/src/system/libroot/posix/glibc/misc/insremque.c 2008-09-11 22:23:21 UTC (rev 27422) @@ -0,0 +1,46 @@ +/* Copyright (C) 1992, 1995, 1996 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include + +/* Insert ELEM into a doubly-linked list, after PREV. */ + +void +insque (void *elem, void *prev) +{ + struct qelem *next = ((struct qelem *) prev)->q_forw; + ((struct qelem *) prev)->q_forw = (struct qelem *) elem; + if (next != NULL) + next->q_back = (struct qelem *) elem; + ((struct qelem *) elem)->q_forw = next; + ((struct qelem *) elem)->q_back = (struct qelem *) prev; +} + +/* Unlink ELEM from the doubly-linked list that it is in. */ + +void +remque (void *elem) +{ + struct qelem *next = ((struct qelem *) elem)->q_forw; + struct qelem *prev = ((struct qelem *) elem)->q_back; + if (next != NULL) + next->q_back = prev; + if (prev != NULL) + prev->q_forw = (struct qelem *) next; +} From korli at mail.berlios.de Fri Sep 12 00:27:55 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Fri, 12 Sep 2008 00:27:55 +0200 Subject: [Haiku-commits] r27423 - in haiku/trunk: headers/posix src/system/libroot/posix/glibc/misc Message-ID: <200809112227.m8BMRtNG030366@sheep.berlios.de> Author: korli Date: 2008-09-12 00:27:55 +0200 (Fri, 12 Sep 2008) New Revision: 27423 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27423&view=rev Added: haiku/trunk/src/system/libroot/posix/glibc/misc/lsearch.c Modified: haiku/trunk/headers/posix/math.h haiku/trunk/headers/posix/string.h haiku/trunk/src/system/libroot/posix/glibc/misc/Jamfile Log: added lsearch and lfind remove unknown infnanf and strtcopy functions Modified: haiku/trunk/headers/posix/math.h =================================================================== --- haiku/trunk/headers/posix/math.h 2008-09-11 22:23:21 UTC (rev 27422) +++ haiku/trunk/headers/posix/math.h 2008-09-11 22:27:55 UTC (rev 27423) @@ -189,7 +189,6 @@ /* other stuff as defined in BeOS */ extern int isinff(float value); extern int finitef(float value); -extern float infnanf(int error); extern float dremf(float x, float y); extern float significandf(float x); extern float copysignf(float x, float y); Modified: haiku/trunk/headers/posix/string.h =================================================================== --- haiku/trunk/headers/posix/string.h 2008-09-11 22:23:21 UTC (rev 27422) +++ haiku/trunk/headers/posix/string.h 2008-09-11 22:27:55 UTC (rev 27423) @@ -59,7 +59,6 @@ extern char *strdup(const char *string); extern char *stpcpy(char *dest, const char *source); -extern const char *strtcopy(char *dest, const char *source); extern size_t strlcat(char *dest, const char *source, size_t length); extern size_t strlcpy(char *dest, const char *source, size_t length); Modified: haiku/trunk/src/system/libroot/posix/glibc/misc/Jamfile =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/misc/Jamfile 2008-09-11 22:23:21 UTC (rev 27422) +++ haiku/trunk/src/system/libroot/posix/glibc/misc/Jamfile 2008-09-11 22:27:55 UTC (rev 27423) @@ -15,6 +15,7 @@ MergeObject posix_gnu_misc.o : dirname.c insremque.c + lsearch.c tsearch.c efgcvt.c efgcvt_r.c Added: haiku/trunk/src/system/libroot/posix/glibc/misc/lsearch.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/misc/lsearch.c 2008-09-11 22:23:21 UTC (rev 27422) +++ haiku/trunk/src/system/libroot/posix/glibc/misc/lsearch.c 2008-09-11 22:27:55 UTC (rev 27423) @@ -0,0 +1,59 @@ +/* Linear search functions. + Copyright (C) 1996,97,98,2002 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper , 1996. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include + + +void * +lsearch (const void *key, void *base, size_t *nmemb, size_t size, + __compar_fn_t compar) +{ + void *result; + + /* Try to find it. */ + result = lfind (key, base, nmemb, size, compar); + if (result == NULL) + { + /* Not available. Insert at the end. */ + result = memcpy (base + (*nmemb) * size, key, size); + ++(*nmemb); + } + + return result; +} + + +void * +lfind (const void *key, const void *base, size_t *nmemb, size_t size, + __compar_fn_t compar) +{ + const void *result = base; + size_t cnt = 0; + + while (cnt < *nmemb && (*compar) (key, result) != 0) + { + result += size; + ++cnt; + } + + return cnt < *nmemb ? (void *) result : NULL; +} +libc_hidden_def (lfind) From korli at mail.berlios.de Fri Sep 12 00:45:18 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Fri, 12 Sep 2008 00:45:18 +0200 Subject: [Haiku-commits] r27424 - haiku/trunk/headers/posix Message-ID: <200809112245.m8BMjIaI017256@sheep.berlios.de> Author: korli Date: 2008-09-12 00:45:17 +0200 (Fri, 12 Sep 2008) New Revision: 27424 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27424&view=rev Modified: haiku/trunk/headers/posix/math.h Log: isnan and isfinite are macros Modified: haiku/trunk/headers/posix/math.h =================================================================== --- haiku/trunk/headers/posix/math.h 2008-09-11 22:27:55 UTC (rev 27423) +++ haiku/trunk/headers/posix/math.h 2008-09-11 22:45:17 UTC (rev 27424) @@ -198,8 +198,6 @@ extern double scalbln(double x, long n); extern double scalbn(double x, int y); extern double drem(double x, double y); -extern int isnan(double x); -extern int isfinite(double x); extern int finite(double x); extern float j0f(float x); extern float j1f(float x); From julun at mail.berlios.de Fri Sep 12 00:52:45 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Fri, 12 Sep 2008 00:52:45 +0200 Subject: [Haiku-commits] r27425 - haiku/trunk/src/apps/magnify Message-ID: <200809112252.m8BMqjrJ026783@sheep.berlios.de> Author: julun Date: 2008-09-12 00:52:44 +0200 (Fri, 12 Sep 2008) New Revision: 27425 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27425&view=rev Modified: haiku/trunk/src/apps/magnify/Magnify.cpp Log: * automatic whitespace cleanup Modified: haiku/trunk/src/apps/magnify/Magnify.cpp =================================================================== --- haiku/trunk/src/apps/magnify/Magnify.cpp 2008-09-11 22:45:17 UTC (rev 27424) +++ haiku/trunk/src/apps/magnify/Magnify.cpp 2008-09-11 22:52:44 UTC (rev 27425) @@ -8,7 +8,6 @@ * This file may be used under the terms of the Be Sample Code License. */ - #include "Magnify.h" #include @@ -91,13 +90,13 @@ static float FontHeight(BView* target, bool full) { - font_height finfo; + font_height finfo; target->GetFontHeight(&finfo); float h = ceil(finfo.ascent) + ceil(finfo.descent); if (full) h += ceil(finfo.leading); - + return h; } @@ -167,7 +166,7 @@ menuItem = new BMenuItem("Freeze/Unfreeze image", new BMessage(msg_freeze),'F'); menu->AddItem(menuItem); menu->AddSeparatorItem(); - + menuItem = new BMenuItem("Make Square", new BMessage(msg_make_square),'/'); menu->AddItem(menuItem); menuItem = new BMenuItem("Decrease Window Size", new BMessage(msg_shrink),'-'); @@ -177,7 +176,7 @@ menuItem = new BMenuItem("Decrease Pixel Size", new BMessage(msg_shrink_pixel),','); menu->AddItem(menuItem); menuItem = new BMenuItem("Increase Pixel Size", new BMessage(msg_grow_pixel),'.'); - menu->AddItem(menuItem); + menu->AddItem(menuItem); } @@ -244,7 +243,7 @@ if (InfoIsShowing()) fbRect.OffsetBy(10, fInfoHeight); fFatBits = new TMagnify(fbRect, this); - fInfo->AddChild(fFatBits); + fInfo->AddChild(fFatBits); fFatBits->SetSelection(fShowInfo); fInfo->SetMagView(fFatBits); @@ -276,26 +275,26 @@ TWindow::MessageReceived(BMessage* m) { bool active = fFatBits->Active(); - + switch (m->what) { case B_ABOUT_REQUESTED: be_app->MessageReceived(m); break; - + case msg_help: ShowHelp(); break; - + case msg_show_info: if (active) ShowInfo(!fShowInfo); break; - + case msg_toggle_grid: if (active) SetGrid(!fShowGrid); break; - + case msg_grow: if (active) ResizeWindow(true); @@ -312,7 +311,7 @@ ResizeWindow(big, big); } break; - + case msg_shrink_pixel: if (active) SetPixelSize(false); @@ -321,7 +320,7 @@ if (active) SetPixelSize(true); break; - + case msg_add_cross_hair: if (active && fShowInfo) AddCrossHair(); @@ -343,7 +342,7 @@ case msg_save: // freeze the image here, unfreeze after dump or cancel fFatBits->StartSave(); - + fSavePanel = new BFilePanel(B_SAVE_PANEL, new BMessenger(NULL, this), 0, 0, false, new BMessage(msg_dump)); fSavePanel->SetSaveText("Bitmaps.h"); @@ -352,12 +351,12 @@ case msg_dump: { delete fSavePanel; - + entry_ref dirRef; char* name; m->FindRef("directory", &dirRef); m->FindString((const char*)"name",(const char**) &name); - + fFatBits->SaveImage(&dirRef, name); } break; @@ -365,14 +364,14 @@ // image is frozen before the FilePanel is shown fFatBits->EndSave(); break; - + case msg_copy_image: fFatBits->CopyImage(); break; default: BWindow::MessageReceived(m); break; - } + } } @@ -459,7 +458,7 @@ if (haveLoc && BScreen(B_MAIN_SCREEN_ID).Frame().Contains(loc)) { MoveTo(loc); goto DONE; - } + } } } @@ -501,7 +500,7 @@ CrossHairsShowing(&ch1, &ch2); write(ref, &ch1, sizeof(bool)); write(ref, &ch2, sizeof(bool)); - + write(ref, &fHPixelCount, sizeof(int32)); write(ref, &fVPixelCount, sizeof(int32)); write(ref, &fPixelSize, sizeof(int32)); @@ -516,12 +515,12 @@ TWindow::FrameResized(float w, float h) { CalcViewablePixels(); - + float width; float height; - GetPreferredSize(&width, &height); + GetPreferredSize(&width, &height); ResizeTo(width, height); - + fFatBits->InitBuffers(fHPixelCount, fVPixelCount, fPixelSize, ShowGrid()); } @@ -555,14 +554,14 @@ { float w = Bounds().Width(); float h = Bounds().Height(); - + if (InfoIsShowing()) { w -= 20; // remove the gutter h = h-fInfoHeight-10; // remove info and gutter } bool ch1, ch2; - fFatBits->CrossHairsShowing(&ch1, &ch2); + fFatBits->CrossHairsShowing(&ch1, &ch2); if (ch1) h -= fFontHeight; if (ch2) @@ -584,16 +583,16 @@ *width = fHPixelCount * fPixelSize; // calc window width *height = fVPixelCount * fPixelSize; // calc window height if (InfoIsShowing()) { - *width += 20; + *width += 20; *height += fInfoHeight + 10; } - + bool ch1, ch2; - fFatBits->CrossHairsShowing(&ch1, &ch2); + fFatBits->CrossHairsShowing(&ch1, &ch2); if (ch1) *height += fFontHeight; if (ch2) - *height += fFontHeight + 5; + *height += fFontHeight + 5; } @@ -602,10 +601,10 @@ { fHPixelCount = hPixelCount; fVPixelCount = vPixelCount; - + float width, height; GetPreferredSize(&width, &height); - + ResizeTo(width, height); } @@ -615,7 +614,7 @@ { int32 x = fHPixelCount; int32 y = fVPixelCount; - + if (direction) { x += 4; y += 4; @@ -630,7 +629,7 @@ if (y < 4) y = 4; - ResizeWindow(x, y); + ResizeWindow(x, y); } @@ -639,7 +638,7 @@ { if (s == fShowGrid) return; - + fShowGrid = s; fFatBits->SetUpdate(true); } @@ -657,7 +656,7 @@ { if (i == fShowInfo) return; - + fShowInfo = i; if (fShowInfo) @@ -692,7 +691,7 @@ fFatBits->AddCrossHair(); // crosshair info needs to be added - // window resizes accordingly + // window resizes accordingly float width; float height; GetPreferredSize(&width, &height); @@ -704,9 +703,9 @@ TWindow::RemoveCrossHair() { fFatBits->RemoveCrossHair(); - + // crosshair info needs to be removed - // window resizes accordingly + // window resizes accordingly float width; float height; GetPreferredSize(&width, &height); @@ -734,7 +733,7 @@ { if (s == fPixelSize) return; - + fPixelSize = s; // resize window // tell info that size has changed @@ -762,7 +761,7 @@ float h = Bounds().Height(); CalcViewablePixels(); ResizeWindow(fHPixelCount, fVPixelCount); - + // the window might not actually change in size // in that case force the buffers to the new dimension if (w == Bounds().Width() && h == Bounds().Height()) @@ -811,7 +810,7 @@ text->Insert("Info:\n"); text->Insert(" hide/show info - hides/shows all these new features\n"); text->Insert(" note: when showing, a red square will appear which signifies\n"); - text->Insert(" which pixel's rgb values will be displayed\n"); + text->Insert(" which pixel's rgb values will be displayed\n"); text->Insert(" add/remove crosshairs - 2 crosshairs can be added (or removed)\n"); text->Insert(" to aid in the alignment and placement of objects.\n"); text->Insert(" The crosshairs are represented by blue squares and blue lines.\n"); @@ -836,7 +835,7 @@ text->Insert(" option-arrow key - moves the mouse location 1 pixel at a time\n"); text->Insert(" x marks the selection - the current selection has an 'x' in it\n"); - CenterWindowOnScreen(w); + CenterWindowOnScreen(w); w->Show(); } @@ -857,12 +856,12 @@ B_NO_BORDER) { SetFont(be_plain_font); - fFontHeight = FontHeight(this, true); + fFontHeight = FontHeight(this, true); fMagView = NULL; - + fSelectionColor = kBlack; fCH1Loc.x = fCH1Loc.y = fCH2Loc.x = fCH2Loc.y = 0; - + fInfoStr[0] = 0; fRGBStr[0] = 0; fCH1Str[0] = 0; @@ -881,9 +880,9 @@ BBox::AttachedToWindow(); dynamic_cast(Window())->PixelCount(&fHPixelCount, &fVPixelCount); - fPixelSize = dynamic_cast(Window())->PixelSize(); + fPixelSize = dynamic_cast(Window())->PixelSize(); - AddMenu(); + AddMenu(); } @@ -927,14 +926,14 @@ SetHighColor(0,0,0,255); strcpy(fRGBStr,str); DrawString(fRGBStr); - + bool ch1Showing, ch2Showing; dynamic_cast(Window())->CrossHairsShowing(&ch1Showing, &ch2Showing); - + if (fMagView) { BPoint pt1(fMagView->CrossHair1Loc()); BPoint pt2(fMagView->CrossHair2Loc()); - + float h = Bounds().Height(); if (ch2Showing) { MovePenTo(10, h-12); @@ -947,7 +946,7 @@ strcpy(fCH2Str,str); DrawString(fCH2Str); } - + if (ch1Showing && ch2Showing) { MovePenTo(10, h-10-fFontHeight-2); sprintf(str, "1) x: %li y: %li x: %i", (int32)pt1.x, (int32)pt1.y, @@ -969,7 +968,7 @@ DrawString(fCH1Str); } } - + PopState(); } @@ -1016,7 +1015,7 @@ } -void +void TMenu::AttachedToWindow() { bool state = true; @@ -1251,7 +1250,7 @@ BPopUpMenu *menu = new BPopUpMenu("Info"); menu->SetFont(be_plain_font); BuildInfoMenu(menu); - + BMenuItem *selected = menu->Go(ConvertToScreen(where)); if (selected) Window()->PostMessage(selected->Message()->what); @@ -1261,13 +1260,13 @@ // add a mousedown looper here - int32 pixelSize = PixelSize(); + int32 pixelSize = PixelSize(); float x = where.x / pixelSize; float y = where.y / pixelSize; MoveSelectionTo(x, y); - // draw the frozen image + // draw the frozen image // update the info region fNeedToUpdate = true; @@ -1290,7 +1289,7 @@ { if (fShowSelection == state) return; - + fShowSelection = state; fSelection = 0; Invalidate(); @@ -1659,10 +1658,10 @@ BFile file; BDirectory parentDir(ref); parentDir.CreateFile(name, &file); - + // write off the bitmaps bits to the file SaveBits(&file, fImageView->Bitmap(), "Data"); - + // unfreeze the image, image was frozen before invoke of FilePanel EndSave(); } @@ -1672,7 +1671,7 @@ TMagnify::SaveBits(BFile* file, const BBitmap *bitmap, char* name) const { int32 bytesPerPixel; - const char *kColorSpaceName; + const char *kColorSpaceName; switch (bitmap->ColorSpace()) { case B_GRAY8: @@ -1773,7 +1772,7 @@ fBytesPerPixel = 1; break; case B_RGB15: - case B_RGBA15: + case B_RGBA15: case B_RGB15_BIG: case B_RGBA15_BIG: case B_RGB16: @@ -1880,7 +1879,7 @@ DrawBitmap(fBitmap, srcRect, destRect); - DrawGrid(width, height, destRect, pixelSize); + DrawGrid(width, height, destRect, pixelSize); DrawSelection(); Sync(); @@ -1931,7 +1930,7 @@ // horizontal lines for (int32 i = pixelSize; i < (height * pixelSize); i += pixelSize) AddLine(BPoint(0, i), BPoint(destRect.right, i), kGridGray); - + // vertical lines for (int32 i = pixelSize; i < (width * pixelSize); i += pixelSize) AddLine(BPoint(i, 0), BPoint(i, destRect.bottom), kGridGray); @@ -1968,7 +1967,7 @@ if (selection == 0) { StrokeLine(BPoint(x,y), BPoint(x+squareSize,y+squareSize)); StrokeLine(BPoint(x,y+squareSize), BPoint(x+squareSize,y)); - } + } bool ch1Showing, ch2Showing; fParent->CrossHairsShowing(&ch1Showing, &ch2Showing); @@ -1992,7 +1991,7 @@ if (selection == 1) { StrokeLine(BPoint(x,y), BPoint(x+squareSize,y+squareSize)); StrokeLine(BPoint(x,y+squareSize), BPoint(x+squareSize,y)); - } + } } if (ch2Showing) { SetHighColor(kBlueColor); @@ -2014,7 +2013,7 @@ if (selection == 2) { StrokeLine(BPoint(x,y), BPoint(x+squareSize,y+squareSize)); StrokeLine(BPoint(x,y+squareSize), BPoint(x+squareSize,y)); - } + } } PopState(); @@ -2023,7 +2022,7 @@ rgb_color TOSMagnify::ColorAtSelection() -{ +{ float x, y; fParent->SelectionLoc(&x, &y); BRect srcRect(x, y, x, y); @@ -2033,7 +2032,7 @@ fPixelView->Sync(); fPixel->Unlock(); - uint32 pixel = *((uint32*)fPixel->Bits()); + uint32 pixel = *((uint32*)fPixel->Bits()); rgb_color c; c.alpha = pixel >> 24; c.red = (pixel >> 16) & 0xFF; @@ -2073,6 +2072,6 @@ } TApp app(pixelCount); - app.Run(); + app.Run(); return 0; } From julun at mail.berlios.de Fri Sep 12 01:09:46 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Fri, 12 Sep 2008 01:09:46 +0200 Subject: [Haiku-commits] r27426 - haiku/trunk/src/apps/magnify Message-ID: <200809112309.m8BN9kZx015456@sheep.berlios.de> Author: julun Date: 2008-09-12 01:09:45 +0200 (Fri, 12 Sep 2008) New Revision: 27426 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27426&view=rev Modified: haiku/trunk/src/apps/magnify/Magnify.cpp Log: * Bug #264 appeared again after I removed the disabled programmatically resize during user resize. Obviously we ported the bug over from BeOS, during the FrameResized call the preferred size of the window was calculated based on the current size of the window, calculating the same size FrameResized reported. Thus resulting in trying to resize it to the same size ending in an loop. It seems they worked arround the oversight using the outline resize thing. Modified: haiku/trunk/src/apps/magnify/Magnify.cpp =================================================================== --- haiku/trunk/src/apps/magnify/Magnify.cpp 2008-09-11 22:52:44 UTC (rev 27425) +++ haiku/trunk/src/apps/magnify/Magnify.cpp 2008-09-11 23:09:45 UTC (rev 27426) @@ -515,12 +515,6 @@ TWindow::FrameResized(float w, float h) { CalcViewablePixels(); - - float width; - float height; - GetPreferredSize(&width, &height); - ResizeTo(width, height); - fFatBits->InitBuffers(fHPixelCount, fVPixelCount, fPixelSize, ShowGrid()); } From leavengood at mail.berlios.de Fri Sep 12 06:13:33 2008 From: leavengood at mail.berlios.de (leavengood at BerliOS) Date: Fri, 12 Sep 2008 06:13:33 +0200 Subject: [Haiku-commits] r27427 - haiku/trunk/src/servers/print Message-ID: <200809120413.m8C4DXQQ005900@sheep.berlios.de> Author: leavengood Date: 2008-09-12 06:13:30 +0200 (Fri, 12 Sep 2008) New Revision: 27427 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27427&view=rev Modified: haiku/trunk/src/servers/print/ConfigWindow.cpp Log: Fixing CID 1305: the null check of fPageFormatText on line 483 was redundant since fPageFormatText is accessed in both branches of the if before the null check. If it was actually null there would be a crash well before line 483. In addition this member is initialized in the constructor. I assume the null check was added to provide symmetry with the null check of fJobSetupText below it. But that latter null check is needed since fJobSetupText may not have been created in the constructor. Modified: haiku/trunk/src/servers/print/ConfigWindow.cpp =================================================================== --- haiku/trunk/src/servers/print/ConfigWindow.cpp 2008-09-11 23:09:45 UTC (rev 27426) +++ haiku/trunk/src/servers/print/ConfigWindow.cpp 2008-09-12 04:13:30 UTC (rev 27427) @@ -480,11 +480,10 @@ fJobSetupText->ResizeToPreferred(); } } - if (fPageFormatText) { - if (fOk->Frame().right < fPageFormatText->Frame().right) - ResizeTo(fPageFormatText->Frame().right + 10, Bounds().bottom); - } + if (fOk->Frame().right < fPageFormatText->Frame().right) + ResizeTo(fPageFormatText->Frame().right + 10, Bounds().bottom); + if (fJobSetupText) { if (fOk->Frame().right < fJobSetupText->Frame().right) ResizeTo(fJobSetupText->Frame().right + 10, Bounds().bottom); From leavengood at mail.berlios.de Fri Sep 12 06:28:11 2008 From: leavengood at mail.berlios.de (leavengood at BerliOS) Date: Fri, 12 Sep 2008 06:28:11 +0200 Subject: [Haiku-commits] r27428 - haiku/trunk/src/system/kernel Message-ID: <200809120428.m8C4SBn3010823@sheep.berlios.de> Author: leavengood Date: 2008-09-12 06:28:09 +0200 (Fri, 12 Sep 2008) New Revision: 27428 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27428&view=rev Modified: haiku/trunk/src/system/kernel/thread.cpp Log: Fixed CID 1299: the char* name was used in a call to strtoul on line 1220 before being NULL checked on line 1234. I moved the null check to be after name is initialized and removed it from line 1234. Modified: haiku/trunk/src/system/kernel/thread.cpp =================================================================== --- haiku/trunk/src/system/kernel/thread.cpp 2008-09-12 04:13:30 UTC (rev 27427) +++ haiku/trunk/src/system/kernel/thread.cpp 2008-09-12 04:28:09 UTC (rev 27428) @@ -1218,31 +1218,32 @@ for (; argi < argc; argi++) { const char *name = argv[argi]; - int32 id = strtoul(name, NULL, 0); + if (name != NULL) { + int32 id = strtoul(name, NULL, 0); - if (IS_KERNEL_ADDRESS(id)) { - // semi-hack - _dump_thread_info((struct thread *)id, shortInfo); - continue; - } + if (IS_KERNEL_ADDRESS(id)) { + // semi-hack + _dump_thread_info((struct thread *)id, shortInfo); + continue; + } - // walk through the thread list, trying to match name or id - bool found = false; - struct hash_iterator i; - hash_open(sThreadHash, &i); - struct thread *thread; - while ((thread = (struct thread*)hash_next(sThreadHash, &i)) != NULL) { - if ((name != NULL && !strcmp(name, thread->name)) - || thread->id == id) { - _dump_thread_info(thread, shortInfo); - found = true; - break; + // walk through the thread list, trying to match name or id + bool found = false; + struct hash_iterator i; + hash_open(sThreadHash, &i); + struct thread *thread; + while ((thread = (struct thread*)hash_next(sThreadHash, &i)) != NULL) { + if (!strcmp(name, thread->name) || thread->id == id) { + _dump_thread_info(thread, shortInfo); + found = true; + break; + } } + hash_close(sThreadHash, &i, false); + + if (!found) + kprintf("thread \"%s\" (%ld) doesn't exist!\n", name, id); } - hash_close(sThreadHash, &i, false); - - if (!found) - kprintf("thread \"%s\" (%ld) doesn't exist!\n", name, id); } return 0; From leavengood at mail.berlios.de Fri Sep 12 06:40:39 2008 From: leavengood at mail.berlios.de (leavengood at BerliOS) Date: Fri, 12 Sep 2008 06:40:39 +0200 Subject: [Haiku-commits] r27429 - haiku/trunk/src/system/kernel/device_manager Message-ID: <200809120440.m8C4edYC025511@sheep.berlios.de> Author: leavengood Date: 2008-09-12 06:40:37 +0200 (Fri, 12 Sep 2008) New Revision: 27429 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27429&view=rev Modified: haiku/trunk/src/system/kernel/device_manager/device_manager.cpp Log: Fixed CID 1300: the pointer last is never modified in the loop, so there is no need for a null check. Or the null check needs to be moved to after last is initialized. But if the user_memcpy of cookie succeeds, last should not be null since it is just a copy of cookie. Probably. Modified: haiku/trunk/src/system/kernel/device_manager/device_manager.cpp =================================================================== --- haiku/trunk/src/system/kernel/device_manager/device_manager.cpp 2008-09-12 04:28:09 UTC (rev 27428) +++ haiku/trunk/src/system/kernel/device_manager/device_manager.cpp 2008-09-12 04:40:37 UTC (rev 27429) @@ -461,7 +461,7 @@ NodeList::ConstIterator iterator = last->Parent()->Children().GetIterator(); // skip those we already traversed - while (iterator.HasNext() && last != NULL) { + while (iterator.HasNext()) { device_node* node = iterator.Next(); if (node == last) From leavengood at mail.berlios.de Fri Sep 12 06:44:58 2008 From: leavengood at mail.berlios.de (leavengood at BerliOS) Date: Fri, 12 Sep 2008 06:44:58 +0200 Subject: [Haiku-commits] r27430 - haiku/trunk/src/add-ons/kernel/bus_managers/usb Message-ID: <200809120444.m8C4iw0p029572@sheep.berlios.de> Author: leavengood Date: 2008-09-12 06:44:55 +0200 (Fri, 12 Sep 2008) New Revision: 27430 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27430&view=rev Modified: haiku/trunk/src/add-ons/kernel/bus_managers/usb/BusManager.cpp Log: Fixed CID 1301: we should probably have the null check of defaultPipe before it is first dereferenced... Modified: haiku/trunk/src/add-ons/kernel/bus_managers/usb/BusManager.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/usb/BusManager.cpp 2008-09-12 04:40:37 UTC (rev 27429) +++ haiku/trunk/src/add-ons/kernel/bus_managers/usb/BusManager.cpp 2008-09-12 04:44:55 UTC (rev 27430) @@ -124,7 +124,6 @@ TRACE(("USB BusManager: setting device address to %d\n", deviceAddress)); ControlPipe *defaultPipe = _GetDefaultPipe(speed); - defaultPipe->SetHubInfo(hubAddress, hubPort); if (!defaultPipe) { TRACE_ERROR(("USB BusManager: error getting the default pipe for speed %d\n", (int)speed)); @@ -132,6 +131,8 @@ return NULL; } + defaultPipe->SetHubInfo(hubAddress, hubPort); + status_t result = B_ERROR; for (int32 i = 0; i < 3; i++) { // Set the address of the device USB 1.1 spec p202 From leavengood at mail.berlios.de Fri Sep 12 07:20:52 2008 From: leavengood at mail.berlios.de (leavengood at BerliOS) Date: Fri, 12 Sep 2008 07:20:52 +0200 Subject: [Haiku-commits] r27431 - haiku/trunk/src/preferences/print Message-ID: <200809120520.m8C5KqDs006988@sheep.berlios.de> Author: leavengood Date: 2008-09-12 07:20:49 +0200 (Fri, 12 Sep 2008) New Revision: 27431 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27431&view=rev Modified: haiku/trunk/src/preferences/print/PrinterListView.cpp Log: Fixed CID 1298: In the case that sSelectedIcon is not valid, checkMark could be leaked. So I reorganized the if statement to remove this possibility. Modified: haiku/trunk/src/preferences/print/PrinterListView.cpp =================================================================== --- haiku/trunk/src/preferences/print/PrinterListView.cpp 2008-09-12 04:44:55 UTC (rev 27430) +++ haiku/trunk/src/preferences/print/PrinterListView.cpp 2008-09-12 05:20:49 UTC (rev 27431) @@ -252,21 +252,22 @@ if (sIcon && sIcon->IsValid() && sSelectedIcon == NULL) { BBitmap *checkMark = LoadBitmap("check_mark_icon", 'BBMP'); - sSelectedIcon = new BBitmap(rect, B_RGBA32, true); - if (checkMark && checkMark->IsValid() - && sSelectedIcon && sSelectedIcon->IsValid()) { - // draw check mark at bottom left over printer icon - BView *view = new BView(rect, "offscreen", B_FOLLOW_ALL, B_WILL_DRAW); - float y = rect.Height() - checkMark->Bounds().Height(); - sSelectedIcon->Lock(); - sSelectedIcon->AddChild(view); - view->DrawBitmap(sIcon); - view->SetDrawingMode(B_OP_ALPHA); - view->DrawBitmap(checkMark, BPoint(0, y)); - view->Sync(); - view->RemoveSelf(); - sSelectedIcon->Unlock(); - delete view; + if (checkMark && checkMark->IsValid()) { + sSelectedIcon = new BBitmap(rect, B_RGBA32, true); + if (sSelectedIcon && sSelectedIcon->IsValid()) { + // draw check mark at bottom left over printer icon + BView *view = new BView(rect, "offscreen", B_FOLLOW_ALL, B_WILL_DRAW); + float y = rect.Height() - checkMark->Bounds().Height(); + sSelectedIcon->Lock(); + sSelectedIcon->AddChild(view); + view->DrawBitmap(sIcon); + view->SetDrawingMode(B_OP_ALPHA); + view->DrawBitmap(checkMark, BPoint(0, y)); + view->Sync(); + view->RemoveSelf(); + sSelectedIcon->Unlock(); + delete view; + } delete checkMark; } } From leavengood at mail.berlios.de Fri Sep 12 07:29:29 2008 From: leavengood at mail.berlios.de (leavengood at BerliOS) Date: Fri, 12 Sep 2008 07:29:29 +0200 Subject: [Haiku-commits] r27432 - haiku/trunk/src/apps/mediaplayer/media_node_framework/video Message-ID: <200809120529.m8C5TTO1015519@sheep.berlios.de> Author: leavengood Date: 2008-09-12 07:29:27 +0200 (Fri, 12 Sep 2008) New Revision: 27432 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27432&view=rev Modified: haiku/trunk/src/apps/mediaplayer/media_node_framework/video/VideoConsumer.cpp Log: Fixed CID 1297: the buffList array was never deleted. Modified: haiku/trunk/src/apps/mediaplayer/media_node_framework/video/VideoConsumer.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/media_node_framework/video/VideoConsumer.cpp 2008-09-12 05:20:49 UTC (rev 27431) +++ haiku/trunk/src/apps/mediaplayer/media_node_framework/video/VideoConsumer.cpp 2008-09-12 05:29:27 UTC (rev 27432) @@ -293,6 +293,8 @@ } } else ERROR("VideoConsumer::CreateBuffers ERROR IN GET BUFFER LIST\n"); + + delete[] buffList; FUNCTION("VideoConsumer::CreateBuffers - EXIT\n"); return status; From leavengood at mail.berlios.de Fri Sep 12 08:10:56 2008 From: leavengood at mail.berlios.de (leavengood at BerliOS) Date: Fri, 12 Sep 2008 08:10:56 +0200 Subject: [Haiku-commits] r27433 - haiku/trunk/src/apps/text_search Message-ID: <200809120610.m8C6AuMa029284@sheep.berlios.de> Author: leavengood Date: 2008-09-12 08:10:56 +0200 (Fri, 12 Sep 2008) New Revision: 27433 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27433&view=rev Modified: haiku/trunk/src/apps/text_search/GrepWindow.cpp Log: Fixed CID 1294 and 1295: delete the entry_ref on the terminating conditions. Modified: haiku/trunk/src/apps/text_search/GrepWindow.cpp =================================================================== --- haiku/trunk/src/apps/text_search/GrepWindow.cpp 2008-09-12 05:29:27 UTC (rev 27432) +++ haiku/trunk/src/apps/text_search/GrepWindow.cpp 2008-09-12 06:10:56 UTC (rev 27433) @@ -1733,8 +1733,10 @@ if (status == B_OK) windowList.AddItem(static_cast(tracker_ref)); - if (status != B_OK) + if (status != B_OK) { + delete tracker_ref; break; + } } int32 folderCount = folderList->CountItems(); @@ -1830,8 +1832,10 @@ entry_ref *windowRef = new entry_ref; status = windowReplyMessage.FindRef("result", windowRef); - if (status != B_OK) + if (status != B_OK) { + delete windowRef; break; + } int32 folderCount = folderList->CountItems(); From michael.w.pfeiffer at gmail.com Fri Sep 12 08:16:32 2008 From: michael.w.pfeiffer at gmail.com (Michael Pfeiffer) Date: Fri, 12 Sep 2008 08:16:32 +0200 Subject: [Haiku-commits] r27431 - haiku/trunk/src/preferences/print In-Reply-To: <200809120520.m8C5KqDs006988@sheep.berlios.de> References: <200809120520.m8C5KqDs006988@sheep.berlios.de> Message-ID: <4BB1BE2D-7DDF-41B9-9F5F-B5A025993D57@gmail.com> Am 12.09.2008 um 07:20 schrieb leavengood at BerliOS: > Author: leavengood > Date: 2008-09-12 07:20:49 +0200 (Fri, 12 Sep 2008) > New Revision: 27431 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27431&view=rev > > Modified: > haiku/trunk/src/preferences/print/PrinterListView.cpp > Log: > Fixed CID 1298: In the case that sSelectedIcon is not valid, > checkMark could be > leaked. So I reorganized the if statement to remove this possibility. > > > > + if (checkMark && checkMark->IsValid()) { > ... > + } > delete checkMark; > } checkMark is still leaked, if it is not NULL but "invalid". Moving the delete statement after the if statement should fix it. - Michael From leavengood at mail.berlios.de Fri Sep 12 08:21:34 2008 From: leavengood at mail.berlios.de (leavengood at BerliOS) Date: Fri, 12 Sep 2008 08:21:34 +0200 Subject: [Haiku-commits] r27434 - haiku/trunk/src/kits/device Message-ID: <200809120621.m8C6LYDK031318@sheep.berlios.de> Author: leavengood Date: 2008-09-12 08:21:34 +0200 (Fri, 12 Sep 2008) New Revision: 27434 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27434&view=rev Modified: haiku/trunk/src/kits/device/Joystick.cpp Log: Fixed CID 1290 and 1291: the temp BString is initialized with a new BString and then immediately replaced. A later null check ensures it is OK to initialize it to NULL. Also fixed a GCC warning about comparison between signed and unsigned. Modified: haiku/trunk/src/kits/device/Joystick.cpp =================================================================== --- haiku/trunk/src/kits/device/Joystick.cpp 2008-09-12 06:10:56 UTC (rev 27433) +++ haiku/trunk/src/kits/device/Joystick.cpp 2008-09-12 06:21:34 UTC (rev 27434) @@ -165,14 +165,14 @@ BJoystick::GetDeviceName(int32 n, char *name, size_t bufSize) { CALLED(); - BString *temp = new BString(); + BString *temp = NULL; if (fDevices != NULL && fDevices->CountItems() > n) temp = static_cast(fDevices->ItemAt(n)); else return B_BAD_INDEX; if (temp != NULL && name != NULL) { - if(temp->Length() > bufSize) + if(temp->Length() > (int32)bufSize) return B_NAME_TOO_LONG; strncpy(name, temp->String(), bufSize); name[bufSize - 1] = '\0'; From leavengood at mail.berlios.de Fri Sep 12 08:30:08 2008 From: leavengood at mail.berlios.de (leavengood at BerliOS) Date: Fri, 12 Sep 2008 08:30:08 +0200 Subject: [Haiku-commits] r27435 - haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid Message-ID: <200809120630.m8C6U8j3032420@sheep.berlios.de> Author: leavengood Date: 2008-09-12 08:30:07 +0200 (Fri, 12 Sep 2008) New Revision: 27435 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27435&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/DeviceList.cpp Log: Fixed CID 1289: if name cannot be strdup'ed, we should delete entry before returning B_NO_MEMORY; Modified: haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/DeviceList.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/DeviceList.cpp 2008-09-12 06:21:34 UTC (rev 27434) +++ haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/DeviceList.cpp 2008-09-12 06:30:07 UTC (rev 27435) @@ -45,8 +45,10 @@ return B_NO_MEMORY; entry->name = strdup(name); - if (entry->name == NULL) + if (entry->name == NULL) { + delete entry; return B_NO_MEMORY; + } entry->device = device; entry->next = NULL; From leavengood at mail.berlios.de Fri Sep 12 08:34:39 2008 From: leavengood at mail.berlios.de (leavengood at BerliOS) Date: Fri, 12 Sep 2008 08:34:39 +0200 Subject: [Haiku-commits] r27436 - haiku/trunk/src/preferences/print Message-ID: <200809120634.m8C6YdVM000143@sheep.berlios.de> Author: leavengood Date: 2008-09-12 08:34:39 +0200 (Fri, 12 Sep 2008) New Revision: 27436 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27436&view=rev Modified: haiku/trunk/src/preferences/print/PrinterListView.cpp Log: Apply Michael Pfeiffer's advice and move the delete outside the if. Modified: haiku/trunk/src/preferences/print/PrinterListView.cpp =================================================================== --- haiku/trunk/src/preferences/print/PrinterListView.cpp 2008-09-12 06:30:07 UTC (rev 27435) +++ haiku/trunk/src/preferences/print/PrinterListView.cpp 2008-09-12 06:34:39 UTC (rev 27436) @@ -268,8 +268,8 @@ sSelectedIcon->Unlock(); delete view; } - delete checkMark; } + delete checkMark; } // Get Name of printer From leavengood at gmail.com Fri Sep 12 08:35:12 2008 From: leavengood at gmail.com (Ryan Leavengood) Date: Fri, 12 Sep 2008 02:35:12 -0400 Subject: [Haiku-commits] r27431 - haiku/trunk/src/preferences/print In-Reply-To: <4BB1BE2D-7DDF-41B9-9F5F-B5A025993D57@gmail.com> References: <200809120520.m8C5KqDs006988@sheep.berlios.de> <4BB1BE2D-7DDF-41B9-9F5F-B5A025993D57@gmail.com> Message-ID: On Fri, Sep 12, 2008 at 2:16 AM, Michael Pfeiffer wrote: > > checkMark is still leaked, if it is not NULL but "invalid". > Moving the delete statement after the if statement should fix it. OK fixed in r27436. Ryan From leavengood at mail.berlios.de Fri Sep 12 08:43:08 2008 From: leavengood at mail.berlios.de (leavengood at BerliOS) Date: Fri, 12 Sep 2008 08:43:08 +0200 Subject: [Haiku-commits] r27437 - haiku/trunk/src/system/kernel/messaging Message-ID: <200809120643.m8C6h8mp001150@sheep.berlios.de> Author: leavengood Date: 2008-09-12 08:43:07 +0200 (Fri, 12 Sep 2008) New Revision: 27437 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27437&view=rev Modified: haiku/trunk/src/system/kernel/messaging/KMessage.cpp Log: Fixed CID 1306: initialize size to 0. Modified: haiku/trunk/src/system/kernel/messaging/KMessage.cpp =================================================================== --- haiku/trunk/src/system/kernel/messaging/KMessage.cpp 2008-09-12 06:34:39 UTC (rev 27436) +++ haiku/trunk/src/system/kernel/messaging/KMessage.cpp 2008-09-12 06:43:07 UTC (rev 27437) @@ -630,7 +630,7 @@ if (field.CountElements() != 1) printFunc("\n"); - int32 size; + int32 size = 0; for (int i = 0; const void* data = field.ElementAt(i, &size); i++) { if (field.CountElements() != 1) printFunc(" [%2d] ", i); From modeenf at mail.berlios.de Fri Sep 12 09:07:02 2008 From: modeenf at mail.berlios.de (modeenf at mail.berlios.de) Date: Fri, 12 Sep 2008 09:07:02 +0200 Subject: [Haiku-commits] r27438 - haiku/trunk/src/kits/device Message-ID: <200809120707.m8C772MB003332@sheep.berlios.de> Author: modeenf Date: 2008-09-12 09:07:00 +0200 (Fri, 12 Sep 2008) New Revision: 27438 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27438&view=rev Modified: haiku/trunk/src/kits/device/SerialPort.cpp Log: Fixed CID 1031: removed check _fDevice for NULL as we do new BList in constructor also removed temp var count as _fDevice->CountItems() should return 0 if empty Modified: haiku/trunk/src/kits/device/SerialPort.cpp =================================================================== --- haiku/trunk/src/kits/device/SerialPort.cpp 2008-09-12 06:43:07 UTC (rev 27437) +++ haiku/trunk/src/kits/device/SerialPort.cpp 2008-09-12 07:07:00 UTC (rev 27438) @@ -479,15 +479,9 @@ int32 BSerialPort::CountDevices() { - int32 count = 0; - // Refresh devices list ScanDevices(); - - if (_fDevices != NULL) - count = _fDevices->CountItems(); - - return count; + return _fDevices->CountItems(); } From jackburton at mail.berlios.de Fri Sep 12 09:34:39 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Fri, 12 Sep 2008 09:34:39 +0200 Subject: [Haiku-commits] r27439 - haiku/trunk/src/kits/interface Message-ID: <200809120734.m8C7YdbV005482@sheep.berlios.de> Author: jackburton Date: 2008-09-12 09:34:37 +0200 (Fri, 12 Sep 2008) New Revision: 27439 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27439&view=rev Modified: haiku/trunk/src/kits/interface/TextView.cpp Log: buffer is an array, so use delete[]. CID 130 Modified: haiku/trunk/src/kits/interface/TextView.cpp =================================================================== --- haiku/trunk/src/kits/interface/TextView.cpp 2008-09-12 07:07:00 UTC (rev 27438) +++ haiku/trunk/src/kits/interface/TextView.cpp 2008-09-12 07:34:37 UTC (rev 27439) @@ -4385,9 +4385,10 @@ reply->what = B_REPLY; reply->AddString("result", buffer); - delete buffer; reply->AddInt32("error", B_OK); + delete[] buffer; + return true; } else if (strcmp(property, "text_run_array") == 0) return false; From axeld at pinc-software.de Fri Sep 12 09:43:44 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Fri, 12 Sep 2008 09:43:44 +0200 CEST Subject: [Haiku-commits] r27437 - haiku/trunk/src/system/kernel/messaging In-Reply-To: <200809120643.m8C6h8mp001150@sheep.berlios.de> Message-ID: <820564028-BeMail@zon> leavengood at BerliOS wrote: > Log: > Fixed CID 1306: initialize size to 0. [...] > > > Modified: haiku/trunk/src/system/kernel/messaging/KMessage.cpp > =================================================================== > --- haiku/trunk/src/system/kernel/messaging/KMessage.cpp 2008-09-12 > 06:34:39 UTC (rev 27436) > +++ haiku/trunk/src/system/kernel/messaging/KMessage.cpp 2008-09-12 > 06:43:07 UTC (rev > 27437) > @@ -630,7 +630,7 @@ > if (field.CountElements() != 1) > printFunc("\n"); > > - int32 size; > + int32 size = 0; > for (int i = 0; const void* data = field.ElementAt(i, &size); i > ++) { > if (field.CountElements() != 1) There was actually no bug. ElementAt() would have initialized "size", and it's not used anywhere else; before changing code like this just because a Coverity report, please mark the bug invalid instead. Bye, Axel. From axeld at pinc-software.de Fri Sep 12 09:49:29 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Fri, 12 Sep 2008 09:49:29 +0200 CEST Subject: [Haiku-commits] r27428 - haiku/trunk/src/system/kernel In-Reply-To: <200809120428.m8C4SBn3010823@sheep.berlios.de> Message-ID: <1165375134-BeMail@zon> leavengood at BerliOS wrote: > Log: > Fixed CID 1299: the char* name was used in a call to strtoul on line > 1220 > before being NULL checked on line 1234. I moved the null check to be > after name > is initialized and removed it from line 1234. [...] > for (; argi < argc; argi++) { > const char *name = argv[argi]; > - int32 id = strtoul(name, NULL, 0); > + if (name != NULL) { > + int32 id = strtoul(name, NULL, 0); That's not really necessary; correct would have been to remove the NULL check altogether, as valid arguments (within the range) are never NULL. Bye, Axel. From jackburton at mail.berlios.de Fri Sep 12 10:09:15 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Fri, 12 Sep 2008 10:09:15 +0200 Subject: [Haiku-commits] r27440 - haiku/trunk/src/kits/interface Message-ID: <200809120809.m8C89FH3010233@sheep.berlios.de> Author: jackburton Date: 2008-09-12 10:09:13 +0200 (Fri, 12 Sep 2008) New Revision: 27440 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27440&view=rev Modified: haiku/trunk/src/kits/interface/Menu.cpp Log: buttons could be used initialized if locking the looper failed (CID 1134) Modified: haiku/trunk/src/kits/interface/Menu.cpp =================================================================== --- haiku/trunk/src/kits/interface/Menu.cpp 2008-09-12 07:34:37 UTC (rev 27439) +++ haiku/trunk/src/kits/interface/Menu.cpp 2008-09-12 08:09:13 UTC (rev 27440) @@ -1407,7 +1407,7 @@ fSuper->fState = MENU_STATE_TRACKING_SUBMENU; BPoint location; - uint32 buttons; + uint32 buttons = 0; if (LockLooper()) { GetMouse(&location, &buttons); UnlockLooper(); From mmlr at mlotz.ch Fri Sep 12 10:34:44 2008 From: mmlr at mlotz.ch (Michael Lotz) Date: Fri, 12 Sep 2008 10:34:44 +0200 Subject: [Haiku-commits] r27438 - haiku/trunk/src/kits/device In-Reply-To: <200809120707.m8C772MB003332@sheep.berlios.de> References: <200809120707.m8C772MB003332@sheep.berlios.de> Message-ID: <20080912083034.M82200@mlotz.ch> On Fri, 12 Sep 2008 09:07:02 +0200, modeenf wrote > Author: modeenf > Date: 2008-09-12 09:07:00 +0200 (Fri, 12 Sep 2008) > New Revision: 27438 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27438&view=rev > > Modified: > haiku/trunk/src/kits/device/SerialPort.cpp > Log: > Fixed CID 1031: removed check _fDevice for NULL as we do new BList > in constructor also removed temp var count as _fDevice->CountItems() > should return 0 if empty And what if the new (which should really be new(std::nothrow) instead) fails because there's no memory? In that case you'd still have NULL in there. So instead of removing such checks I'd think it'd be better to instead also add them in the other places that use that member. Regards Michael From axeld at mail.berlios.de Fri Sep 12 11:25:18 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Fri, 12 Sep 2008 11:25:18 +0200 Subject: [Haiku-commits] r27441 - haiku/trunk/src/add-ons/kernel/file_systems/bfs Message-ID: <200809120925.m8C9PItE016862@sheep.berlios.de> Author: axeld Date: 2008-09-12 11:25:17 +0200 (Fri, 12 Sep 2008) New Revision: 27441 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27441&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.cpp Log: * Reverted r27196 and solved it differently (in a more robust way): instead of guessing that the first attribute will be a name attribute, fCurrentSmallData now takes hidden attributes into account. * I haven't tested this change, though, so if it messes things up again, please yell at me :-) Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.cpp 2008-09-12 08:09:13 UTC (rev 27440) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.cpp 2008-09-12 09:25:17 UTC (rev 27441) @@ -2599,16 +2599,13 @@ RecursiveLocker _(&fInode->SmallDataLock()); - int32 i = 0; - for (;;item = item->Next()) { - if (item->IsLast(node)) - break; - + int32 index = 0; + for (; !item->IsLast(node); item = item->Next(), index++) { if (item->NameSize() == FILE_NAME_NAME_LENGTH && *item->Name() == FILE_NAME_NAME) continue; - if (i++ == fCurrentSmallData) + if (index >= fCurrentSmallData) break; } @@ -2618,15 +2615,12 @@ *_length = item->NameSize(); *_id = (ino_t)fCurrentSmallData; - fCurrentSmallData = i; + fCurrentSmallData = index; + return B_OK; } - else { - // stop traversing the small_data section - fCurrentSmallData = -1; - } - if (fCurrentSmallData != -1) - return B_OK; + // stop traversing the small_data section + fCurrentSmallData = -1; } // read attributes out of the attribute directory @@ -2641,7 +2635,7 @@ if (get_vnode(volume->FSVolume(), volume->ToVnode(fInode->Attributes()), (void**)&fAttributes) != B_OK) { FATAL(("get_vnode() failed in AttributeIterator::GetNext(ino_t" - " = %Ld,name = \"%s\")\n",fInode->ID(),name)); + " = %Ld,name = \"%s\")\n", fInode->ID(), name)); return B_ENTRY_NOT_FOUND; } @@ -2649,7 +2643,7 @@ if (fAttributes->GetTree(&tree) < B_OK || (fIterator = new TreeIterator(tree)) == NULL) { FATAL(("could not get tree in AttributeIterator::GetNext(ino_t" - " = %Ld,name = \"%s\")\n",fInode->ID(),name)); + " = %Ld,name = \"%s\")\n", fInode->ID(), name)); return B_ENTRY_NOT_FOUND; } } @@ -2661,7 +2655,7 @@ if (status < B_OK) return status; - Vnode vnode(volume,id); + Vnode vnode(volume, id); Inode* attribute; if ((status = vnode.Get(&attribute)) == B_OK) { *_type = attribute->Type(); @@ -2676,11 +2670,8 @@ void AttributeIterator::Update(uint16 index, int8 change) { - // fCurrentSmallData points already to the next item. OTOH, index is always - // the position when considering the special name attribute while the - // attribute iterators do ignore that (they always start at the second - // position in the small data section, not the first). - if (index <= fCurrentSmallData) + // fCurrentSmallData points already to the next item + if (index < fCurrentSmallData) fCurrentSmallData += change; } From axeld at pinc-software.de Fri Sep 12 11:25:00 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Fri, 12 Sep 2008 11:25:00 +0200 CEST Subject: [Haiku-commits] =?utf-8?q?r27196_-_haiku/trunk/src/add-ons/kernel?= =?utf-8?q?/file=5Fsystems/bfs?= In-Reply-To: <200808251225.m7PCPG7t015584@sheep.berlios.de> Message-ID: <6896401179-BeMail@zon> bga at BerliOS wrote: > Log: > - AttributeIterator::Update() now take into account differences > between its > view of the small data section and the outside view. > > Long version: > > AttributeIterator is a higher level class designed to make it easy to > iterate > through attributes in the small data section. The first attribute in > the small > data section is the special "name" attribute that is used to > reconstruct the > node path when you only have a node handy. As this attribute is not > user > visible nor user modifiable (except by changing a node name of > course), it is > considered a special attribute so the AttributeIterator class ignores > it and > starts iterating from the second attribute on. > > As opposed to this, internally the Inode class accesses the small > data section > directly without using the AttributeIterator class so whenever it > indexes items > in the small data section, it takes into account the special "name" > attribute. > > This creates a off-by-one relationship between those 2 > representations and this > was a problem because whenever the small data section changed, all > iterators > had to be updated (through a call to AttributeIterator::Update() > having an > index parameter that represented the outside view and not the > AttributeIterator > view, so iterators would not be adjusted correctly and the end result > is that > every other attribute was not removed from the index. This would > cause all > types of havoc with indexes, the simplest one being that entries in > indexes > would point to non-existing nodes. The investigation is correct, but the solution is not really that nice, as it makes assumptions that aren't made anywhere else, and also aren't enforced anywhere else (they currently just happen to be true). A much better solution would have been to take fCurrentSmallData hidden attributes into account. I've done so now in r27441. Bye, Axel. From emitrax at gmail.com Fri Sep 12 11:33:48 2008 From: emitrax at gmail.com (Salvatore Benedetto) Date: Fri, 12 Sep 2008 09:33:48 +0000 Subject: [Haiku-commits] r27441 - haiku/trunk/src/add-ons/kernel/file_systems/bfs In-Reply-To: <200809120925.m8C9PItE016862@sheep.berlios.de> References: <200809120925.m8C9PItE016862@sheep.berlios.de> Message-ID: 2008/9/12 axeld at BerliOS : > Author: axeld > Date: 2008-09-12 11:25:17 +0200 (Fri, 12 Sep 2008) > New Revision: 27441 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27441&view=rev > > Modified: > haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.cpp > Log: > * Reverted r27196 and solved it differently (in a more robust way): instead of > guessing that the first attribute will be a name attribute, fCurrentSmallData > now takes hidden attributes into account. > * I haven't tested this change, though, so if it messes things up again, please > yell at me :-) You should set a good example for newcomers devs and always test the code before committing it. Especially if it can corrupt data. ;-p Regards, -- Salvatore Benedetto (a.k.a. emitrax) Student of Computer Engineer University of Pisa www.haiku-os.it From jackburton at mail.berlios.de Fri Sep 12 11:34:00 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Fri, 12 Sep 2008 11:34:00 +0200 Subject: [Haiku-commits] r27442 - haiku/trunk/src/apps/expander Message-ID: <200809120934.m8C9Y0Hl017712@sheep.berlios.de> Author: jackburton Date: 2008-09-12 11:33:59 +0200 (Fri, 12 Sep 2008) New Revision: 27442 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27442&view=rev Modified: haiku/trunk/src/apps/expander/GenericThread.cpp Log: gcc4 noticed GenericThread::GetName() was returning a pointer to a local variable. No code is using this function, so it's safe to strdup() it. This class needs a serious restyling, though, as it doesn't conform to our coding guidelines Modified: haiku/trunk/src/apps/expander/GenericThread.cpp =================================================================== --- haiku/trunk/src/apps/expander/GenericThread.cpp 2008-09-12 09:25:17 UTC (rev 27441) +++ haiku/trunk/src/apps/expander/GenericThread.cpp 2008-09-12 09:33:59 UTC (rev 27442) @@ -313,7 +313,7 @@ { thread_info t_thread_info; GetInfo(& t_thread_info); - return (t_thread_info.name); + return strdup(t_thread_info.name); } thread_state From jackburton at mail.berlios.de Fri Sep 12 11:34:49 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Fri, 12 Sep 2008 11:34:49 +0200 Subject: [Haiku-commits] r27443 - haiku/trunk/src/apps/expander Message-ID: <200809120934.m8C9Ynfb017834@sheep.berlios.de> Author: jackburton Date: 2008-09-12 11:34:47 +0200 (Fri, 12 Sep 2008) New Revision: 27443 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27443&view=rev Modified: haiku/trunk/src/apps/expander/GenericThread.cpp Log: build fix Modified: haiku/trunk/src/apps/expander/GenericThread.cpp =================================================================== --- haiku/trunk/src/apps/expander/GenericThread.cpp 2008-09-12 09:33:59 UTC (rev 27442) +++ haiku/trunk/src/apps/expander/GenericThread.cpp 2008-09-12 09:34:47 UTC (rev 27443) @@ -3,6 +3,8 @@ #include "GenericThread.h" +#include + GenericThread::GenericThread(const char * a_thread_name, int32 a_priority, BMessage * a_message) : m_thread_data_store(a_message), From axeld at pinc-software.de Fri Sep 12 11:44:57 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Fri, 12 Sep 2008 11:44:57 +0200 CEST Subject: [Haiku-commits] r27196 - haiku/trunk/src/add-ons/kernel/file_systems/bfs In-Reply-To: <6896401179-BeMail@zon> Message-ID: <8093086262-BeMail@zon> bga at BerliOS wrote: > This creates a off-by-one relationship between those 2 > representations and this was a problem because whenever the small > data section changed, all iterators had to be updated (through a call > to AttributeIterator::Update() having an index parameter that > represented > the outside view and not the AttributeIterator view, so iterators > would not > be adjusted correctly and the end result is that every other > attribute was > not removed from the index. This would cause all types of havoc with > indexes, the simplest one being that entries in indexes would point > to > non-existing nodes. While the AttributeIterator class was wrong in this regard, I honestly don't see the connection to a messed up index. The worst that could happen was that an attribute was either hidden or twice in a "listattr" call. The AttributeIterator class is not used anywhere else. Can you elaborate how this could possibly happen? Bye, Axel. From axeld at mail.berlios.de Fri Sep 12 11:53:58 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Fri, 12 Sep 2008 11:53:58 +0200 Subject: [Haiku-commits] r27444 - haiku/trunk/src/add-ons/kernel/file_systems/bfs Message-ID: <200809120953.m8C9rwX8020037@sheep.berlios.de> Author: axeld Date: 2008-09-12 11:53:58 +0200 (Fri, 12 Sep 2008) New Revision: 27444 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27444&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.cpp Log: * Improved reported inode number to the be actual index. Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.cpp 2008-09-12 09:34:47 UTC (rev 27443) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.cpp 2008-09-12 09:53:58 UTC (rev 27444) @@ -2613,9 +2613,9 @@ strncpy(name, item->Name(), B_FILE_NAME_LENGTH); *_type = item->Type(); *_length = item->NameSize(); - *_id = (ino_t)fCurrentSmallData; + *_id = (ino_t)index; - fCurrentSmallData = index; + fCurrentSmallData = index + 1; return B_OK; } From jackburton at mail.berlios.de Fri Sep 12 11:55:03 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Fri, 12 Sep 2008 11:55:03 +0200 Subject: [Haiku-commits] r27445 - haiku/trunk/src/apps/expander Message-ID: <200809120955.m8C9t3Pv020103@sheep.berlios.de> Author: jackburton Date: 2008-09-12 11:55:02 +0200 (Fri, 12 Sep 2008) New Revision: 27445 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27445&view=rev Modified: haiku/trunk/src/apps/expander/GenericThread.cpp haiku/trunk/src/apps/expander/GenericThread.h Log: First round of style changes: renamed all member variables from m_var_name to fVarName Modified: haiku/trunk/src/apps/expander/GenericThread.cpp =================================================================== --- haiku/trunk/src/apps/expander/GenericThread.cpp 2008-09-12 09:53:58 UTC (rev 27444) +++ haiku/trunk/src/apps/expander/GenericThread.cpp 2008-09-12 09:55:02 UTC (rev 27445) @@ -5,25 +5,27 @@ #include -GenericThread::GenericThread(const char * a_thread_name, int32 a_priority, BMessage * a_message) +GenericThread::GenericThread(const char * thread_name, int32 a_priority, BMessage * message) : - m_thread_data_store(a_message), - m_thread_id(spawn_thread(private_thread_function, a_thread_name, a_priority, this)), - m_execute_unit(create_sem(1, "m_execute_unit")), - m_quit_requested(false), - m_thread_is_paused(false) + fThreadDataStore(message), + fThreadId(spawn_thread(private_thread_function, thread_name, a_priority, this)), + fExecuteUnit(create_sem(1, "ExecuteUnit sem")), + fQuitRequested(false), + fThreadIsPaused(false) { - if (m_thread_data_store == NULL) - m_thread_data_store = new BMessage(); + if (fThreadDataStore == NULL) + fThreadDataStore = new BMessage(); } + GenericThread::~GenericThread() { - kill_thread(m_thread_id); + kill_thread(fThreadId); - delete_sem(m_execute_unit); + delete_sem(fExecuteUnit); } + status_t GenericThread::ThreadFunction(void) { @@ -65,6 +67,7 @@ return (B_OK); } + status_t GenericThread::ThreadStartup(void) { @@ -87,6 +90,7 @@ return B_OK; } + status_t GenericThread::ThreadShutdown(void) { @@ -96,6 +100,7 @@ return B_OK; } + void GenericThread::ThreadStartupFailed(status_t a_status) { @@ -105,6 +110,7 @@ Quit(); } + void GenericThread::ExecuteUnitFailed(status_t a_status) { @@ -114,6 +120,7 @@ Quit(); } + void GenericThread::ThreadShutdownFailed(status_t a_status) { @@ -123,6 +130,7 @@ // (is this good default behaviour?) } + status_t GenericThread::Start(void) { @@ -130,18 +138,19 @@ if (IsPaused()) { - status = release_sem(m_execute_unit); + status = release_sem(fExecuteUnit); if (status != B_OK) return status; - m_thread_is_paused = false; + fThreadIsPaused = false; } - status = resume_thread(m_thread_id); + status = resume_thread(fThreadId); return status; } + int32 GenericThread::private_thread_function(void * a_simple_thread_ptr) { @@ -152,126 +161,144 @@ return (status); } + BMessage * GenericThread::GetDataStore(void) { - return (m_thread_data_store); + return (fThreadDataStore); } + void -GenericThread::SetDataStore(BMessage * a_message) +GenericThread::SetDataStore(BMessage * message) { - m_thread_data_store = a_message; + fThreadDataStore = message; } + status_t GenericThread::Pause(bool a_do_block, bigtime_t a_timeout) { status_t status = B_OK; if (a_do_block) - status = acquire_sem(m_execute_unit); + status = acquire_sem(fExecuteUnit); // thread will wait on semaphore else - status = acquire_sem_etc(m_execute_unit, 1, B_RELATIVE_TIMEOUT, a_timeout); + status = acquire_sem_etc(fExecuteUnit, 1, B_RELATIVE_TIMEOUT, a_timeout); // thread will timeout if (status == B_OK) { - m_thread_is_paused = true; + fThreadIsPaused = true; return (B_OK); } return status; } + void GenericThread::Quit(void) { - m_quit_requested = true; + fQuitRequested = true; } + bool GenericThread::HasQuitBeenRequested(void) { - return (m_quit_requested); + return (fQuitRequested); } + bool GenericThread::IsPaused(void) { - return (m_thread_is_paused); + return (fThreadIsPaused); } + status_t GenericThread::Suspend(void) { - return (suspend_thread(m_thread_id)); + return (suspend_thread(fThreadId)); } + status_t GenericThread::Resume(void) { - release_sem(m_execute_unit); // to counteract Pause() - m_thread_is_paused = false; + release_sem(fExecuteUnit); // to counteract Pause() + fThreadIsPaused = false; - return (resume_thread(m_thread_id)); // to counteract Suspend() + return (resume_thread(fThreadId)); // to counteract Suspend() } + status_t GenericThread::Kill(void) { - return (kill_thread(m_thread_id)); + return (kill_thread(fThreadId)); } + void GenericThread::ExitWithReturnValue(status_t a_return_value) { exit_thread(a_return_value); } + status_t GenericThread::SetExitCallback(void(*a_callback)(void*), void * a_data) { return (on_exit_thread(a_callback, a_data)); } + status_t GenericThread::WaitForThread(status_t * a_exit_value) { - return (wait_for_thread(m_thread_id, a_exit_value)); + return (wait_for_thread(fThreadId, a_exit_value)); } + status_t GenericThread::Rename(char * a_name) { - return (rename_thread(m_thread_id, a_name)); + return (rename_thread(fThreadId, a_name)); } + status_t GenericThread::SendData(int32 a_code, void * a_buffer, size_t a_buffer_size) { - return (send_data(m_thread_id, a_code, a_buffer, a_buffer_size)); + return (send_data(fThreadId, a_code, a_buffer, a_buffer_size)); } + int32 GenericThread::ReceiveData(thread_id * a_sender, void * a_buffer, size_t a_buffer_size) { return (receive_data(a_sender, a_buffer, a_buffer_size)); } + bool GenericThread::HasData(void) { - return (has_data(m_thread_id)); + return (has_data(fThreadId)); } + status_t GenericThread::SetPriority(int32 a_new_priority) { - return (set_thread_priority(m_thread_id, a_new_priority)); + return (set_thread_priority(fThreadId, a_new_priority)); } + void GenericThread::Snooze(bigtime_t a_microseconds) { @@ -280,6 +307,7 @@ Resume(); } + void GenericThread::SnoozeUntil(bigtime_t a_microseconds, int a_timebase) { @@ -288,12 +316,14 @@ Resume(); } + status_t -GenericThread::GetInfo(thread_info * a_thread_info) +GenericThread::GetInfo(thread_info * thread_info) { - return (get_thread_info(m_thread_id, a_thread_info)); + return (get_thread_info(fThreadId, thread_info)); } + thread_id GenericThread::GetThread(void) { @@ -302,6 +332,7 @@ return (t_thread_info.thread); } + team_id GenericThread::GetTeam(void) { @@ -310,6 +341,7 @@ return (t_thread_info.team); } + char * GenericThread::GetName(void) { @@ -318,6 +350,7 @@ return strdup(t_thread_info.name); } + thread_state GenericThread::GetState(void) { @@ -326,6 +359,7 @@ return (t_thread_info.state); } + sem_id GenericThread::GetSemaphore(void) { @@ -334,6 +368,7 @@ return (t_thread_info.sem); } + int32 GenericThread::GetPriority(void) { @@ -342,6 +377,7 @@ return (t_thread_info.priority); } + bigtime_t GenericThread::GetUserTime(void) { @@ -350,6 +386,7 @@ return (t_thread_info.user_time); } + bigtime_t GenericThread::GetKernelTime(void) { @@ -358,6 +395,7 @@ return (t_thread_info.kernel_time); } + void * GenericThread::GetStackBase(void) { @@ -366,6 +404,7 @@ return (t_thread_info.stack_base); } + void * GenericThread::GetStackEnd(void) { @@ -374,15 +413,17 @@ return (t_thread_info.stack_end); } + void GenericThread::BeginUnit(void) { - acquire_sem(m_execute_unit); // thread can not be paused until it releases semaphore + acquire_sem(fExecuteUnit); // thread can not be paused until it releases semaphore } + void GenericThread::EndUnit(void) { - release_sem(m_execute_unit); // thread can now be paused + release_sem(fExecuteUnit); // thread can now be paused } Modified: haiku/trunk/src/apps/expander/GenericThread.h =================================================================== --- haiku/trunk/src/apps/expander/GenericThread.h 2008-09-12 09:53:58 UTC (rev 27444) +++ haiku/trunk/src/apps/expander/GenericThread.h 2008-09-12 09:55:02 UTC (rev 27445) @@ -7,11 +7,11 @@ class GenericThread { public: - GenericThread(const char * a_thread_name = "generic_thread", int32 a_priority = B_NORMAL_PRIORITY, BMessage * a_message = NULL); + GenericThread(const char * thread_name = "generic_thread", int32 a_priority = B_NORMAL_PRIORITY, BMessage * message = NULL); virtual ~GenericThread(void); BMessage * GetDataStore(void); - void SetDataStore(BMessage * a_message); + void SetDataStore(BMessage * message); status_t Start(void); status_t Pause(bool a_do_block = TRUE, bigtime_t a_timeout = 0); @@ -39,7 +39,7 @@ void SnoozeUntil(bigtime_t a_microseconds, int a_timebase = B_SYSTEM_TIMEBASE); - status_t GetInfo(thread_info * a_thread_info); + status_t GetInfo(thread_info * thread_info); thread_id GetThread(void); team_id GetTeam(void); char * GetName(void); @@ -65,18 +65,18 @@ void BeginUnit(void); // acquire m_execute_cycle void EndUnit(void); // release m_execute_cycle - BMessage * m_thread_data_store; + BMessage * fThreadDataStore; private: static status_t private_thread_function(void * a_simple_thread_ptr); - thread_id m_thread_id; + thread_id fThreadId; - sem_id m_execute_unit; // acq./relase within tread_function.. For Pause() + sem_id fExecuteUnit; // acq./relase within tread_function.. For Pause() - bool m_quit_requested; - bool m_thread_is_paused; + bool fQuitRequested; + bool fThreadIsPaused; }; From stefano.ceccherini at gmail.com Fri Sep 12 12:07:15 2008 From: stefano.ceccherini at gmail.com (Stefano Ceccherini) Date: Fri, 12 Sep 2008 12:07:15 +0200 Subject: [Haiku-commits] r27445 - haiku/trunk/src/apps/expander In-Reply-To: <200809120955.m8C9t3Pv020103@sheep.berlios.de> References: <200809120955.m8C9t3Pv020103@sheep.berlios.de> Message-ID: <894b9700809120307m3d2cdf3es3bbc4d9c44b1899@mail.gmail.com> 2008/9/12 : > Author: jackburton > Date: 2008-09-12 11:55:02 +0200 (Fri, 12 Sep 2008) > New Revision: 27445 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27445&view=rev > > Modified: > haiku/trunk/src/apps/expander/GenericThread.cpp > haiku/trunk/src/apps/expander/GenericThread.h > Log: > First round of style changes: renamed all member variables from m_var_name to fVarName I was wondering: do you think we should have some class like this available in a shared place ? Also tracker uses a similar class (Thread), and probably other pieces of code, too. From jackburton at mail.berlios.de Fri Sep 12 12:10:15 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Fri, 12 Sep 2008 12:10:15 +0200 Subject: [Haiku-commits] r27446 - haiku/trunk/src/kits/game Message-ID: <200809121010.m8CAAFUu023725@sheep.berlios.de> Author: jackburton Date: 2008-09-12 12:10:13 +0200 (Fri, 12 Sep 2008) New Revision: 27446 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27446&view=rev Modified: haiku/trunk/src/kits/game/GameSoundBuffer.cpp Log: fixed buffer overrun, CID 649 Modified: haiku/trunk/src/kits/game/GameSoundBuffer.cpp =================================================================== --- haiku/trunk/src/kits/game/GameSoundBuffer.cpp 2008-09-12 09:55:02 UTC (rev 27445) +++ haiku/trunk/src/kits/game/GameSoundBuffer.cpp 2008-09-12 10:10:13 UTC (rev 27446) @@ -250,7 +250,7 @@ void GameSoundBuffer::Play(void * data, int64 frames) { - float * pan = new float[1]; + float *pan = new float[2]; pan[0] = fPanRight; pan[1] = fPanLeft; From jackburton at mail.berlios.de Fri Sep 12 12:26:06 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Fri, 12 Sep 2008 12:26:06 +0200 Subject: [Haiku-commits] r27447 - haiku/trunk/src/kits/shared Message-ID: <200809121026.m8CAQ6RF027445@sheep.berlios.de> Author: jackburton Date: 2008-09-12 12:26:05 +0200 (Fri, 12 Sep 2008) New Revision: 27447 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27447&view=rev Modified: haiku/trunk/src/kits/shared/AboutWindow.cpp Log: fAppName was leaked (CID 6). Also moved the initialization of fText to the end of the function, so that we avoid a BString::Adopt() call Modified: haiku/trunk/src/kits/shared/AboutWindow.cpp =================================================================== --- haiku/trunk/src/kits/shared/AboutWindow.cpp 2008-09-12 10:10:13 UTC (rev 27446) +++ haiku/trunk/src/kits/shared/AboutWindow.cpp 2008-09-12 10:26:05 UTC (rev 27447) @@ -20,7 +20,6 @@ const char **authors, char *extraInfo) { fAppName = new BString(appName); - fText = new BString(); // Get current year time_t tp; @@ -42,13 +41,14 @@ text << "\n" << extraInfo << "\n"; } - fText->Adopt(text); + fText = new BString(text); } BAboutWindow::~BAboutWindow() { delete fText; + delete fAppName; } From superstippi at gmx.de Fri Sep 12 12:44:01 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Fri, 12 Sep 2008 12:44:01 +0200 Subject: [Haiku-commits] r27441 - haiku/trunk/src/add-ons/kernel/file_systems/bfs In-Reply-To: References: <200809120925.m8C9PItE016862@sheep.berlios.de> Message-ID: <20080912104401.17100@gmx.net> Hi, > 2008/9/12 axeld at BerliOS : > > Author: axeld > > Date: 2008-09-12 11:25:17 +0200 (Fri, 12 Sep 2008) > > New Revision: 27441 > > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27441&view=rev > > > > Modified: > > haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.cpp > > Log: > > * Reverted r27196 and solved it differently (in a more robust way): > instead of > > guessing that the first attribute will be a name attribute, > fCurrentSmallData > > now takes hidden attributes into account. > > * I haven't tested this change, though, so if it messes things up again, > please > > yell at me :-) > > You should set a good example for newcomers devs and always test the code > before committing it. Especially if it can corrupt data. ;-p Yes please. It takes much more time to find and fix such problems if the memory of what was changed isn't fresh. Best regards, -Stephan From axeld at pinc-software.de Fri Sep 12 12:52:46 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Fri, 12 Sep 2008 12:52:46 +0200 CEST Subject: [Haiku-commits] =?utf-8?q?r27441_-_haiku/trunk/src/add-ons/kernel?= =?utf-8?q?/file=5Fsystems/bfs?= In-Reply-To: Message-ID: <12162369902-BeMail@zon> "Salvatore Benedetto" wrote: > > * I haven't tested this change, though, so if it messes things up > > again, please > > yell at me :-) > You should set a good example for newcomers devs and always test the > code > before committing it. Especially if it can corrupt data. ;-p I don't see how this could corrupt any data. And that I haven't tested it yet doesn't mean I won't test it; I just made the change from a slow system, and wanted to have it somewhere else for testing. Bye, Axel. From modeenf at mail.berlios.de Fri Sep 12 13:32:42 2008 From: modeenf at mail.berlios.de (modeenf at mail.berlios.de) Date: Fri, 12 Sep 2008 13:32:42 +0200 Subject: [Haiku-commits] r27448 - haiku/trunk/src/preferences/mouse Message-ID: <200809121132.m8CBWgXi009135@sheep.berlios.de> Author: modeenf Date: 2008-09-12 13:32:40 +0200 (Fri, 12 Sep 2008) New Revision: 27448 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27448&view=rev Modified: haiku/trunk/src/preferences/mouse/MouseView.cpp Log: Fixed CID 1033: fMouseDownBounds will never be null as we do a new BBitmap before we check for NULL Modified: haiku/trunk/src/preferences/mouse/MouseView.cpp =================================================================== --- haiku/trunk/src/preferences/mouse/MouseView.cpp 2008-09-12 10:26:05 UTC (rev 27447) +++ haiku/trunk/src/preferences/mouse/MouseView.cpp 2008-09-12 11:32:40 UTC (rev 27448) @@ -99,10 +99,7 @@ //fMouseBitmap = BTranslationUtils::GetBitmap(B_PNG_FORMAT, "mouse_bmap"); //fMouseDownBitmap = BTranslationUtils::GetBitmap(B_PNG_FORMAT, "pressed_mouse_bmap"); - if (fMouseDownBitmap != NULL) - fMouseDownBounds = fMouseDownBitmap->Bounds(); - else - fMouseDownBounds.Set(0, 0, 55, 29); + fMouseDownBounds = fMouseDownBitmap->Bounds(); } From axeld at mail.berlios.de Fri Sep 12 14:23:39 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Fri, 12 Sep 2008 14:23:39 +0200 Subject: [Haiku-commits] r27449 - haiku/trunk/src/tests/add-ons/kernel/file_systems/bfs Message-ID: <200809121223.m8CCNdsp030350@sheep.berlios.de> Author: axeld Date: 2008-09-12 14:23:39 +0200 (Fri, 12 Sep 2008) New Revision: 27449 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27449&view=rev Added: haiku/trunk/src/tests/add-ons/kernel/file_systems/bfs/bfs_attribute_iterator_test.cpp Modified: haiku/trunk/src/tests/add-ons/kernel/file_systems/bfs/Jamfile Log: * Added test application for the AttributeIterator implementation. Note that this test fails under BeOS, while it works just fine under Haiku. Modified: haiku/trunk/src/tests/add-ons/kernel/file_systems/bfs/Jamfile =================================================================== --- haiku/trunk/src/tests/add-ons/kernel/file_systems/bfs/Jamfile 2008-09-12 11:32:40 UTC (rev 27448) +++ haiku/trunk/src/tests/add-ons/kernel/file_systems/bfs/Jamfile 2008-09-12 12:23:39 UTC (rev 27449) @@ -1,5 +1,9 @@ SubDir HAIKU_TOP src tests add-ons kernel file_systems bfs ; +SimpleTest bfs_attribute_iterator_test : + bfs_attribute_iterator_test.cpp + : be ; + SubInclude HAIKU_TOP src tests add-ons kernel file_systems bfs array ; SubInclude HAIKU_TOP src tests add-ons kernel file_systems bfs bufferPool ; SubInclude HAIKU_TOP src tests add-ons kernel file_systems bfs bfs_shell ; Added: haiku/trunk/src/tests/add-ons/kernel/file_systems/bfs/bfs_attribute_iterator_test.cpp =================================================================== --- haiku/trunk/src/tests/add-ons/kernel/file_systems/bfs/bfs_attribute_iterator_test.cpp 2008-09-12 11:32:40 UTC (rev 27448) +++ haiku/trunk/src/tests/add-ons/kernel/file_systems/bfs/bfs_attribute_iterator_test.cpp 2008-09-12 12:23:39 UTC (rev 27449) @@ -0,0 +1,316 @@ +/* + * Copyright 2008, Axel D?rfler, axeld at pinc-software.de. + * This file may be used under the terms of the MIT License. + */ + + +#include +#include +#include +#include + +#include +#include +#include +#include + + +const char* kTempFile = "/tmp/bfs_attribute_iterator_test"; + +bool gVerbose; + + +bool +is_marker(const char* name) +{ + return strstr(name, ":marker") != NULL; +} + + +int32 +attribute_index(const char* name) +{ + int32 number; + if (sscanf(name, "test:%ld", &number) == 1) + return number; + + return 0; +} + + +void +add_attributes(BFile& file, int32 start, int32 count) +{ + for (int32 index = start; index < start + count; index++) { + char name[B_ATTR_NAME_LENGTH]; + snprintf(name, sizeof(name), "test:%ld", index); + file.WriteAttr(name, B_INT32_TYPE, 0, &index, sizeof(int32)); + } +} + + +void +remove_attributes(BFile& file, int32 start, int32 count) +{ + for (int32 index = start; index < start + count; index++) { + char name[B_ATTR_NAME_LENGTH]; + snprintf(name, sizeof(name), "test:%ld", index); + file.RemoveAttr(name); + } +} + + +void +add_marker_attribute(BFile& file, int32 index) +{ + char name[B_ATTR_NAME_LENGTH]; + snprintf(name, sizeof(name), "test:%ld:marker", index); + file.WriteAttr(name, B_INT32_TYPE, 0, &index, sizeof(int32)); +} + + +void +remove_marker_attribute(BFile& file, int32 index) +{ + char name[B_ATTR_NAME_LENGTH]; + snprintf(name, sizeof(name), "test:%ld:marker", index); + file.RemoveAttr(name); +} + + +void +test_remove_attributes(BFile& file, int32 start, int32 count, int32 removeAt, + int32 removeIndex1, int32 removeIndex2) +{ + int fd = file.Dup(); + if (fd < 0) + return; + + int32 index = 0; + bool seen[4096] = {0}; + + if (gVerbose) + printf("test removeAt %ld\n", removeAt); + + DIR* dir = fs_fopen_attr_dir(fd); + while (struct dirent* entry = fs_read_attr_dir(dir)) { + if (gVerbose) + printf(" %ld. %s\n", index, entry->d_name); + if (index == removeAt) { + if (removeIndex1 > 0) + remove_marker_attribute(file, removeIndex1); + if (removeIndex2 > 0) + remove_marker_attribute(file, removeIndex2); + } + index++; + + if (is_marker(entry->d_name)) + continue; + + int32 attributeIndex = attribute_index(entry->d_name); + if (attributeIndex > 0) { + if (seen[attributeIndex]) { + printf("attribute index %ld already listed!\n", attributeIndex); + exit(1); + } else + seen[attributeIndex] = true; + } + } + + fs_close_attr_dir(dir); + close(fd); + + for (int32 i = start; i < start + count; i++) { + if (!seen[i]) { + printf("attribute index %ld not listed, saw only %ld/%ld!\n", i, + index, count); + exit(1); + } + } +} + + +void +test_add_attributes(BFile& file, int32 start, int32 count, int32 addAt, + int32 addIndex1, int32 addIndex2) +{ + int fd = file.Dup(); + if (fd < 0) + return; + + int32 index = 0; + bool seen[4096] = {0}; + + if (gVerbose) + printf("test addAt %ld\n", addAt); + + DIR* dir = fs_fopen_attr_dir(fd); + while (struct dirent* entry = fs_read_attr_dir(dir)) { + if (gVerbose) + printf(" %ld. %s\n", index, entry->d_name); + if (index == addAt) { + if (addIndex1 > 0) + add_marker_attribute(file, addIndex1); + if (addIndex2 > 0) + add_marker_attribute(file, addIndex2); + } + index++; + + if (is_marker(entry->d_name)) + continue; + + int32 attributeIndex = attribute_index(entry->d_name); + if (attributeIndex > 0) { + if (seen[attributeIndex]) { + printf("attribute index %ld already listed!\n", attributeIndex); + exit(1); + } else + seen[attributeIndex] = true; + } + } + + fs_close_attr_dir(dir); + close(fd); + + for (int32 i = start; i < start + count; i++) { + if (!seen[i]) { + printf("attribute index %ld not listed, saw only %ld/%ld!\n", i, + index, count); + exit(1); + } + } +} + + +int +main(int argc, char** argv) +{ + if (argc > 1 && !strcmp(argv[1], "-v")) + gVerbose = true; + + BFile file; + status_t status = file.SetTo(kTempFile, B_CREATE_FILE | B_READ_WRITE); + if (status != B_OK) { + fprintf(stderr, "Could not create temporary file: %s\n", + strerror(status)); + return 1; + } + + puts("--------- Remove Tests ----------"); + + // remove test, many attributes + + puts("Test 1..."); + + for (int32 count = 5; count <= 100; count += 5) { + add_attributes(file, 1, count); + add_marker_attribute(file, count); + add_attributes(file, count + 1, count); + + test_remove_attributes(file, 1, count, + count & 1 ? count - 1 : count + 1, count, -1); + + remove_attributes(file, 1, count * 2); + } + + // remove test, all positions + + puts("Test 2..."); + + for (int32 i = 1; i < 100; i++) { + add_attributes(file, 1, 50); + add_marker_attribute(file, 51); + add_attributes(file, 51, 50); + + test_remove_attributes(file, 1, 100, i, 51, -1); + + remove_attributes(file, 1, 100); + } + + // remove test, all positions, remove many + + puts("Test 3..."); + + for (int32 i = 1; i < 100; i++) { + add_attributes(file, 1, 33); + add_marker_attribute(file, 33); + add_attributes(file, 34, 34); + add_marker_attribute(file, 67); + add_attributes(file, 68, 33); + + test_remove_attributes(file, 1, 100, i, 33, 67); + + remove_attributes(file, 1, 100); + } + + puts("--------- Add Tests ----------"); + + // add test, many attributes + + puts("Test 4..."); + + for (int32 count = 10; count <= 200; count += 10) { + add_attributes(file, 1, count); + + int32 half = count / 2; + + test_add_attributes(file, 1, count, + half & 1 ? half - 1 : half + 1, half - 2, half + 2); + + remove_attributes(file, 1, count); + } + + // add test, all iterator positions + + puts("Test 5..."); + + for (int32 i = 1; i < 100; i++) { + add_attributes(file, 1, 100); + + test_add_attributes(file, 1, 100, i, 50, -1); + + remove_attributes(file, 1, 100); + } + + // add test, all attribute positions + + puts("Test 6..."); + + for (int32 i = 1; i < 100; i++) { + add_attributes(file, 1, 100); + + test_add_attributes(file, 1, 100, 50, i, -1); + + remove_attributes(file, 1, 100); + } + + // add test, many attributes + + puts("Test 7..."); + + for (int32 i = 1; i < 100; i++) { + add_attributes(file, 1, 100); + + test_add_attributes(file, 1, 100, i, 33, 67); + + remove_attributes(file, 1, 100); + } + + // add test, many attributes + + puts("Test 8..."); + + for (int32 i = 1; i < 100; i++) { + add_attributes(file, 1, 100); + + test_add_attributes(file, 1, 100, 50, i - 1, i + 1); + + remove_attributes(file, 1, 100); + } + + BEntry entry; + if (entry.SetTo(kTempFile) == B_OK) + entry.Remove(); + + return 0; +} From bga at bug-br.org.br Fri Sep 12 14:50:47 2008 From: bga at bug-br.org.br (Bruno Albuquerque) Date: Fri, 12 Sep 2008 09:50:47 -0300 Subject: [Haiku-commits] r27449 - haiku/trunk/src/tests/add-ons/kernel/file_systems/bfs In-Reply-To: <200809121223.m8CCNdsp030350@sheep.berlios.de> References: <200809121223.m8CCNdsp030350@sheep.berlios.de> Message-ID: <48CA65A7.2090600@bug-br.org.br> axeld at BerliOS wrote: > * Added test application for the AttributeIterator implementation. Note that > this test fails under BeOS, while it works just fine under Haiku. Did you try this under Zeta? If I understand your tests correctly (I just read the email, no access to Haiku, BeOS or Zeta right now), what you are seeing is a bug that the R5 BFS had that would be triggered when attributes would be moved from the small data section to normal attribute files. I fixed this in Zeta (in case it is the same bug). -Bruno From axeld at pinc-software.de Fri Sep 12 15:17:53 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Fri, 12 Sep 2008 15:17:53 +0200 CEST Subject: [Haiku-commits] =?utf-8?q?r27449_-_haiku/trunk/src/tests/add-ons/?= =?utf-8?q?kernel/file=5Fsystems/bfs?= In-Reply-To: <48CA65A7.2090600@bug-br.org.br> Message-ID: <20869753447-BeMail@zon> Bruno Albuquerque wrote: > axeld at BerliOS wrote: > > * Added test application for the AttributeIterator implementation. > > Note that > > this test fails under BeOS, while it works just fine under Haiku. > Did you try this under Zeta? If I understand your tests correctly (I > just read the email, no access to Haiku, BeOS or Zeta right now), > what > you are seeing is a bug that the R5 BFS had that would be triggered > when > attributes would be moved from the small data section to normal > attribute files. I fixed this in Zeta (in case it is the same bug). I haven't tested it in Zeta, but it sounds very likely that this is that bug exactly; at least 25 attributes were missing all of a sudden... Bye, Axel. From axeld at pinc-software.de Fri Sep 12 15:18:50 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Fri, 12 Sep 2008 15:18:50 +0200 CEST Subject: [Haiku-commits] =?utf-8?q?r27390_-_haiku/trunk/src/system/boot/pl?= =?utf-8?q?atform/bios=5Fia32?= In-Reply-To: <1e80d8750809090948x734aeee6kf950b02b184b1fbb@mail.gmail.com> Message-ID: <20926654218-BeMail@zon> "Urias McCullough" wrote: > 2008/9/9 axeld at BerliOS : > > Author: axeld > > Date: 2008-09-09 17:18:51 +0200 (Tue, 09 Sep 2008) > > New Revision: 27390 > Would this have possibly affected the video mode chosen by the > intel_extreme driver? I started having problems with this on one of > my > machines recently and had to start using VESA video instead (choosing > a resolution manually at boot didn't fix it). It shouldn't have any influence on that; the change should only affect the boot loader and splash screen. Bye, Axel. From axeld at pinc-software.de Fri Sep 12 15:20:20 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Fri, 12 Sep 2008 15:20:20 +0200 CEST Subject: [Haiku-commits] =?utf-8?q?r27390_-_haiku/trunk/src/system/boot/pl?= =?utf-8?q?atform/bios=5Fia32?= In-Reply-To: Message-ID: <21016219805-BeMail@zon> Hi J?r?me, "J?r?me Duval" wrote: > I still have the "video mode out of range" message but after the boot > (when > the desktop should appear). > Though it works when I choose a fail-safe video mode (ie 1280*1024* > 32). Do you know which resolution it tries to use? And with which graphics chipset are you experiencing this problem? What kind of monitor? What EDID info does the monitor return? Bye, Axel. From leavengood at gmail.com Fri Sep 12 15:37:24 2008 From: leavengood at gmail.com (Ryan Leavengood) Date: Fri, 12 Sep 2008 09:37:24 -0400 Subject: [Haiku-commits] r27428 - haiku/trunk/src/system/kernel In-Reply-To: <1165375134-BeMail@zon> References: <200809120428.m8C4SBn3010823@sheep.berlios.de> <1165375134-BeMail@zon> Message-ID: On Fri, Sep 12, 2008 at 3:49 AM, Axel D?rfler wrote: > > That's not really necessary; correct would have been to remove the NULL > check altogether, as valid arguments (within the range) are never NULL. OK, for me it is sort of trial and error to figure what is the proper fix for some of these. But I will learn as I go. Thanks for the feedback. Ryan From leavengood at mail.berlios.de Fri Sep 12 15:44:00 2008 From: leavengood at mail.berlios.de (leavengood at BerliOS) Date: Fri, 12 Sep 2008 15:44:00 +0200 Subject: [Haiku-commits] r27450 - haiku/trunk/src/system/kernel Message-ID: <200809121344.m8CDi0Tl007321@sheep.berlios.de> Author: leavengood Date: 2008-09-12 15:44:00 +0200 (Fri, 12 Sep 2008) New Revision: 27450 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27450&view=rev Modified: haiku/trunk/src/system/kernel/thread.cpp Log: Remove the null check as per Axel's advice: valid arguments within the range are never null. Modified: haiku/trunk/src/system/kernel/thread.cpp =================================================================== --- haiku/trunk/src/system/kernel/thread.cpp 2008-09-12 12:23:39 UTC (rev 27449) +++ haiku/trunk/src/system/kernel/thread.cpp 2008-09-12 13:44:00 UTC (rev 27450) @@ -1218,32 +1218,30 @@ for (; argi < argc; argi++) { const char *name = argv[argi]; - if (name != NULL) { - int32 id = strtoul(name, NULL, 0); + int32 id = strtoul(name, NULL, 0); - if (IS_KERNEL_ADDRESS(id)) { - // semi-hack - _dump_thread_info((struct thread *)id, shortInfo); - continue; - } + if (IS_KERNEL_ADDRESS(id)) { + // semi-hack + _dump_thread_info((struct thread *)id, shortInfo); + continue; + } - // walk through the thread list, trying to match name or id - bool found = false; - struct hash_iterator i; - hash_open(sThreadHash, &i); - struct thread *thread; - while ((thread = (struct thread*)hash_next(sThreadHash, &i)) != NULL) { - if (!strcmp(name, thread->name) || thread->id == id) { - _dump_thread_info(thread, shortInfo); - found = true; - break; - } + // walk through the thread list, trying to match name or id + bool found = false; + struct hash_iterator i; + hash_open(sThreadHash, &i); + struct thread *thread; + while ((thread = (struct thread*)hash_next(sThreadHash, &i)) != NULL) { + if (!strcmp(name, thread->name) || thread->id == id) { + _dump_thread_info(thread, shortInfo); + found = true; + break; } - hash_close(sThreadHash, &i, false); - - if (!found) - kprintf("thread \"%s\" (%ld) doesn't exist!\n", name, id); } + hash_close(sThreadHash, &i, false); + + if (!found) + kprintf("thread \"%s\" (%ld) doesn't exist!\n", name, id); } return 0; From leavengood at mail.berlios.de Fri Sep 12 15:46:51 2008 From: leavengood at mail.berlios.de (leavengood at BerliOS) Date: Fri, 12 Sep 2008 15:46:51 +0200 Subject: [Haiku-commits] r27451 - haiku/trunk/src/system/kernel/messaging Message-ID: <200809121346.m8CDkpmM007732@sheep.berlios.de> Author: leavengood Date: 2008-09-12 15:46:50 +0200 (Fri, 12 Sep 2008) New Revision: 27451 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27451&view=rev Modified: haiku/trunk/src/system/kernel/messaging/KMessage.cpp Log: Reverting r27437 as per Axel's advice. The variable size is initialized by the call to ElementAt. Marked CID 1306 as false. Modified: haiku/trunk/src/system/kernel/messaging/KMessage.cpp =================================================================== --- haiku/trunk/src/system/kernel/messaging/KMessage.cpp 2008-09-12 13:44:00 UTC (rev 27450) +++ haiku/trunk/src/system/kernel/messaging/KMessage.cpp 2008-09-12 13:46:50 UTC (rev 27451) @@ -630,7 +630,7 @@ if (field.CountElements() != 1) printFunc("\n"); - int32 size = 0; + int32 size; for (int i = 0; const void* data = field.ElementAt(i, &size); i++) { if (field.CountElements() != 1) printFunc(" [%2d] ", i); From modeenf at mail.berlios.de Fri Sep 12 16:06:59 2008 From: modeenf at mail.berlios.de (modeenf at mail.berlios.de) Date: Fri, 12 Sep 2008 16:06:59 +0200 Subject: [Haiku-commits] r27452 - haiku/trunk/src/kits/device Message-ID: <200809121406.m8CE6xjE010830@sheep.berlios.de> Author: modeenf Date: 2008-09-12 16:06:56 +0200 (Fri, 12 Sep 2008) New Revision: 27452 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27452&view=rev Modified: haiku/trunk/src/kits/device/SerialPort.cpp Log: reverted to 11769 and added (std::nothrow) Modified: haiku/trunk/src/kits/device/SerialPort.cpp =================================================================== --- haiku/trunk/src/kits/device/SerialPort.cpp 2008-09-12 13:46:50 UTC (rev 27451) +++ haiku/trunk/src/kits/device/SerialPort.cpp 2008-09-12 14:06:56 UTC (rev 27452) @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -18,6 +19,7 @@ #include #include + /* The directory where the serial driver publishes its devices */ #define SERIAL_DIR "/dev/ports" @@ -62,7 +64,7 @@ fFlow(B_HARDWARE_CONTROL), fTimeout(B_INFINITE_TIMEOUT), fBlocking(true), - _fDevices(new BList) + _fDevices(new(std::nothrow) BList) { ScanDevices(); } @@ -479,9 +481,15 @@ int32 BSerialPort::CountDevices() { + int32 count = 0; + // Refresh devices list ScanDevices(); - return _fDevices->CountItems(); + + if (_fDevices != NULL) + count = _fDevices->CountItems(); + + return count; } From modeenf at mail.berlios.de Fri Sep 12 16:15:50 2008 From: modeenf at mail.berlios.de (modeenf at mail.berlios.de) Date: Fri, 12 Sep 2008 16:15:50 +0200 Subject: [Haiku-commits] r27453 - haiku/trunk/src/preferences/filetypes Message-ID: <200809121415.m8CEFoBk011938@sheep.berlios.de> Author: modeenf Date: 2008-09-12 16:15:47 +0200 (Fri, 12 Sep 2008) New Revision: 27453 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27453&view=rev Modified: haiku/trunk/src/preferences/filetypes/ApplicationTypeWindow.cpp haiku/trunk/src/preferences/filetypes/IconView.cpp Log: Fixed CID 321, 868: check item for NULL and delete recource leak Modified: haiku/trunk/src/preferences/filetypes/ApplicationTypeWindow.cpp =================================================================== --- haiku/trunk/src/preferences/filetypes/ApplicationTypeWindow.cpp 2008-09-12 14:06:56 UTC (rev 27452) +++ haiku/trunk/src/preferences/filetypes/ApplicationTypeWindow.cpp 2008-09-12 14:15:47 UTC (rev 27453) @@ -703,7 +703,8 @@ SupportedTypeItem* item = dynamic_cast( fTypeListView->ItemAt(i)); - supportedTypes.AddString("types", item->Type()); + if (item != NULL) + supportedTypes.AddString("types", item->Type()); } version_info versionInfo; @@ -735,7 +736,8 @@ SupportedTypeItem* item = dynamic_cast( fTypeListView->ItemAt(i)); - item->Icon().CopyTo(info, item->Type(), true); + if (item != NULL) + item->Icon().CopyTo(info, item->Type(), true); } } Modified: haiku/trunk/src/preferences/filetypes/IconView.cpp =================================================================== --- haiku/trunk/src/preferences/filetypes/IconView.cpp 2008-09-12 14:06:56 UTC (rev 27452) +++ haiku/trunk/src/preferences/filetypes/IconView.cpp 2008-09-12 14:15:47 UTC (rev 27453) @@ -574,8 +574,8 @@ if (message->WasDropped() && message->ReturnAddress() != BMessenger(this) && AcceptsDrag(message)) { // set icon from message - BBitmap* mini = NULL; - BBitmap* large = NULL; + BBitmap *mini = NULL; + BBitmap *large = NULL; const uint8* data = NULL; ssize_t size = 0; @@ -591,11 +591,16 @@ if (large != NULL || mini != NULL || (data != NULL && size > 0)) _SetIcon(large, mini, data, size); + else { + entry_ref ref; + if (message->FindRef("refs", &ref) == B_OK) + _SetIcon(&ref); + } + + delete(large); + delete(mini); + delete(data); - entry_ref ref; - if (message->FindRef("refs", &ref) == B_OK) - _SetIcon(&ref); - return; } From mmlr at mlotz.ch Fri Sep 12 16:20:08 2008 From: mmlr at mlotz.ch (Michael Lotz) Date: Fri, 12 Sep 2008 16:20:08 +0200 Subject: [Haiku-commits] r27453 - haiku/trunk/src/preferences/filetypes In-Reply-To: <200809121415.m8CEFoBk011938@sheep.berlios.de> References: <200809121415.m8CEFoBk011938@sheep.berlios.de> Message-ID: <20080912141900.M86328@mlotz.ch> On Fri, 12 Sep 2008 16:15:50 +0200, modeenf wrote > Author: modeenf > Date: 2008-09-12 16:15:47 +0200 (Fri, 12 Sep 2008) > New Revision: 27453 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27453&view=rev > > Modified: > haiku/trunk/src/preferences/filetypes/ApplicationTypeWindow.cpp > haiku/trunk/src/preferences/filetypes/IconView.cpp > Log: > Fixed CID 321, 868: check item for NULL and delete recource leak > ... > + delete(large); > + delete(mini); > + delete(data); Please omit the extra parenthesis. Delete is an operator, not a function, so these are unnecessary. Regards Michael From axeld at pinc-software.de Fri Sep 12 16:23:37 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Fri, 12 Sep 2008 16:23:37 +0200 CEST Subject: [Haiku-commits] r27453 - haiku/trunk/src/preferences/filetypes In-Reply-To: <200809121415.m8CEFoBk011938@sheep.berlios.de> Message-ID: <24813262096-BeMail@zon> modeenf at mail.berlios.de wrote: > - BBitmap* mini = NULL; > - BBitmap* large = NULL; > + BBitmap *mini = NULL; > + BBitmap *large = NULL; And also, please don't change the coding style to something inconsistent. The whole file uses "* ", not " *". Please change back. Bye, Axel. From axeld at pinc-software.de Fri Sep 12 16:24:36 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Fri, 12 Sep 2008 16:24:36 +0200 CEST Subject: [Haiku-commits] r27452 - haiku/trunk/src/kits/device In-Reply-To: <200809121406.m8CE6xjE010830@sheep.berlios.de> Message-ID: <24872453289-BeMail@zon> modeenf at mail.berlios.de wrote: > Log: > reverted to 11769 and added (std::nothrow) That's actually not enough, as there are many other places in the code that assume _fDevices (which should be renamed to fDevices) to be non- NULL. Bye, Axel. From stippi at mail.berlios.de Fri Sep 12 18:29:54 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Fri, 12 Sep 2008 18:29:54 +0200 Subject: [Haiku-commits] r27454 - haiku/trunk/src/add-ons/media/media-add-ons/opensound Message-ID: <200809121629.m8CGTsXK031904@sheep.berlios.de> Author: stippi Date: 2008-09-12 18:29:52 +0200 (Fri, 12 Sep 2008) New Revision: 27454 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27454&view=rev Modified: haiku/trunk/src/add-ons/media/media-add-ons/opensound/OpenSoundDeviceEngine.cpp haiku/trunk/src/add-ons/media/media-add-ons/opensound/OpenSoundNode.cpp Log: Fixed CID 1303. The config message was dereferenced in the constructor list. I don't know if it can be NULL at all, but let's be defensive. It was already checked later anyways. Modified: haiku/trunk/src/add-ons/media/media-add-ons/opensound/OpenSoundDeviceEngine.cpp =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/opensound/OpenSoundDeviceEngine.cpp 2008-09-12 14:15:47 UTC (rev 27453) +++ haiku/trunk/src/add-ons/media/media-add-ons/opensound/OpenSoundDeviceEngine.cpp 2008-09-12 16:29:52 UTC (rev 27454) @@ -105,7 +105,6 @@ // C-Media supports "only" 16). If OSS uses the same 2048 bytes even for // 32 bit/sample, then I could see how that would be asking for too much, // since that would effectively half the latency. - #ifdef HAIKU_TARGET_PLATFORM_HAIKU uint32 bufferCount = 6; uint32 bufferSize = 0x000b; // 1024 bytes Modified: haiku/trunk/src/add-ons/media/media-add-ons/opensound/OpenSoundNode.cpp =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/opensound/OpenSoundNode.cpp 2008-09-12 14:15:47 UTC (rev 27453) +++ haiku/trunk/src/add-ons/media/media-add-ons/opensound/OpenSoundNode.cpp 2008-09-12 16:29:52 UTC (rev 27454) @@ -136,7 +136,7 @@ for (int32 i = 0; i < frames; i ++) { // convert sample rate from 48000 to connected format uint32 p = (uint32)((fTestTonePhase * sampleRate) / 48000); - + // prevent phase from integer overflow fTestTonePhase = (fTestTonePhase + 1) % 4800; for (int32 k = 0; k < channels; k++) @@ -255,16 +255,16 @@ { if (fBufferGroup == NULL) return NULL; - + BBuffer* buffer = fBufferGroup->RequestBuffer( fOutput.format.u.raw_audio.buffer_size, bufferDuration); - + // if we fail to get a buffer (for example, if the request times out), // we skip this buffer and go on to the next, to avoid locking up the // control thread if (!buffer) return NULL; - + // now fill it with data ssize_t sizeUsed = fRealEngine->Read(buffer->Data(), fOutput.format.u.raw_audio.buffer_size); @@ -296,7 +296,7 @@ // AFMT_* flags for this output media_output fOutput; media_format fPreferredFormat; - + thread_id fThread; BBufferGroup* fBufferGroup; bool fUsingOwnBufferGroup; @@ -323,19 +323,19 @@ fTimeSourceStartTime(0), fWeb(NULL), - fConfig(*config) + fConfig(0UL) { CALLED(); - + if (fDevice == NULL) return; - + fAddOn = addon; fId = internal_id; - + AddNodeKind(B_PHYSICAL_OUTPUT); AddNodeKind(B_PHYSICAL_INPUT); - + // initialize our preferred format object // TODO: this should go away! should use engine's preferred for each afmt. #if 1 @@ -359,15 +359,17 @@ } // TODO: Use the OSS suggested buffer size via SNDCTL_DSP_GETBLKSIZE ? - fPreferredFormat.u.raw_audio.buffer_size = DEFAULT_BUFFER_SIZE + fPreferredFormat.u.raw_audio.buffer_size = DEFAULT_BUFFER_SIZE * (fPreferredFormat.u.raw_audio.format & media_raw_audio_format::B_AUDIO_SIZE_MASK) * fPreferredFormat.u.raw_audio.channel_count; #endif - - if (config) - PRINT_OBJECT(*config); - + + if (config != NULL) { + fConfig = *config; + PRINT_OBJECT(fConfig); + } + fInitCheckStatus = B_OK; } @@ -386,8 +388,8 @@ delete (NodeOutput*)fOutputs.ItemAtFast(i); BMediaEventLooper::Quit(); - - fWeb = NULL; + + fWeb = NULL; } @@ -438,16 +440,16 @@ OpenSoundNode::NodeRegistered() { CALLED(); - + if (fInitCheckStatus != B_OK) { ReportError(B_NODE_IN_DISTRESS); return; } - + SetPriority(B_REAL_TIME_PRIORITY); - + Run(); - + TRACE("NodeRegistered: %d engines\n", fDevice->CountEngines()); for (int32 i = 0; i < fDevice->CountEngines(); i++) { OpenSoundDeviceEngine* engine = fDevice->EngineAt(i); @@ -486,7 +488,7 @@ prefix = "S/PDIF "; sprintf(mediaInput.name, "%sOutput %ld (%s)", prefix, mediaInput.destination.id, gSupportedFormatsNames[f]); - + NodeInput* input = new (nothrow) NodeInput(mediaInput, i, fmt, this); if (input == NULL || !fInputs.AddItem(input)) { @@ -495,7 +497,7 @@ } } } - + for (int32 i = 0; i < fDevice->CountEngines(); i++) { OpenSoundDeviceEngine* engine = fDevice->EngineAt(i); if (engine == NULL) @@ -516,7 +518,7 @@ continue; TRACE("NodeRegistered() : creating an output for engine %i, " "format[%i]\n", i, f); - + media_format preferredFormat; status_t err = engine->PreferredFormatFor(fmt, preferredFormat); if (err < B_OK) @@ -534,7 +536,7 @@ prefix = "S/PDIF "; sprintf(mediaOutput.name, "%sInput %ld (%s)", prefix, mediaOutput.source.id, gSupportedFormatsNames[f]); - + NodeOutput* output = new (nothrow) NodeOutput(mediaOutput, preferredFormat); if (output == NULL || !fOutputs.AddItem(output)) { @@ -549,11 +551,11 @@ output->fNode = this; } } - + // set up our parameter web fWeb = MakeParameterWeb(); SetParameterWeb(fWeb); - + // apply configuration #ifdef PRINTING bigtime_t start = system_time(); @@ -570,7 +572,7 @@ } index++; } - + TRACE("apply configuration in : %lld?s\n", system_time() - start); } @@ -605,16 +607,16 @@ // any wildcards corresponding to our requirements. CALLED(); - + NodeInput* channel = _FindInput(dest); - + if (channel == NULL) { fprintf(stderr, "OpenSoundNode::AcceptFormat()" " - B_MEDIA_BAD_DESTINATION"); return B_MEDIA_BAD_DESTINATION; // we only have one input so that better be it } - + if (format == NULL) { fprintf(stderr, "OpenSoundNode::AcceptFormat() - B_BAD_VALUE\n"); return B_BAD_VALUE; @@ -629,41 +631,41 @@ fprintf(stderr,"\n");*/ // Be's format_is_compatible doesn't work. // if (!format_is_compatible(*format,*myFormat)) { - + BAutolock L(fDevice->Locker()); - + OpenSoundDeviceEngine* engine = fDevice->NextFreeEngineAt( channel->fEngineIndex, false); if (!engine) return B_BUSY; - + status_t err = engine->AcceptFormatFor(channel->fOSSFormatFlags, *format, false); if (err < B_OK) return err; - + channel->fRealEngine = engine; - + /* if ( format->type != B_MEDIA_RAW_AUDIO ) { fprintf(stderr,"<- B_MEDIA_BAD_FORMAT\n"); return B_MEDIA_BAD_FORMAT; - } + } */ - + //channel->fInput.format = channel->fPreferredFormat; channel->fInput.format = *format; - + /*if(format->u.raw_audio.format == media_raw_audio_format::B_AUDIO_FLOAT && channel->fPreferredFormat.u.raw_audio.format == media_raw_audio_format::B_AUDIO_SHORT) format->u.raw_audio.format = media_raw_audio_format::B_AUDIO_FLOAT; - else*/ + else*/ /* format->u.raw_audio.format = channel->fPreferredFormat.u.raw_audio.format; format->u.raw_audio.valid_bits = channel->fPreferredFormat.u.raw_audio.valid_bits; - + format->u.raw_audio.frame_rate = channel->fPreferredFormat.u.raw_audio.frame_rate; format->u.raw_audio.channel_count @@ -677,7 +679,7 @@ & media_raw_audio_format::B_AUDIO_SIZE_MASK) * format->u.raw_audio.channel_count; */ - + // media_format myFormat; // GetFormat(&myFormat); // if (!format_is_acceptible(*format,myFormat)) { @@ -685,7 +687,7 @@ // return B_MEDIA_BAD_FORMAT; // } - return B_OK; + return B_OK; } @@ -700,10 +702,10 @@ fprintf(stderr,"OpenSoundNode::GetNextInput() - B_BAD_VALUE\n"); return B_BAD_VALUE; } - + if (*cookie >= fInputs.CountItems() || *cookie < 0) return B_BAD_INDEX; - + NodeInput* channel = (NodeInput*)fInputs.ItemAt(*cookie); *out_input = channel->fInput; *cookie += 1; @@ -736,7 +738,7 @@ // fprintf(stderr, "ApplyParameterData() in " // "OpenSoundNode::BufferReceived() failed: %s\n", // strerror(status)); -// } +// } // buffer->Recycle(); // break; // } @@ -745,7 +747,7 @@ fprintf(stderr, "OpenSoundNode::BufferReceived() - " "B_SMALL_BUFFER not implemented\n"); // TODO: implement this part - buffer->Recycle(); + buffer->Recycle(); } else { media_timed_event event(buffer->Header()->start_time, BTimedEventQueue::B_HANDLE_BUFFER, buffer, @@ -759,7 +761,7 @@ } } break; - default: + default: fprintf(stderr, "OpenSoundNode::BufferReceived() - unexpected " "buffer type\n"); buffer->Recycle(); @@ -773,22 +775,22 @@ int32 status, bigtime_t at_performance_time) { CALLED(); - + NodeInput* channel = _FindInput(for_whom); - + if (channel == NULL) { fprintf(stderr,"OpenSoundNode::ProducerDataStatus() - " "invalid destination\n"); return; } - + // TRACE("************ ProducerDataStatus: queuing event ************\n"); // TRACE("************ status=%d ************\n", status); - + media_timed_event event(at_performance_time, BTimedEventQueue::B_DATA_STATUS, &channel->fInput, BTimedEventQueue::B_NO_CLEANUP, status, 0, NULL); - EventQueue()->AddEvent(event); + EventQueue()->AddEvent(event); } @@ -802,9 +804,9 @@ fprintf(stderr,"OpenSoundNode::GetLatencyFor() - B_BAD_VALUE\n"); return B_BAD_VALUE; } - + NodeInput* channel = _FindInput(for_whom); - + if (channel == NULL || channel->fRealEngine == NULL) { fprintf(stderr,"OpenSoundNode::GetLatencyFor() - " "B_MEDIA_BAD_DESTINATION\n"); @@ -864,10 +866,10 @@ channel->fInput.format = with_format; *out_input = channel->fInput; - + // we are sure the thread is started _StartPlayThread(channel); - + return B_OK; } @@ -912,7 +914,7 @@ { CALLED(); NodeInput* channel = _FindInput(consumer); - + if (channel == NULL) { fprintf(stderr,"OpenSoundNode::FormatChanged() - " "B_MEDIA_BAD_DESTINATION\n"); @@ -925,7 +927,7 @@ return B_MEDIA_BAD_SOURCE; } - // currently not supported, TODO: implement? + // currently not supported, TODO: implement? return B_ERROR; } @@ -952,7 +954,7 @@ // negotiation process; it's simply an interrogation -- the caller wants // to see what the node's preferred data format is, given a suggestion by // the caller. -status_t +status_t OpenSoundNode::FormatSuggestionRequested(media_type type, int32 /*quality*/, media_format* format) { @@ -982,13 +984,13 @@ //! FormatProposal() is the first stage in the BMediaRoster::Connect() // process. We hand out a suggested format, with wildcards for any // variations we support. -status_t +status_t OpenSoundNode::FormatProposal(const media_source& output, media_format* format) { CALLED(); NodeOutput* channel = _FindOutput(output); - + // is this a proposal for our select output? if (channel == NULL) { fprintf(stderr, "OpenSoundNode::FormatProposal returning " @@ -1020,13 +1022,13 @@ "B_MEDIA_BAD_FORMAT\n"); return B_MEDIA_BAD_FORMAT; } - + // raw audio or wildcard type, either is okay by us return B_OK; } -status_t +status_t OpenSoundNode::FormatChangeRequested(const media_source& source, const media_destination& destination, media_format* io_format, int32* _deprecated_) @@ -1039,7 +1041,7 @@ } -status_t +status_t OpenSoundNode::GetNextOutput(int32* cookie, media_output* out_output) { CALLED(); @@ -1054,7 +1056,7 @@ } -status_t +status_t OpenSoundNode::DisposeOutputCookie(int32 cookie) { CALLED(); @@ -1063,14 +1065,14 @@ } -status_t +status_t OpenSoundNode::SetBufferGroup(const media_source& for_source, BBufferGroup* newGroup) { CALLED(); NodeOutput* channel = _FindOutput(for_source); - + // is this our output? if (channel == NULL) { fprintf(stderr, "OpenSoundNode::SetBufferGroup() returning " @@ -1107,7 +1109,7 @@ // changed the proposed format. It may also have left wildcards in the // format. PrepareToConnect() *must* fully specialize the format before // returning! -status_t +status_t OpenSoundNode::PrepareToConnect(const media_source& what, const media_destination& where, media_format* format, media_source* out_source, char* out_name) @@ -1116,7 +1118,7 @@ status_t err; NodeOutput *channel = _FindOutput(what); - + // is this our output? if (channel == NULL) { fprintf(stderr, "OpenSoundNode::PrepareToConnect returning " @@ -1142,13 +1144,13 @@ fprintf(stderr, "\tnon-raw-audio format?!\n"); return B_MEDIA_BAD_FORMAT; } - + // !!! validate all other fields except for buffer_size here, because the // consumer might have supplied different values from AcceptFormat()? err = engine->SpecializeFormatFor(channel->fOSSFormatFlags, *format, true); if (err < B_OK) return err; - + channel->fRealEngine = engine; #if 0 @@ -1174,15 +1176,15 @@ } -void +void OpenSoundNode::Connect(status_t error, const media_source& source, const media_destination& destination, const media_format& format, char* io_name) { CALLED(); - + NodeOutput *channel = _FindOutput(source); - + // is this our output? if (channel == NULL) { fprintf(stderr, "OpenSoundNode::Connect returning (cause : " @@ -1193,7 +1195,7 @@ OpenSoundDeviceEngine *engine = channel->fRealEngine; if (engine == NULL) return; - + // If something earlier failed, Connect() might still be called, but with // a non-zero error code. When that happens we simply unreserve the // connection and do nothing else. @@ -1216,11 +1218,11 @@ * 10000 / ( (channel->fOutput.format.u.raw_audio.format & media_raw_audio_format::B_AUDIO_SIZE_MASK) - * channel->fOutput.format.u.raw_audio.channel_count) + * channel->fOutput.format.u.raw_audio.channel_count) / ((int32)(channel->fOutput.format.u.raw_audio.frame_rate / 100)); - + SetBufferDuration(duration); - + // Now that we're connected, we can determine our downstream latency. // Do so, then make sure we get our events early enough. media_node_id id; @@ -1232,7 +1234,7 @@ fInternalLatency); //SetEventLatency(fLatency + fInternalLatency); - // Set up the buffer group for our connection, as long as nobody handed us + // Set up the buffer group for our connection, as long as nobody handed us // a buffer group (via SetBufferGroup()) prior to this. That can happen, // for example, if the consumer calls SetOutputBuffersFor() on us from // within its Connected() method. @@ -1240,20 +1242,20 @@ channel->AllocateBuffers(BufferDuration(), fLatency); engine->StartRecording(); - + // we are sure the thread is started _StartRecThread(channel); } -void +void OpenSoundNode::Disconnect(const media_source& what, const media_destination& where) { CALLED(); - + NodeOutput *channel = _FindOutput(what); - + // is this our output? if (channel == NULL) { fprintf(stderr, "OpenSoundNode::Disconnect() returning (cause : " @@ -1264,9 +1266,9 @@ _StopRecThread(channel); BAutolock L(fDevice->Locker()); - + OpenSoundDeviceEngine* engine = channel->fRealEngine; - + // Make sure that our connection is the one being disconnected if (where == channel->fOutput.destination && what == channel->fOutput.source) { @@ -1284,12 +1286,12 @@ } -void +void OpenSoundNode::LateNoticeReceived(const media_source& what, bigtime_t how_much, bigtime_t performance_time) { CALLED(); - + // is this our output? NodeOutput *channel = _FindOutput(what); if (channel == NULL) @@ -1327,7 +1329,7 @@ } -void +void OpenSoundNode::EnableOutput(const media_source& what, bool enabled, int32* _deprecated_) { @@ -1338,14 +1340,14 @@ // node only has one output, so I just make sure the given source matches, then set // the enable state accordingly. NodeOutput *channel = _FindOutput(what); - + if (channel != NULL) { channel->fOutputEnabled = enabled; } } -void +void OpenSoundNode::AdditionalBufferRequested(const media_source& source, media_buffer_id prev_buffer, bigtime_t prev_time, const media_seek_tag* prev_tag) @@ -1413,22 +1415,22 @@ fprintf(stderr,"OpenSoundNode::HandleBuffer() - B_BAD_VALUE\n"); return B_BAD_VALUE; } - + NodeInput *channel = _FindInput(buffer->Header()->destination); // TRACE("buffer->Header()->destination : %i\n", // buffer->Header()->destination); - + if (channel == NULL) { buffer->Recycle(); fprintf(stderr,"OpenSoundNode::HandleBuffer() - " "B_MEDIA_BAD_DESTINATION\n"); return B_MEDIA_BAD_DESTINATION; } - + media_header* hdr = buffer->Header(); bigtime_t now = TimeSource()->Now(); bigtime_t perf_time = hdr->start_time; - + // the how_early calculated here doesn't include scheduling latency // because we've already been scheduled to handle the buffer bigtime_t how_early = perf_time - EventLatency() - now; @@ -1471,7 +1473,7 @@ { // CALLED(); - // TODO: this is called mostly whenever the system mixer + // TODO: this is called mostly whenever the system mixer // switches from not sending us buffers (no client connected) // to sending buffers, and vice versa. In a Terminal, this // can be nicely demonstrated by provoking a system beep while @@ -1527,7 +1529,7 @@ return B_OK; } - + status_t OpenSoundNode::HandleWarp(const media_timed_event* event, bigtime_t lateness, bool realTimeEvent) @@ -1581,10 +1583,10 @@ if (RunState() != BMediaEventLooper::B_STARTED) { fTimeSourceStarted = true; fTimeSourceStartTime = RealTime(); - + media_timed_event startEvent(0, BTimedEventQueue::B_START); EventQueue()->AddEvent(startEvent); - } + } break; case B_TIMESOURCE_STOP: TRACE("TimeSourceOp op B_TIMESOURCE_STOP\n"); @@ -1620,7 +1622,7 @@ // #pragma mark - BControllable -status_t +status_t OpenSoundNode::GetParameterValue(int32 id, bigtime_t* last_change, void* value, size_t* ioSize) { @@ -1628,13 +1630,13 @@ int channelCount = 1; int sliderShift = 8; - + OpenSoundDeviceMixer* mixer = fDevice->MixerAt(0); if (!mixer) return ENODEV; TRACE("id : %i, *ioSize=%d\n", id, *ioSize); - + oss_mixext mixext; status_t err = mixer->GetExtInfo(id, &mixext); if (err < B_OK) @@ -1643,11 +1645,11 @@ oss_mixer_value mixval; mixval.ctrl = mixext.ctrl; mixval.timestamp = mixext.timestamp; - + err = mixer->GetMixerValue(&mixval); if (err < B_OK) return err; - + if (!(mixext.flags & MIXF_READABLE)) return EINVAL; @@ -1664,7 +1666,7 @@ TRACE("%s: value = 0x%08x\n", __FUNCTION__, mixval.value); *last_change = system_time();//?? - + switch (mixext.type) { case MIXT_DEVROOT: case MIXT_GROUP: @@ -1694,7 +1696,7 @@ return EINVAL; if (parameter->Type() != BParameter::B_CONTINUOUS_PARAMETER) return EINVAL; - if (mixext.type == MIXT_STEREOSLIDER16 || + if (mixext.type == MIXT_STEREOSLIDER16 || mixext.type == MIXT_MONOSLIDER16) sliderShift = 16; *ioSize = channelCount * sizeof(float); @@ -1744,7 +1746,7 @@ } -void +void OpenSoundNode::SetParameterValue(int32 id, bigtime_t performance_time, const void* value, size_t size) { @@ -1752,11 +1754,11 @@ TRACE("id : %i, performance_time : %lld, size : %i\n", id, performance_time, size); - + OpenSoundDeviceMixer *mixer = fDevice->MixerAt(0); if (mixer == NULL) return; - + oss_mixext mixext; if (mixer->GetExtInfo(id, &mixext) < B_OK) return; @@ -1766,14 +1768,14 @@ oss_mixer_value mixval; mixval.ctrl = mixext.ctrl; mixval.timestamp = mixext.timestamp; - + status_t err = mixer->GetMixerValue(&mixval); if (err < B_OK) return; mixval.ctrl = mixext.ctrl; mixval.timestamp = mixext.timestamp; - + BParameter *parameter = NULL; for(int32 i=0; iCountParameters(); i++) { parameter = fWeb->ParameterAt(i); @@ -1803,7 +1805,7 @@ // XXX: find something better, doesn't work correctly here. // XXX: try a timed event ? _PropagateParameterChanges(mixext.ctrl, mixext.type, mixext.id); - + return; case MIXT_ENUM: if (size < sizeof(int32)) @@ -1823,22 +1825,22 @@ return; if (parameter->Type() != BParameter::B_CONTINUOUS_PARAMETER) return; - if (mixext.type == MIXT_STEREOSLIDER16 || + if (mixext.type == MIXT_STEREOSLIDER16 || mixext.type == MIXT_MONOSLIDER16) sliderShift = 16; mixval.value = 0; - + TRACE("-------- sliderShift=%d, v = %08x, v & %08x = %08x\n", sliderShift, mixval.value, ((1 << sliderShift) - 1), mixval.value & ((1 << sliderShift) - 1)); - + mixval.value |= ((int)(((float *)value)[0])) & ((1 << sliderShift) - 1); if (channelCount > 1) { mixval.value |= (((int)(((float *)value)[1])) & ((1 << sliderShift) - 1)) << sliderShift; } - + TRACE("%s: value = 0x%08x\n", __FUNCTION__, mixval.value); mixer->SetMixerValue(&mixval); return; @@ -1875,23 +1877,23 @@ TRACE("OpenSoundNode::%s: unknown mixer control type %d\n", __FUNCTION__, mixext.type); } - + return; } -BParameterWeb* +BParameterWeb* OpenSoundNode::MakeParameterWeb() { CALLED(); BParameterWeb* web = new BParameterWeb; - - // TODO: the card might change the mixer controls at some point, + + // TODO: the card might change the mixer controls at some point, // we should detect it (poll) and recreate the parameter web and - // re-set it. - + // re-set it. + // TODO: cache mixext[...] and poll for changes in their update_counter. - + OpenSoundDeviceMixer* mixer = fDevice->MixerAt(0); if (mixer == NULL) { // some cards don't have a mixer, just put a placeholder then @@ -1900,7 +1902,7 @@ B_GENERIC); return web; } - + int mixext_count = mixer->CountExtInfos(); TRACE("OpenSoundNode::MakeParameterWeb %i ExtInfos\n", mixext_count); @@ -1908,7 +1910,7 @@ oss_mixext mixext; if (mixer->GetExtInfo(i, &mixext) < B_OK) continue; - + if (mixext.type == MIXT_DEVROOT) { oss_mixext_root* extroot = (oss_mixext_root*)mixext.data; TRACE("OpenSoundNode: mixext[%d]: ROOT\n", i); @@ -1927,7 +1929,7 @@ // #pragma mark - OpenSoundNode specific -void +void OpenSoundNode::_ProcessGroup(BParameterGroup *group, int32 index, int32& nbParameters) { @@ -1943,7 +1945,7 @@ // only keep direct children of that group if (mixext.parent != index) continue; - + int32 nb = 1; TRACE("OpenSoundNode: mixext[%d]: { %s/%s, type=%d, parent=%d, " @@ -1955,19 +1957,19 @@ mixext.minvalue, mixext.maxvalue, mixext.flags, mixext.control_no, mixext.desc, mixext.update_counter); - + // should actually rename the whole group but it's too late there. const char *childName = mixext.extname; if (mixext.flags & MIXF_MAINVOL) childName = "Master Gain"; - + const char *sliderUnit = "";//"(linear)"; if (mixext.flags & MIXF_HZ) sliderUnit = "Hz"; - + const char *continuousKind = B_GAIN; BParameterGroup* child; - + switch (mixext.type) { case MIXT_DEVROOT: // root item, should be done already @@ -1998,7 +2000,7 @@ case MIXT_ENUM: { TRACE("OpenSoundNode: mixext[%d]: ENUM\n", i); - BDiscreteParameter *parameter = + BDiscreteParameter *parameter = group->MakeDiscreteParameter(i, B_MEDIA_RAW_AUDIO, childName, B_INPUT_MUX); if (nbParameters > 0) { @@ -2021,7 +2023,7 @@ // fall through case MIXT_STEREOSLIDER: TRACE("OpenSoundNode: mixext[%d]: [MONO|STEREO]SLIDER\n", i); - + if (mixext.flags & MIXF_MAINVOL) continuousKind = B_MASTER_GAIN; @@ -2030,23 +2032,23 @@ // true;//step size // if (mixext.flags & MIXF_DECIBEL) // true;//step size - + group->MakeContinuousParameter(i, B_MEDIA_RAW_AUDIO, childName, continuousKind, sliderUnit, mixext.minvalue, mixext.maxvalue, /*TODO: should be "granularity"*/1); - - if (mixext.type == MIXT_STEREOSLIDER || - mixext.type == MIXT_STEREOSLIDER16 || + + if (mixext.type == MIXT_STEREOSLIDER || + mixext.type == MIXT_STEREOSLIDER16 || mixext.type == MIXT_STEREODB) group->ParameterAt(nbParameters)->SetChannelCount(2); - + TRACE("nb parameters : %d\n", nbParameters); if (nbParameters > 0) { (group->ParameterAt(nbParameters - 1))->AddOutput( group->ParameterAt(nbParameters)); nbParameters++; } - + break; case MIXT_MESSAGE: break; @@ -2091,7 +2093,7 @@ } -void +void OpenSoundNode::_ProcessMux(BDiscreteParameter* parameter, int32 index) { CALLED(); @@ -2112,7 +2114,7 @@ } return; } - + for (int32 i = 0; i < enuminfo.nvalues; i++) { parameter->AddItem(i, &enuminfo.strings[enuminfo.strindex[i]]); } @@ -2120,7 +2122,7 @@ } -status_t +status_t OpenSoundNode::_PropagateParameterChanges(int from, int type, const char* id) { CALLED(); @@ -2131,38 +2133,38 @@ OpenSoundDeviceMixer* mixer = fDevice->MixerAt(0); if (mixer == NULL) return ENODEV; - + // TODO: Cortex doesn't like that! // try timed event [... truncated: 157 lines follow ...] From mmlr at mail.berlios.de Fri Sep 12 18:48:59 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Fri, 12 Sep 2008 18:48:59 +0200 Subject: [Haiku-commits] r27455 - haiku/trunk/src/add-ons/kernel/bus_managers/usb Message-ID: <200809121648.m8CGmxE3022918@sheep.berlios.de> Author: mmlr Date: 2008-09-12 18:48:41 +0200 (Fri, 12 Sep 2008) New Revision: 27455 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27455&view=rev Modified: haiku/trunk/src/add-ons/kernel/bus_managers/usb/Stack.cpp Log: * CID 7: The fObjectArray that holds the usb_id to object association was never freed. * Also the allocation of said array was not checked. Modified: haiku/trunk/src/add-ons/kernel/bus_managers/usb/Stack.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/usb/Stack.cpp 2008-09-12 16:29:52 UTC (rev 27454) +++ haiku/trunk/src/add-ons/kernel/bus_managers/usb/Stack.cpp 2008-09-12 16:48:41 UTC (rev 27455) @@ -33,6 +33,11 @@ size_t objectArraySize = fObjectMaxCount * sizeof(Object *); fObjectArray = (Object **)malloc(objectArraySize); + if (fObjectArray == NULL) { + TRACE_ERROR(("USB Stack: failed to allocate object array\n")); + return; + } + memset(fObjectArray, 0, objectArraySize); fAllocator = new(std::nothrow) PhysicalMemoryAllocator("USB Stack Allocator", @@ -113,6 +118,7 @@ } delete fAllocator; + free(fObjectArray); } From mmlr at mail.berlios.de Fri Sep 12 19:00:47 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Fri, 12 Sep 2008 19:00:47 +0200 Subject: [Haiku-commits] r27456 - haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid Message-ID: <200809121700.m8CH0l5D003928@sheep.berlios.de> Author: mmlr Date: 2008-09-12 19:00:28 +0200 (Fri, 12 Sep 2008) New Revision: 27456 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27456&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/DeviceList.cpp haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/Driver.cpp haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/HIDDevice.cpp Log: * Use new(std::nothrow) everywhere (NULL checks were already there). * Fix a warning if trace output is not enabled. Modified: haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/DeviceList.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/DeviceList.cpp 2008-09-12 16:48:41 UTC (rev 27455) +++ haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/DeviceList.cpp 2008-09-12 17:00:28 UTC (rev 27456) @@ -7,6 +7,7 @@ #include #include #include +#include struct device_list_entry { char * name; @@ -40,7 +41,7 @@ status_t DeviceList::AddDevice(const char *name, void *device) { - device_list_entry *entry = new device_list_entry; + device_list_entry *entry = new(std::nothrow) device_list_entry; if (entry == NULL) return B_NO_MEMORY; Modified: haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/Driver.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/Driver.cpp 2008-09-12 16:48:41 UTC (rev 27455) +++ haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/Driver.cpp 2008-09-12 17:00:28 UTC (rev 27456) @@ -16,7 +16,9 @@ #include "BeOSCompatibility.h" // for pseudo mutex #endif +#include + int32 api_version = B_CUR_DRIVER_API_VERSION; usb_module_info *gUSBModule = NULL; DeviceList *gDeviceList = NULL; @@ -68,9 +70,9 @@ const usb_interface_info *interface = config->interface[i].active; uint8 interfaceClass = interface->descr->interface_class; uint8 interfaceSubclass = interface->descr->interface_subclass; - uint8 interfaceProtocol = interface->descr->interface_protocol; TRACE("interface %lu: class: %u; subclass: %u; protocol: %u\n", - i, interfaceClass, interfaceSubclass, interfaceProtocol); + i, interfaceClass, interfaceSubclass, + interface->descr->interface_protocol); if (interfaceClass == USB_INTERFACE_CLASS_HID && interfaceSubclass == USB_INTERFACE_SUBCLASS_HID_BOOT) { @@ -221,7 +223,7 @@ if (get_module(B_USB_MODULE_NAME, (module_info **)&gUSBModule) != B_OK) return B_ERROR; - gDeviceList = new DeviceList(); + gDeviceList = new(std::nothrow) DeviceList(); if (gDeviceList == NULL) { put_module(B_USB_MODULE_NAME); return B_NO_MEMORY; Modified: haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/HIDDevice.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/HIDDevice.cpp 2008-09-12 16:48:41 UTC (rev 27455) +++ haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/HIDDevice.cpp 2008-09-12 17:00:28 UTC (rev 27456) @@ -8,6 +8,7 @@ #include #include #include +#include // includes for the different device types #include "KeyboardDevice.h" @@ -181,11 +182,14 @@ // determine device type and create the device object if (deviceType == USB_HID_DEVICE_TYPE_KEYBOARD) { - return new KeyboardDevice(device, interruptPipe, interfaceIndex, - finalInstructions, instructionCount, totalReportSize); - } else if (deviceType == USB_HID_DEVICE_TYPE_MOUSE) { - return new MouseDevice(device, interruptPipe, interfaceIndex, - finalInstructions, instructionCount, totalReportSize); + return new(std::nothrow) KeyboardDevice(device, interruptPipe, + interfaceIndex, finalInstructions, instructionCount, + totalReportSize); + } else if (deviceType == USB_HID_DEVICE_TYPE_MOUSE + || deviceType == 0x01250015) { + return new(std::nothrow) MouseDevice(device, interruptPipe, + interfaceIndex, finalInstructions, instructionCount, + totalReportSize); } TRACE_ALWAYS("unsupported device type 0x%08lx\n", deviceType); From mmlr at mail.berlios.de Fri Sep 12 19:10:41 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Fri, 12 Sep 2008 19:10:41 +0200 Subject: [Haiku-commits] r27457 - haiku/trunk/src/add-ons/kernel/bus_managers/usb Message-ID: <200809121710.m8CHAf9C015093@sheep.berlios.de> Author: mmlr Date: 2008-09-12 19:10:35 +0200 (Fri, 12 Sep 2008) New Revision: 27457 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27457&view=rev Modified: haiku/trunk/src/add-ons/kernel/bus_managers/usb/Device.cpp Log: Check the allocation of the endpoint pipe object. Modified: haiku/trunk/src/add-ons/kernel/bus_managers/usb/Device.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/usb/Device.cpp 2008-09-12 17:00:28 UTC (rev 27456) +++ haiku/trunk/src/add-ons/kernel/bus_managers/usb/Device.cpp 2008-09-12 17:10:35 UTC (rev 27457) @@ -467,6 +467,13 @@ break; } + if (pipe == NULL) { + TRACE_ERROR(("USB Device %d: failed to allocate pipe\n", + fDeviceAddress)); + endpoint->handle = 0; + continue; + } + pipe->InitCommon(fDeviceAddress, endpoint->descr->endpoint_address & 0x0f, fSpeed, direction, endpoint->descr->max_packet_size, From mmlr at mail.berlios.de Fri Sep 12 19:17:42 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Fri, 12 Sep 2008 19:17:42 +0200 Subject: [Haiku-commits] r27458 - haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid Message-ID: <200809121717.m8CHHg4s023581@sheep.berlios.de> Author: mmlr Date: 2008-09-12 19:17:29 +0200 (Fri, 12 Sep 2008) New Revision: 27458 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27458&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/DeviceList.cpp Log: CID 1261: The "previous" list entry wasn't maintained, causing lost list items when removing a non-first element. Modified: haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/DeviceList.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/DeviceList.cpp 2008-09-12 17:10:35 UTC (rev 27457) +++ haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/DeviceList.cpp 2008-09-12 17:17:29 UTC (rev 27458) @@ -95,6 +95,7 @@ return B_OK; } + previous = current; current = current->next; } From stippi at mail.berlios.de Fri Sep 12 19:24:34 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Fri, 12 Sep 2008 19:24:34 +0200 Subject: [Haiku-commits] r27459 - haiku/trunk/src/apps/mediaplayer/supplier Message-ID: <200809121724.m8CHOYXb032415@sheep.berlios.de> Author: stippi Date: 2008-09-12 19:24:32 +0200 (Fri, 12 Sep 2008) New Revision: 27459 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27459&view=rev Modified: haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.cpp Log: Fixed CID 1292. If the allocation or adding to the list of the very first Buffer failed, the buffer data would be leaked. Note that for failure to allocate later buffers, the data is correctly freed in _FreeBuffers(). Modified: haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.cpp 2008-09-12 17:17:29 UTC (rev 27458) +++ haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.cpp 2008-09-12 17:24:32 UTC (rev 27459) @@ -212,7 +212,7 @@ int64 MediaTrackAudioSupplier::_FramesPerBuffer() const { - int64 sampleSize = fFormat.u.raw_audio.format + int64 sampleSize = fFormat.u.raw_audio.format & media_raw_audio_format::B_AUDIO_SIZE_MASK; int64 frameSize = sampleSize * fFormat.u.raw_audio.channel_count; return fFormat.u.raw_audio.buffer_size / frameSize; @@ -229,7 +229,7 @@ void* target, int64 targetOffset, int64 position, int64 frames) const { - int64 sampleSize = fFormat.u.raw_audio.format + int64 sampleSize = fFormat.u.raw_audio.format & media_raw_audio_format::B_AUDIO_SIZE_MASK; int64 frameSize = sampleSize * fFormat.u.raw_audio.channel_count; source = (char*)source + frameSize * (position - sourceOffset); @@ -266,6 +266,8 @@ Buffer* buffer = new (nothrow) Buffer; if (!buffer || !fBuffers.AddItem(buffer)) { delete buffer; + if (fBuffers.CountItems() == 0) + delete[] data; return; } buffer->data = data; @@ -521,7 +523,7 @@ } } // Ensure that all frames up to the next key frame are cached. - // This avoids, that each read + // This avoids, that each read if (error == B_OK) { int64 nextKeyFrame = currentPos; if (_FindKeyFrameForward(nextKeyFrame) == B_OK) { From stippi at mail.berlios.de Fri Sep 12 19:31:50 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Fri, 12 Sep 2008 19:31:50 +0200 Subject: [Haiku-commits] r27460 - haiku/trunk/src/add-ons/kernel/network/stack Message-ID: <200809121731.m8CHVoXD018718@sheep.berlios.de> Author: stippi Date: 2008-09-12 19:31:48 +0200 (Fri, 12 Sep 2008) New Revision: 27460 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27460&view=rev Modified: haiku/trunk/src/add-ons/kernel/network/stack/stack_interface.cpp Log: Fixed CID 1272. Looks like _addressLength is allowed to be NULL, but at function exit, it was still dereferenced. Modified: haiku/trunk/src/add-ons/kernel/network/stack/stack_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/stack/stack_interface.cpp 2008-09-12 17:24:32 UTC (rev 27459) +++ haiku/trunk/src/add-ons/kernel/network/stack/stack_interface.cpp 2008-09-12 17:31:48 UTC (rev 27460) @@ -99,7 +99,8 @@ if (error != B_OK) return error; - *_addressLength = message.msg_namelen; + if (_addressLength != NULL) + *_addressLength = message.msg_namelen; return B_OK; } From axeld at pinc-software.de Fri Sep 12 19:53:27 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Fri, 12 Sep 2008 19:53:27 +0200 CEST Subject: [Haiku-commits] =?utf-8?q?r27456_-_haiku/trunk/src/add-ons/kernel?= =?utf-8?q?/drivers/input/usb=5Fhid?= In-Reply-To: <200809121700.m8CH0l5D003928@sheep.berlios.de> Message-ID: <37403679705-BeMail@zon> mmlr at mail.berlios.de wrote: > Log: > * Use new(std::nothrow) everywhere (NULL checks were already there). > * Fix a warning if trace output is not enabled. [...] > #include > #include > #include > +#include Although this improves clarity, the header already replaces the standard new with new(std::nothrow). Bye, Axel. From mmlr at mail.berlios.de Fri Sep 12 20:02:09 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Fri, 12 Sep 2008 20:02:09 +0200 Subject: [Haiku-commits] r27461 - haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid Message-ID: <200809121802.m8CI29DN031891@sheep.berlios.de> Author: mmlr Date: 2008-09-12 20:02:07 +0200 (Fri, 12 Sep 2008) New Revision: 27461 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27461&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/HIDDevice.cpp Log: * Don't leak the decoded instructions in case the device object cannot be allocated. * Remove accidentally added debug device id. Modified: haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/HIDDevice.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/HIDDevice.cpp 2008-09-12 17:31:48 UTC (rev 27460) +++ haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/HIDDevice.cpp 2008-09-12 18:02:07 UTC (rev 27461) @@ -181,20 +181,21 @@ } // determine device type and create the device object + HIDDevice *hidDevice = NULL; if (deviceType == USB_HID_DEVICE_TYPE_KEYBOARD) { - return new(std::nothrow) KeyboardDevice(device, interruptPipe, + hidDevice = new(std::nothrow) KeyboardDevice(device, interruptPipe, interfaceIndex, finalInstructions, instructionCount, totalReportSize); - } else if (deviceType == USB_HID_DEVICE_TYPE_MOUSE - || deviceType == 0x01250015) { - return new(std::nothrow) MouseDevice(device, interruptPipe, + } else if (deviceType == USB_HID_DEVICE_TYPE_MOUSE) { + hidDevice = new(std::nothrow) MouseDevice(device, interruptPipe, interfaceIndex, finalInstructions, instructionCount, totalReportSize); - } + } else + TRACE_ALWAYS("unsupported device type 0x%08lx\n", deviceType); - TRACE_ALWAYS("unsupported device type 0x%08lx\n", deviceType); - free(finalInstructions); - return NULL; + if (hidDevice == NULL) + free(finalInstructions); + return hidDevice; } From oliver.ruiz.dorantes at gmail.com Fri Sep 12 20:03:28 2008 From: oliver.ruiz.dorantes at gmail.com (Oliver Ruiz Dorantes) Date: Fri, 12 Sep 2008 20:03:28 +0200 Subject: [Haiku-commits] r27453 - haiku/trunk/src/preferences/filetypes In-Reply-To: <24813262096-BeMail@zon> References: <200809121415.m8CEFoBk011938@sheep.berlios.de> <24813262096-BeMail@zon> Message-ID: This brings me to a question: it is ok to "Class* var" instead of "Class *var" if we are consistent? are we allowed to use the star on left side? thanks 2008/9/12 Axel D?rfler > modeenf at mail.berlios.de wrote: > > - BBitmap* mini = NULL; > > - BBitmap* large = NULL; > > + BBitmap *mini = NULL; > > + BBitmap *large = NULL; > > And also, please don't change the coding style to something > inconsistent. The whole file uses "* ", not " *". Please change back. > > Bye, > Axel. > > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > -- Oliver, http://urnenfeld.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From modeenf at mail.berlios.de Fri Sep 12 20:06:53 2008 From: modeenf at mail.berlios.de (modeenf at mail.berlios.de) Date: Fri, 12 Sep 2008 20:06:53 +0200 Subject: [Haiku-commits] r27462 - haiku/trunk/src/preferences/filetypes Message-ID: <200809121806.m8CI6rXb032552@sheep.berlios.de> Author: modeenf Date: 2008-09-12 20:06:52 +0200 (Fri, 12 Sep 2008) New Revision: 27462 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27462&view=rev Modified: haiku/trunk/src/preferences/filetypes/IconView.cpp Log: fixes pointed out by Michael and Axel, thanks for pointing those out. Modified: haiku/trunk/src/preferences/filetypes/IconView.cpp =================================================================== --- haiku/trunk/src/preferences/filetypes/IconView.cpp 2008-09-12 18:02:07 UTC (rev 27461) +++ haiku/trunk/src/preferences/filetypes/IconView.cpp 2008-09-12 18:06:52 UTC (rev 27462) @@ -574,8 +574,8 @@ if (message->WasDropped() && message->ReturnAddress() != BMessenger(this) && AcceptsDrag(message)) { // set icon from message - BBitmap *mini = NULL; - BBitmap *large = NULL; + BBitmap* mini = NULL; + BBitmap* large = NULL; const uint8* data = NULL; ssize_t size = 0; @@ -597,9 +597,9 @@ _SetIcon(&ref); } - delete(large); - delete(mini); - delete(data); + delete large; + delete mini; + delete data; return; } From fredrik at modeen.se Fri Sep 12 19:59:20 2008 From: fredrik at modeen.se (Fredrik =?iso-8859-1?Q?Mod=E9en?=) Date: Fri, 12 Sep 2008 19:59:20 +0200 (CEST) Subject: [Haiku-commits] r27456 - haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid In-Reply-To: <37403679705-BeMail@zon> References: <200809121700.m8CH0l5D003928@sheep.berlios.de> <37403679705-BeMail@zon> Message-ID: <41226.81.226.238.201.1221242360.squirrel@webmail2.webbhotellsgruppen.se> > mmlr at mail.berlios.de wrote: >> Log: >> * Use new(std::nothrow) everywhere (NULL checks were already there). >> * Fix a warning if trace output is not enabled. > [...] >> #include >> #include >> #include >> +#include > > Although this improves clarity, the header already > replaces the standard new with new(std::nothrow). So I don't need to use new(std::nothrow)? (thought that this was mine as I have used this as well) If that's true then I'm happy :) > > Bye, > Axel. > > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > -- MVH Fredrik Mod?en From axeld at pinc-software.de Fri Sep 12 20:12:17 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Fri, 12 Sep 2008 20:12:17 +0200 CEST Subject: [Haiku-commits] r27453 - haiku/trunk/src/preferences/filetypes In-Reply-To: Message-ID: <38533809056-BeMail@zon> "Oliver Ruiz Dorantes" wrote: > This brings me to a question: > it is ok to "Class* var" > > instead of "Class *var" if we are consistent? > > are we allowed to use the star on left side? Some time ago we agreed on preferring "* " instead of " *" in C++ files, but allow both in our sources according to the maintainer's preference. That means we only ask for a consistent use in a source file, not a specific style (in this regard only, of course :-)). Bye, Axel. From axeld at pinc-software.de Fri Sep 12 20:13:33 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Fri, 12 Sep 2008 20:13:33 +0200 CEST Subject: [Haiku-commits] r27456 - haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid In-Reply-To: <41226.81.226.238.201.1221242360.squirrel@webmail2.webbhotellsgruppen.se> Message-ID: <38609638660-BeMail@zon> Fredrik Mod?en wrote: > > Although this improves clarity, the header already > > replaces the standard new with new(std::nothrow). > So I don't need to use new(std::nothrow)? > (thought that this was mine as I have used this as well) > > If that's true then I'm happy :) This applies only for kernel drivers, therefore that header is called "kernel_cpp.h". For userland APIs, you still have to use it, and we actually started to use it in the kernel as well, as kernel_cpp.h itself is no longer needed in Haiku. Bye, Axel. From modeenf at mail.berlios.de Fri Sep 12 20:29:17 2008 From: modeenf at mail.berlios.de (modeenf at mail.berlios.de) Date: Fri, 12 Sep 2008 20:29:17 +0200 Subject: [Haiku-commits] r27463 - haiku/trunk/src/kits/device Message-ID: <200809121829.m8CITHGn002057@sheep.berlios.de> Author: modeenf Date: 2008-09-12 20:29:16 +0200 (Fri, 12 Sep 2008) New Revision: 27463 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27463&view=rev Modified: haiku/trunk/src/kits/device/SerialPort.cpp Log: fixes pointed out by Axel, and style changes. Modified: haiku/trunk/src/kits/device/SerialPort.cpp =================================================================== --- haiku/trunk/src/kits/device/SerialPort.cpp 2008-09-12 18:06:52 UTC (rev 27462) +++ haiku/trunk/src/kits/device/SerialPort.cpp 2008-09-12 18:29:16 UTC (rev 27463) @@ -56,17 +56,18 @@ - Blocking mode */ BSerialPort::BSerialPort() - : ffd(-1), - fBaudRate(B_19200_BPS), - fDataBits(B_DATA_BITS_8), - fStopBits(B_STOP_BIT_1), - fParityMode(B_NO_PARITY), - fFlow(B_HARDWARE_CONTROL), - fTimeout(B_INFINITE_TIMEOUT), - fBlocking(true), - _fDevices(new(std::nothrow) BList) + : + ffd(-1), + fBaudRate(B_19200_BPS), + fDataBits(B_DATA_BITS_8), + fStopBits(B_STOP_BIT_1), + fParityMode(B_NO_PARITY), + fFlow(B_HARDWARE_CONTROL), + fTimeout(B_INFINITE_TIMEOUT), + fBlocking(true), + fDevices(new(std::nothrow) BList) { - ScanDevices(); + _ScanDevices(); } @@ -78,10 +79,11 @@ if (ffd >= 0) close(ffd); - for (int32 count = _fDevices->CountItems() - 1; count >= 0; count--) - free(_fDevices->RemoveItem(count)); - - delete _fDevices; + if (fDevices != NULL) { + for (int32 count = fDevices->CountItems() - 1; count >= 0; count--) + free(fDevices->RemoveItem(count)); + delete fDevices; + } } @@ -122,7 +124,7 @@ int flags = fcntl(ffd, F_GETFL); fcntl(ffd, F_SETFL, flags & ~O_NONBLOCK); - DriverControl(); + _DriverControl(); } // TODO: I wonder why the return type is a status_t, // since we (as BeOS does) return the descriptor number for the device... @@ -175,7 +177,7 @@ BSerialPort::SetBlocking(bool Blocking) { fBlocking = Blocking; - DriverControl(); + _DriverControl(); } @@ -193,7 +195,7 @@ if (microSeconds == B_INFINITE_TIMEOUT || microSeconds <= 25000000) { fTimeout = microSeconds; - DriverControl(); + _DriverControl(); err = B_OK; } return err; @@ -232,7 +234,7 @@ { fBaudRate = bitsPerSecond; - return DriverControl(); + return _DriverControl(); } @@ -253,7 +255,7 @@ BSerialPort::SetDataBits(data_bits numBits) { fDataBits = numBits; - DriverControl(); + _DriverControl(); } @@ -277,7 +279,7 @@ BSerialPort::SetStopBits(stop_bits numBits) { fStopBits = numBits; - DriverControl(); + _DriverControl(); } @@ -302,7 +304,7 @@ BSerialPort::SetParityMode(parity_mode which) { fParityMode = which; - DriverControl(); + _DriverControl(); } @@ -345,7 +347,7 @@ BSerialPort::SetFlowControl(uint32 method) { fFlow = method; - DriverControl(); + _DriverControl(); } @@ -484,10 +486,10 @@ int32 count = 0; // Refresh devices list - ScanDevices(); + _ScanDevices(); - if (_fDevices != NULL) - count = _fDevices->CountItems(); + if (fDevices != NULL) + count = fDevices->CountItems(); return count; } @@ -507,8 +509,8 @@ status_t result = B_ERROR; const char *dev = NULL; - if (_fDevices != NULL) - dev = static_cast(_fDevices->ItemAt(n)); + if (fDevices != NULL) + dev = static_cast(fDevices->ItemAt(n)); if (dev != NULL && name != NULL) { strncpy(name, dev, bufSize); @@ -526,14 +528,16 @@ and build a list of them. */ void -BSerialPort::ScanDevices() +BSerialPort::_ScanDevices() { // First, we empty the list - for (int32 count = _fDevices->CountItems() - 1; count >= 0; count--) - free(_fDevices->RemoveItem(count)); - - // Add devices to the list - scan_directory(SERIAL_DIR, _fDevices); + if (fDevices != NULL) { + for (int32 count = fDevices->CountItems() - 1; count >= 0; count--) + free(fDevices->RemoveItem(count)); + + // Add devices to the list + scan_directory(SERIAL_DIR, fDevices); + } } @@ -543,7 +547,7 @@ - an error code if something goes wrong. */ int -BSerialPort::DriverControl() +BSerialPort::_DriverControl() { struct termios options; int err; From modeenf at mail.berlios.de Fri Sep 12 20:29:32 2008 From: modeenf at mail.berlios.de (modeenf at mail.berlios.de) Date: Fri, 12 Sep 2008 20:29:32 +0200 Subject: [Haiku-commits] r27464 - haiku/trunk/headers/os/device Message-ID: <200809121829.m8CITWPB002137@sheep.berlios.de> Author: modeenf Date: 2008-09-12 20:29:30 +0200 (Fri, 12 Sep 2008) New Revision: 27464 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27464&view=rev Modified: haiku/trunk/headers/os/device/SerialPort.h Log: fixes pointed by Axel and some stile changes. Modified: haiku/trunk/headers/os/device/SerialPort.h =================================================================== --- haiku/trunk/headers/os/device/SerialPort.h 2008-09-12 18:29:16 UTC (rev 27463) +++ haiku/trunk/headers/os/device/SerialPort.h 2008-09-12 18:29:30 UTC (rev 27464) @@ -84,8 +84,8 @@ private: - void ScanDevices(); - + void _ScanDevices(); + int _DriverControl(); virtual void _ReservedSerialPort1(); virtual void _ReservedSerialPort2(); virtual void _ReservedSerialPort3(); @@ -98,12 +98,9 @@ parity_mode fParityMode; uint32 fFlow; bigtime_t fTimeout; - bool fBlocking; - - int DriverControl(); - - BList * _fDevices; - uint32 _fReserved[3]; + bool fBlocking; + BList * fDevices; + uint32 fReserved[3]; }; #endif From modeenf at mail.berlios.de Fri Sep 12 21:08:33 2008 From: modeenf at mail.berlios.de (modeenf at mail.berlios.de) Date: Fri, 12 Sep 2008 21:08:33 +0200 Subject: [Haiku-commits] r27465 - haiku/trunk/src/apps/glteapot Message-ID: <200809121908.m8CJ8XEB005923@sheep.berlios.de> Author: modeenf Date: 2008-09-12 21:08:31 +0200 (Fri, 12 Sep 2008) New Revision: 27465 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27465&view=rev Modified: haiku/trunk/src/apps/glteapot/TeapotWindow.cpp Log: fixes CID 455 Check for NULL and use std::nothrow Modified: haiku/trunk/src/apps/glteapot/TeapotWindow.cpp =================================================================== --- haiku/trunk/src/apps/glteapot/TeapotWindow.cpp 2008-09-12 18:29:30 UTC (rev 27464) +++ haiku/trunk/src/apps/glteapot/TeapotWindow.cpp 2008-09-12 19:08:31 UTC (rev 27465) @@ -7,6 +7,7 @@ #include #include #include +#include #include "TeapotWindow.h" @@ -34,9 +35,8 @@ AddChild(subView); bounds = subView->Bounds(); - fObjectView = new ObjectView(bounds, "objectView", B_FOLLOW_ALL_SIDES, type); - subView->AddChild(fObjectView); - fObjectView = fObjectView; + fObjectView = new(std::nothrow) ObjectView(bounds, "objectView", B_FOLLOW_ALL_SIDES, type); + subView->AddChild(fObjectView); BMenuItem* item; msg.AddInt32("num", 256); @@ -163,8 +163,9 @@ bool TeapotWindow::QuitRequested() { -// printf("closing \n"); - fObjectView->EnableDirectMode(false); + if (fObjectView != NULL) + fObjectView->EnableDirectMode(false); + be_app->PostMessage(B_QUIT_REQUESTED); return true; } @@ -173,9 +174,10 @@ void TeapotWindow::DirectConnected(direct_buffer_info* info) { - if (fObjectView) + if (fObjectView != NULL) { fObjectView->DirectConnected(info); - fObjectView->EnableDirectMode(true); + fObjectView->EnableDirectMode(true); + } } From superstippi at gmx.de Fri Sep 12 21:12:30 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Fri, 12 Sep 2008 21:12:30 +0200 Subject: [Haiku-commits] r27453 - haiku/trunk/src/preferences/filetypes In-Reply-To: References: <200809121415.m8CEFoBk011938@sheep.berlios.de> <24813262096-BeMail@zon> Message-ID: <20080912191230.174570@gmx.net> -------- Original-Nachricht -------- > Datum: Fri, 12 Sep 2008 20:03:28 +0200 > Von: "Oliver Ruiz Dorantes" > An: "SVN commits to the Haiku source repository" > Betreff: Re: [Haiku-commits] r27453 - haiku/trunk/src/preferences/filetypes > This brings me to a question: > it is ok to "Class* var" > > instead of "Class *var" if we are consistent? > > are we allowed to use the star on left side? Yes, the last time it was discussed, the consensus reached was that it is up to the author of the code but should be used consistently. If someone contributes to someone else's code, the used style should be respected. Best regards, -Stephan From mmlr at mail.berlios.de Sat Sep 13 02:01:50 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sat, 13 Sep 2008 02:01:50 +0200 Subject: [Haiku-commits] r27466 - haiku/trunk/src/add-ons/kernel/generic/scsi_periph Message-ID: <200809130001.m8D01oRU030066@sheep.berlios.de> Author: mmlr Date: 2008-09-13 02:01:48 +0200 (Sat, 13 Sep 2008) New Revision: 27466 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27466&view=rev Modified: haiku/trunk/src/add-ons/kernel/generic/scsi_periph/io.cpp Log: CID 1258: This was probably missed when replacing all "write" with operation->IsWrite(). Modified: haiku/trunk/src/add-ons/kernel/generic/scsi_periph/io.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/generic/scsi_periph/io.cpp 2008-09-12 19:08:31 UTC (rev 27465) +++ haiku/trunk/src/add-ons/kernel/generic/scsi_periph/io.cpp 2008-09-13 00:01:48 UTC (rev 27466) @@ -293,7 +293,7 @@ // peripheral layer only created "read" error, so we have to // map them to "write" errors if this was a write request - if (res.error_code == B_DEV_READ_ERROR && write) + if (res.error_code == B_DEV_READ_ERROR && operation->IsWrite()) return B_DEV_WRITE_ERROR; return res.error_code; From mmlr at mail.berlios.de Sat Sep 13 02:07:01 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sat, 13 Sep 2008 02:07:01 +0200 Subject: [Haiku-commits] r27467 - haiku/trunk/src/add-ons/kernel/file_systems/iso9660 Message-ID: <200809130007.m8D071pJ030421@sheep.berlios.de> Author: mmlr Date: 2008-09-13 02:06:59 +0200 (Sat, 13 Sep 2008) New Revision: 27467 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27467&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/iso9660/kernel_interface.cpp Log: CID 877: Fix memory leak in error case. Modified: haiku/trunk/src/add-ons/kernel/file_systems/iso9660/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/iso9660/kernel_interface.cpp 2008-09-13 00:01:48 UTC (rev 27466) +++ haiku/trunk/src/add-ons/kernel/file_systems/iso9660/kernel_interface.cpp 2008-09-13 00:06:59 UTC (rev 27467) @@ -328,8 +328,10 @@ TRACE(("fs_read_vnode - block = %ld, pos = %ld, raw = %Lu node 0x%x\n", block, pos, vnodeID, newNode)); - if (pos > ns->logicalBlkSize[FS_DATA_FORMAT]) + if (pos > ns->logicalBlkSize[FS_DATA_FORMAT]) { + free(newNode); return B_BAD_VALUE; + } char *data = (char *)block_cache_get_etc(ns->fBlockCache, block, 0, ns->logicalBlkSize[FS_DATA_FORMAT]); From mmlr at mail.berlios.de Sat Sep 13 02:10:43 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sat, 13 Sep 2008 02:10:43 +0200 Subject: [Haiku-commits] r27468 - haiku/trunk/src/add-ons/kernel/file_systems/iso9660 Message-ID: <200809130010.m8D0AhWS030625@sheep.berlios.de> Author: mmlr Date: 2008-09-13 02:10:40 +0200 (Sat, 13 Sep 2008) New Revision: 27468 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27468&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/iso9660/iso9660_identify.cpp Log: CID 1021: Move NULL check before dereferencing "string" in the TRACE statement. Modified: haiku/trunk/src/add-ons/kernel/file_systems/iso9660/iso9660_identify.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/iso9660/iso9660_identify.cpp 2008-09-13 00:06:59 UTC (rev 27467) +++ haiku/trunk/src/add-ons/kernel/file_systems/iso9660/iso9660_identify.cpp 2008-09-13 00:10:40 UTC (rev 27468) @@ -196,11 +196,12 @@ iso9660_info::_SetString(char **string, const char *newString, uint32 newLength) { - TRACE(("iso9660_info::set_string(%p ('%s'), '%s', %ld)\n", string, - *string, newString, newLength)); if (string == NULL) return; + TRACE(("iso9660_info::set_string(%p ('%s'), '%s', %ld)\n", string, + *string, newString, newLength)); + char *&oldString = *string; free(oldString); From mmlr at mail.berlios.de Sat Sep 13 02:28:31 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sat, 13 Sep 2008 02:28:31 +0200 Subject: [Haiku-commits] r27469 - haiku/trunk/src/add-ons/kernel/network/protocols/tcp Message-ID: <200809130028.m8D0SVPL006188@sheep.berlios.de> Author: mmlr Date: 2008-09-13 02:28:29 +0200 (Sat, 13 Sep 2008) New Revision: 27469 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27469&view=rev Modified: haiku/trunk/src/add-ons/kernel/network/protocols/tcp/BufferQueue.cpp Log: CID 26: The status variable was shadowed inside the while loop causing the outer status to always be B_OK, resulting in an incomplete buffer instead of an error if the append failed. Modified: haiku/trunk/src/add-ons/kernel/network/protocols/tcp/BufferQueue.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/tcp/BufferQueue.cpp 2008-09-13 00:10:40 UTC (rev 27468) +++ haiku/trunk/src/add-ons/kernel/network/protocols/tcp/BufferQueue.cpp 2008-09-13 00:28:29 UTC (rev 27469) @@ -323,7 +323,7 @@ status_t status = B_OK; while (bytesLeft > 0 && (source = iterator.Next()) != NULL) { size_t size = min_c(source->size, bytesLeft); - status_t status = gBufferModule->append_cloned(buffer, source, 0, size); + status = gBufferModule->append_cloned(buffer, source, 0, size); if (status < B_OK) break; From mmlr at mail.berlios.de Sat Sep 13 02:44:16 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sat, 13 Sep 2008 02:44:16 +0200 Subject: [Haiku-commits] r27470 - haiku/trunk/src/add-ons/kernel/partitioning_systems/intel Message-ID: <200809130044.m8D0iG5X008012@sheep.berlios.de> Author: mmlr Date: 2008-09-13 02:44:12 +0200 (Sat, 13 Sep 2008) New Revision: 27470 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27470&view=rev Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/write_support.cpp Log: * CID 1044: Add more explicit NULL check before dereferencing in TRACE statement. * Whitespace cleanup. Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/write_support.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/write_support.cpp 2008-09-13 00:28:29 UTC (rev 27469) +++ haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/write_support.cpp 2008-09-13 00:44:12 UTC (rev 27470) @@ -168,7 +168,7 @@ pm_validate_resize(partition_data *partition, off_t *size) { TRACE(("intel: pm_validate_resize\n")); - + if (!partition || !size) return false; @@ -315,7 +315,7 @@ off_t *size) { TRACE(("intel: pm_validate_resize_child\n")); - + if (!partition || !child || !size) return false; @@ -328,7 +328,7 @@ pm_validate_move(partition_data *partition, off_t *start) { TRACE(("intel: pm_validate_move\n")); - + if (!partition || !start) return false; // nothing to do here @@ -383,7 +383,7 @@ off_t *start) { TRACE(("intel: pm_validate_move_child\n")); - + if (!partition || !child || !start) return false; if (*start == child->offset) @@ -428,10 +428,10 @@ pm_validate_set_type(partition_data *partition, const char *type) { TRACE(("intel: pm_validate_set_type\n")); - + if (!partition || !type) return false; - + partition_data *father = get_parent_partition(partition->id); if (!father) return false; @@ -449,7 +449,7 @@ const char *parameters) { TRACE(("intel: pm_validate_initialize\n")); - + if (!partition || !(pm_get_supported_operations(partition) & B_DISK_SYSTEM_SUPPORTS_INITIALIZING)) { return false; @@ -490,13 +490,13 @@ getSiblingPartitions(partition, NULL, *start, &previousSibling, &nextSibling, &previousOffset, &previousSize, &nextOffset, &nextSize); - + // position check of the new partition if (previousSibling && (previousOffset + previousSize > *start)) { *start = previousOffset + previousSize; *start = sector_align_up(*start); } - + if (nextSibling && (nextOffset < *start + *size)) *size = nextOffset - *start; *size = sector_align(*size); @@ -515,7 +515,7 @@ const char *type, const char *parameters, int32 *index) { TRACE(("intel: pm_validate_create_child\n")); - + if (!partition || !(pm_get_supported_operations(partition) & B_DISK_SYSTEM_SUPPORTS_CREATING_CHILD) || !start || !size || !type || !index) { @@ -624,7 +624,7 @@ // sort the array qsort(positions, partition_count, sizeof(PartitionPosition), cmp_partition_position); - + // first sektor is MBR or EBR off_t offset = startOffset + headerSize; off_t size = 0; @@ -677,7 +677,7 @@ partitionable_space_data *buffer, int32 count, int32 *actualCount) { TRACE(("intel: pm_get_partitionable_spaces\n")); - + if (!partition || !partition->content_type || strcmp(partition->content_type, kPartitionTypeIntel) || !actualCount) { @@ -697,7 +697,7 @@ char *_type) { TRACE(("intel: pm_get_next_supported_type\n")); - + if (!partition || !partition->content_type || strcmp(partition->content_type, kPartitionTypeIntel) || !cookie || !_type) { @@ -735,7 +735,7 @@ { TRACE(("intel: pm_shadow_changed(%p, %p, %lu)\n", partition, child, operation)); - + switch (operation) { case B_PARTITION_SHADOW: { @@ -897,14 +897,14 @@ pm_resize(int fd, partition_id partitionID, off_t size, disk_job_id job) { TRACE(("intel: pm_resize\n")); - + if (fd < 0) return B_ERROR; PartitionWriteLocker locker(partitionID); if (!locker.IsLocked()) return B_ERROR; - + // get out partition partition_data *partition = get_partition(partitionID); if (!partition) @@ -934,7 +934,7 @@ pm_resize_child(int fd, partition_id partitionID, off_t size, disk_job_id job) { TRACE(("intel: pm_resize_child\n")); - + if (fd < 0) return B_ERROR; @@ -987,7 +987,7 @@ pm_move(int fd, partition_id partitionID, off_t offset, disk_job_id job) { TRACE(("intel: pm_move\n")); - + if (fd < 0) return B_ERROR; @@ -1087,7 +1087,7 @@ off_t offset, disk_job_id job) { TRACE(("intel: pm_move_child\n")); - + if (fd < 0) return B_ERROR; @@ -1155,7 +1155,7 @@ pm_set_type(int fd, partition_id partitionID, const char *type, disk_job_id job) { TRACE(("intel: pm_set_type\n")); - + if (fd < 0 || !type) return B_BAD_VALUE; @@ -1221,7 +1221,7 @@ const char *parameters, off_t partitionSize, disk_job_id job) { TRACE(("intel: pm_initialize\n")); - + if (fd < 0) return B_ERROR; @@ -1258,7 +1258,7 @@ // parameter -- -1 to be ignored { TRACE(("intel: pm_create_child\n")); - + if (fd < 0 || !childID) return B_BAD_VALUE; @@ -1279,7 +1279,7 @@ off_t validatedOffset = offset; off_t validatedSize = size; int32 index = 0; - + if (!pm_validate_create_child(partition, &validatedOffset, &validatedSize, type, parameters, &index)) { return B_BAD_VALUE; @@ -1307,7 +1307,7 @@ primary->SetType(ptype.Type()); // TODO: correctly fill active parameter primary->SetActive(false); - + // write changes to disk PartitionMapWriter writer(fd, 0, partition->size); // TODO: disk size or 2 * SECTOR_SIZE? @@ -1346,7 +1346,7 @@ disk_job_id job) { TRACE(("intel: pm_delete_child\n")); - + if (fd < 0) return B_ERROR; @@ -1358,7 +1358,7 @@ partition_data *child = get_partition(childID); if (!partition || !child) return B_BAD_VALUE; - + PartitionMap *map = (PartitionMap*)partition->content_cookie; PrimaryPartition *primary = (PrimaryPartition*)child->cookie; if (!map || !primary) @@ -1433,15 +1433,17 @@ bool ep_is_sub_system_for(partition_data *partition) { + if (partition == NULL) + return false; + TRACE(("intel: ep_is_sub_system_for(%ld: %lld, %lld, %ld, %s)\n", partition->id, partition->offset, partition->size, partition->block_size, partition->content_type)); - - + // Intel Extended Partition can live in child partition of Intel Partition // Map - return (partition && partition->content_type - && !strcmp(partition->content_type, kPartitionTypeIntel)); + return partition->content_type + && !strcmp(partition->content_type, kPartitionTypeIntel); } @@ -1453,7 +1455,7 @@ ep_validate_resize(partition_data *partition, off_t *size) { TRACE(("intel: ep_validate_resize\n")); - + if (!partition || !size) return false; @@ -1466,7 +1468,7 @@ off_t *_size) { TRACE(("intel: ep_validate_resize_child\n")); - + if (!partition || !child || !_size) return false; @@ -1485,7 +1487,7 @@ ep_validate_move(partition_data *partition, off_t *start) { TRACE(("intel: ep_validate_move\n")); - + if (!partition || !start) return false; // nothing to do here @@ -1498,7 +1500,7 @@ off_t *_start) { TRACE(("intel: ep_validate_move_child\n")); - + if (!partition || !child || !_start) return false; if (*_start == child->offset) @@ -1529,10 +1531,10 @@ ep_validate_set_type(partition_data *partition, const char *type) { TRACE(("intel: ep_validate_set_type\n")); - + if (!partition || !type) return false; - + // validity check of the type return is_type_valid_ep(type); } @@ -1543,7 +1545,7 @@ const char *parameters) { TRACE(("intel: ep_validate_initialize\n")); - + if (!partition || !(ep_get_supported_operations(partition) & B_DISK_SYSTEM_SUPPORTS_INITIALIZING)) { return false; @@ -1561,7 +1563,7 @@ // index - returns position of the new partition (the last one) { TRACE(("intel: ep_validate_create_child\n")); - + if (!partition || !(ep_get_supported_operations(partition) & B_DISK_SYSTEM_SUPPORTS_CREATING_CHILD) || !_start || !_size || !type || !index) { @@ -1601,7 +1603,7 @@ partitionable_space_data *buffer, int32 count, int32 *actualCount) { TRACE(("intel: ep_get_partitionable_spaces\n")); - + if (!partition || !partition->content_type || strcmp(partition->content_type, kPartitionTypeIntelExtended) || !actualCount) { @@ -1623,7 +1625,7 @@ char *_type) { TRACE(("intel: ep_get_next_supported_type\n")); - + if (!partition || !partition->content_type || strcmp(partition->content_type, kPartitionTypeIntelExtended) || !cookie || !_type) { @@ -1663,7 +1665,7 @@ uint32 operation) { TRACE(("intel: ep_shadow_changed\n")); - + if (!partition) return B_BAD_VALUE; @@ -1680,14 +1682,14 @@ ep_resize(int fd, partition_id partitionID, off_t size, disk_job_id job) { TRACE(("intel: ep_resize\n")); - + if (fd < 0) return B_ERROR; PartitionWriteLocker locker(partitionID); if (!locker.IsLocked()) return B_ERROR; - + // get out partition partition_data *partition = get_partition(partitionID); if (!partition) @@ -1701,7 +1703,7 @@ // update data stuctures update_disk_device_job_progress(job, 0.0); - + // TODO: partition->size is not supposed to be touched. partition->size = validatedSize; partition->content_size = validatedSize; @@ -1717,7 +1719,7 @@ ep_resize_child(int fd, partition_id partitionID, off_t size, disk_job_id job) { TRACE(("intel: ep_resize_child\n")); - + if (fd < 0) return B_ERROR; @@ -1774,7 +1776,7 @@ ep_move(int fd, partition_id partitionID, off_t offset, disk_job_id job) { TRACE(("intel: ep_move\n")); - + if (fd < 0) return B_ERROR; @@ -1802,7 +1804,7 @@ off_t offset, disk_job_id job) { TRACE(("intel: ep_move_child\n")); - + if (fd < 0) return B_ERROR; @@ -1881,7 +1883,7 @@ ep_set_type(int fd, partition_id partitionID, const char *type, disk_job_id job) { TRACE(("intel: ep_set_type\n")); - + if (fd < 0 || !type) return B_BAD_VALUE; @@ -1943,7 +1945,7 @@ const char *parameters, off_t partitionSize, disk_job_id job) { TRACE(("intel: ep_initialize\n")); - + if (fd < 0) return B_ERROR; @@ -1971,7 +1973,7 @@ // (no content_name and content_parameters) // (content_type is set by the system) partition->content_cookie = primary; - + // we delete code area in EBR - nothing should be there partition_table_sector pts; pts.clear_code_area(); @@ -1999,7 +2001,7 @@ partition_id *childID) { TRACE(("intel: ep_create_child\n")); - + if (fd < 0 || !childID) return B_BAD_VALUE; @@ -2021,7 +2023,7 @@ off_t validatedOffset = offset; off_t validatedSize = size; int32 index = 0; - + if (!ep_validate_create_child(partition, &validatedOffset, &validatedSize, type, parameters, &index)) { return B_BAD_VALUE; @@ -2105,7 +2107,7 @@ disk_job_id job) { TRACE(("intel: ep_delete_child\n")); - + if (fd < 0) return B_ERROR; @@ -2117,7 +2119,7 @@ partition_data *child = get_partition(childID); if (!partition || !child) return B_BAD_VALUE; - + PrimaryPartition *primary = (PrimaryPartition*)partition->cookie; LogicalPartition *logical = (LogicalPartition*)child->cookie; if (!primary || !logical) From axeld at mail.berlios.de Sat Sep 13 11:47:56 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sat, 13 Sep 2008 11:47:56 +0200 Subject: [Haiku-commits] r27471 - haiku/trunk/src/add-ons/kernel/file_systems/bfs Message-ID: <200809130947.m8D9luK1009633@sheep.berlios.de> Author: axeld Date: 2008-09-13 11:47:55 +0200 (Sat, 13 Sep 2008) New Revision: 27471 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27471&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Index.cpp haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.cpp haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.h haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp Log: * Some index updating functions did not take into account that not all nodes are put into all indices. For example, symlinks aren't part of the size index. This fixes bug #2704. * Also, Inode::NeedsTrimming() now ignores symlinks that have no data stream, it's const now, too. * Added helper methods Inode::In{Name|Size|LastModified}Index(), and use it where appropriate. * Clarified Inode::Create() description with regards to name vs. parent. Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Index.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/Index.cpp 2008-09-13 00:44:12 UTC (rev 27470) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/Index.cpp 2008-09-13 09:47:55 UTC (rev 27471) @@ -321,7 +321,7 @@ status_t Index::InsertSize(Transaction &transaction, Inode* inode) { - ASSERT(inode->IsFile()); + ASSERT(inode->InSizeIndex()); off_t size = inode->Size(); return Update(transaction, "size", B_INT64_TYPE, NULL, 0, (uint8*)&size, @@ -332,7 +332,7 @@ status_t Index::RemoveSize(Transaction &transaction, Inode* inode) { - ASSERT(inode->IsFile()); + ASSERT(inode->InSizeIndex()); // Inode::OldSize() is the size that's in the index off_t size = inode->OldSize(); @@ -344,7 +344,7 @@ status_t Index::UpdateSize(Transaction &transaction, Inode* inode) { - ASSERT(inode->IsFile()); + ASSERT(inode->InSizeIndex()); off_t oldSize = inode->OldSize(); off_t newSize = inode->Size(); @@ -362,7 +362,7 @@ status_t Index::InsertLastModified(Transaction &transaction, Inode* inode) { - ASSERT(inode->IsFile() || inode->IsSymLink()); + ASSERT(inode->InLastModifiedIndex()); off_t modified = inode->LastModified(); return Update(transaction, "last_modified", B_INT64_TYPE, NULL, 0, @@ -373,7 +373,7 @@ status_t Index::RemoveLastModified(Transaction &transaction, Inode* inode) { - ASSERT(inode->IsFile() || inode->IsSymLink()); + ASSERT(inode->InLastModifiedIndex()); // Inode::OldLastModified() is the value which is in the index off_t modified = inode->OldLastModified(); @@ -386,7 +386,7 @@ Index::UpdateLastModified(Transaction &transaction, Inode* inode, off_t modified) { - ASSERT(inode->IsFile() || inode->IsSymLink()); + ASSERT(inode->InLastModifiedIndex()); off_t oldModified = inode->OldLastModified(); if (modified == -1) Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.cpp 2008-09-13 00:44:12 UTC (rev 27470) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.cpp 2008-09-13 09:47:55 UTC (rev 27471) @@ -2063,18 +2063,19 @@ } -/*! Checks wether or not this inode's data stream needs to be trimmed +/*! Checks whether or not this inode's data stream needs to be trimmed because of an earlier preallocation. Returns true if there are any blocks to be trimmed. */ bool -Inode::NeedsTrimming() +Inode::NeedsTrimming() const { // We never trim preallocated index blocks to make them grow as smooth as // possible. There are only few indices anyway, so this doesn't hurt. // Also, if an inode is already in deleted state, we don't bother trimming // it. - if (IsIndex() || IsDeleted()) + if (IsIndex() || IsDeleted() + || (IsSymLink() && (Flags() & INODE_LONG_SYMLINK) == 0)) return false; off_t roundedSize = round_up(Size(), fVolume->BlockSize()); @@ -2301,36 +2302,36 @@ // are updated here (name, size, & last_modified) Index index(fVolume); - if (inode->IsRegularNode()) { + if (inode->InNameIndex()) { index.RemoveName(transaction, name, inode); // If removing from the index fails, it is not regarded as a // fatal error and will not be reported back! // Deleted inodes won't be visible in queries anyway. } - if (inode->IsFile() || inode->IsSymLink()) { - if (inode->IsFile()) - index.RemoveSize(transaction, inode); + if (inode->InSizeIndex()) + index.RemoveSize(transaction, inode); + if (inode->InLastModifiedIndex()) index.RemoveLastModified(transaction, inode); - } return inode->WriteBack(transaction); } -/*! Creates the inode with the specified parent directory, and automatically +/*! Creates the inode with the specified \a parent directory, and automatically adds the created inode to that parent directory. If an attribute directory - is created, it will also automatically be added to the parent inode as + is created, it will also automatically be added to the \a parent inode as such. However, the indices root node, and the regular root node won't be added to the super block. It will also create the initial B+tree for the inode if it's a directory of any kind. + \a name may be \c NULL, but only if no \a parent is given. If the "_id" or "_inode" variable is given and non-NULL to store the inode's ID, the inode stays locked - you have to call put_vnode() if you don't use it anymore. - If the node already exists, this method will fail if O_EXCL is set, or it's - a directory or a symlink. Otherwise, it will just be returned. If O_TRUNC - has been specified, the file will also be truncated. + If the node already exists, this method will fail if \c O_EXCL is set, or + it's a directory or a symlink. Otherwise, it will just be returned. + If \c O_TRUNC has been specified, the file will also be truncated. */ status_t Inode::Create(Transaction& transaction, Inode* parent, const char* name, @@ -2495,7 +2496,7 @@ // (live queries might want to access us after this) Index index(volume); - if (inode->IsRegularNode() && name != NULL) { + if (inode->InNameIndex() && name != NULL) { // the name index only contains regular files // (but not the root node where name == NULL) status = index.InsertName(transaction, name, inode); @@ -2514,14 +2515,13 @@ inode->UpdateOldLastModified(); - // The "size" & "last_modified" indices don't contain directories - if (inode->IsFile() || inode->IsSymLink()) { - // if adding to these indices fails, the inode creation will not be - // harmed; they are considered less important than the "name" index - if (inode->IsFile()) - index.InsertSize(transaction, inode); + // The "size" & "last_modified" indices don't contain directories. + // If adding to these indices fails, the inode creation will not be + // harmed; they are considered less important than the "name" index. + if (inode->InSizeIndex()) + index.InsertSize(transaction, inode); + if (inode->InLastModifiedIndex()) index.InsertLastModified(transaction, inode); - } if (inode->IsFile() || inode->IsAttribute()) { inode->SetFileCache(file_cache_create(volume->ID(), inode->ID(), @@ -2549,6 +2549,30 @@ } +/*! Checks whether or not this node should be part of the name index */ +bool +Inode::InNameIndex() const +{ + return IsRegularNode(); +} + + +/*! Checks whether or not this node should be part of the size index */ +bool +Inode::InSizeIndex() const +{ + return IsFile(); +} + + +/*! Checks whether or not this node should be part of the last modified index */ +bool +Inode::InLastModifiedIndex() const +{ + return IsFile() || IsSymLink(); +} + + // #pragma mark - AttributeIterator Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.h 2008-09-13 00:44:12 UTC (rev 27470) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.h 2008-09-13 09:47:55 UTC (rev 27471) @@ -140,12 +140,13 @@ status_t SetFileSize(Transaction& transaction, off_t size); status_t Append(Transaction& transaction, off_t bytes); status_t TrimPreallocation(Transaction& transaction); - bool NeedsTrimming(); + bool NeedsTrimming() const; status_t Free(Transaction& transaction); status_t Sync(); bfs_inode& Node() { return fNode; } + const bfs_inode& Node() const { return fNode; } // create/remove inodes status_t Remove(Transaction& transaction, const char* name, @@ -165,6 +166,10 @@ off_t OldSize() { return fOldSize; } off_t OldLastModified() { return fOldLastModified; } + bool InNameIndex() const; + bool InSizeIndex() const; + bool InLastModifiedIndex() const; + // file cache void* FileCache() const { return fCache; } void SetFileCache(void* cache) { fCache = cache; } Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp 2008-09-13 00:44:12 UTC (rev 27470) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp 2008-09-13 09:47:55 UTC (rev 27471) @@ -723,12 +723,14 @@ bfs_inode& node = inode->Node(); - if (mask & B_STAT_SIZE) { + if ((mask & B_STAT_SIZE) != 0) { // Since WSTAT_SIZE is the only thing that can fail directly, we // do it first, so that the inode state will still be consistent // with the on-disk version if (inode->IsDirectory()) return B_IS_A_DIRECTORY; + if (!inode->IsFile()) + return B_BAD_VALUE; if (inode->Size() != stat->st_size) { off_t oldSize = inode->Size(); @@ -751,19 +753,19 @@ } } - if (mask & B_STAT_MODE) { + if ((mask & B_STAT_MODE) != 0) { PRINT(("original mode = %ld, stat->st_mode = %d\n", node.Mode(), stat->st_mode)); node.mode = HOST_ENDIAN_TO_BFS_INT32((node.Mode() & ~S_IUMSK) | (stat->st_mode & S_IUMSK)); } - if (mask & B_STAT_UID) + if ((mask & B_STAT_UID) != 0) node.uid = HOST_ENDIAN_TO_BFS_INT32(stat->st_uid); - if (mask & B_STAT_GID) + if ((mask & B_STAT_GID) != 0) node.gid = HOST_ENDIAN_TO_BFS_INT32(stat->st_gid); - if (mask & B_STAT_MODIFICATION_TIME) { - if (inode->IsDirectory()) { + if ((mask & B_STAT_MODIFICATION_TIME) != 0) { + if (!inode->InLastModifiedIndex()) { // directory modification times are not part of the index node.last_modified_time = HOST_ENDIAN_TO_BFS_INT64( (bigtime_t)stat->st_mtime << INODE_TIME_SHIFT); @@ -774,7 +776,7 @@ (bigtime_t)stat->st_mtime << INODE_TIME_SHIFT); } } - if (mask & B_STAT_CREATION_TIME) { + if ((mask & B_STAT_CREATION_TIME) != 0) { node.create_time = HOST_ENDIAN_TO_BFS_INT64( (bigtime_t)stat->st_crtime << INODE_TIME_SHIFT); } @@ -1296,7 +1298,10 @@ && !inode->IsDeleted() && (needsTrimming || inode->OldLastModified() != inode->LastModified() - || inode->OldSize() != inode->Size())) { + || (inode->InSizeIndex() + // TODO: this can prevent the size update notification + // for nodes not in the index! + && inode->OldSize() != inode->Size()))) { locker.Unlock(); transaction.Start(volume, inode->BlockNumber()); } @@ -1323,11 +1328,15 @@ } } if (inode->OldSize() != inode->Size()) { - index.UpdateSize(transaction, inode); + if (inode->InSizeIndex()) + index.UpdateSize(transaction, inode); changedSize = true; } if (inode->OldLastModified() != inode->LastModified()) { - index.UpdateLastModified(transaction, inode, inode->LastModified()); + if (inode->InLastModifiedIndex()) { + index.UpdateLastModified(transaction, inode, + inode->LastModified()); + } changedTime = true; // updating the index doesn't write back the inode @@ -1385,7 +1394,7 @@ if (!inode->IsSymLink()) RETURN_ERROR(B_BAD_VALUE); - if (inode->Flags() & INODE_LONG_SYMLINK) { + if ((inode->Flags() & INODE_LONG_SYMLINK) != 0) { if (inode->Size() < *_bufferSize) *_bufferSize = inode->Size(); From bonefish at mail.berlios.de Sat Sep 13 12:04:51 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sat, 13 Sep 2008 12:04:51 +0200 Subject: [Haiku-commits] r27472 - haiku/trunk/src/tools/vmdkimage Message-ID: <200809131004.m8DA4p0s012629@sheep.berlios.de> Author: bonefish Date: 2008-09-13 12:04:51 +0200 (Sat, 13 Sep 2008) New Revision: 27472 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27472&view=rev Modified: haiku/trunk/src/tools/vmdkimage/vmdkimage.cpp Log: * The image was create one byte too short. Fixes #2722. * Automatic whitespace cleanup. Modified: haiku/trunk/src/tools/vmdkimage/vmdkimage.cpp =================================================================== --- haiku/trunk/src/tools/vmdkimage/vmdkimage.cpp 2008-09-13 09:47:55 UTC (rev 27471) +++ haiku/trunk/src/tools/vmdkimage/vmdkimage.cpp 2008-09-13 10:04:51 UTC (rev 27472) @@ -48,24 +48,24 @@ exit(EXIT_FAILURE); } - while (1) { + while (1) { int c; - static struct option long_options[] = - { - {"headersize", required_argument, 0, 'h'}, - {"imagesize", required_argument, 0, 'i'}, - {"file", required_argument, 0, 'f'}, - {"clear-image", no_argument, 0, 'c'}, - {"header-only", no_argument, 0, 'H'}, - {0, 0, 0, 0} + static struct option long_options[] = + { + {"headersize", required_argument, 0, 'h'}, + {"imagesize", required_argument, 0, 'i'}, + {"file", required_argument, 0, 'f'}, + {"clear-image", no_argument, 0, 'c'}, + {"header-only", no_argument, 0, 'H'}, + {0, 0, 0, 0} }; opterr = 0; /* don't print errors */ - c = getopt_long(argc, argv, "h:i:cHf:", long_options, NULL); - if (c == -1) - break; + c = getopt_long(argc, argv, "h:i:cHf:", long_options, NULL); + if (c == -1) + break; - switch (c) { + switch (c) { case 'h': headersize = strtoull(optarg, NULL, 10); if (strchr(optarg, 'G') || strchr(optarg, 'g')) @@ -74,7 +74,7 @@ headersize *= 1024 * 1024; else if (strchr(optarg, 'K') || strchr(optarg, 'k')) headersize *= 1024; - break; + break; case 'i': imagesize = strtoull(optarg, NULL, 10); @@ -84,24 +84,24 @@ imagesize *= 1024 * 1024; else if (strchr(optarg, 'K') || strchr(optarg, 'k')) imagesize *= 1024; - break; + break; case 'f': file = optarg; - break; + break; case 'c': clearImage = true; - break; + break; case 'H': headerOnly = true; - break; + break; - default: + default: print_usage(); - } - } + } + } if (file == NULL && optind == argc - 1) file = argv[optind]; @@ -181,7 +181,7 @@ header.doubleEndLineChar1 = '\r'; header.doubleEndLineChar2 = '\n'; - strcat(desc, + strcat(desc, "# Disk Descriptor File\n" "version=1\n" "CID=fffffffe\n" @@ -191,7 +191,7 @@ "# Extent Description\n" "RW %llu FLAT \"%s\" %llu\n", actualImageSize / 512, name, headersize / 512); - sprintf(desc + strlen(desc), + sprintf(desc + strlen(desc), "# Disk Data Base\n" "ddb.toolsVersion = \"0\"\n" "ddb.virtualHWVersion = \"3\"\n" @@ -200,7 +200,7 @@ "ddb.geometry.heads = \"%llu\"\n" "ddb.geometry.cylinders = \"%llu\"\n", sectors, heads, cylinders); - + int fd = open(file, O_RDWR | O_CREAT, 0666); if (fd < 0) { fprintf(stderr, "Error: couldn't open file %s (%s)\n", file, @@ -212,9 +212,8 @@ if (sizeof(desc) != write(fd, desc, sizeof(desc))) goto write_err; - - headersize--; - if (headersize != (uint64)lseek(fd, headersize, SEEK_SET)) + + if (headersize - 1 != (uint64)lseek(fd, headersize - 1, SEEK_SET)) goto write_err; if (1 != write(fd, "", 1)) @@ -222,7 +221,7 @@ if (!headerOnly) { if (clearImage && ftruncate(fd, headersize) != 0 - || ftruncate(fd, actualImageSize + headersize) != 0) { + || ftruncate(fd, actualImageSize + headersize) != 0) { fprintf(stderr, "Error: resizing file %s failed (%s)\n", file, strerror(errno)); exit(EXIT_FAILURE); From mmlr at mail.berlios.de Sat Sep 13 14:28:48 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sat, 13 Sep 2008 14:28:48 +0200 Subject: [Haiku-commits] r27473 - haiku/trunk/src/tests/kits/game/chart Message-ID: <200809131228.m8DCSmTT017773@sheep.berlios.de> Author: mmlr Date: 2008-09-13 14:28:46 +0200 (Sat, 13 Sep 2008) New Revision: 27473 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27473&view=rev Modified: haiku/trunk/src/tests/kits/game/chart/ChartWindow.cpp Log: CID 325: Be defensive and check the results of the dynamic_casts. Modified: haiku/trunk/src/tests/kits/game/chart/ChartWindow.cpp =================================================================== --- haiku/trunk/src/tests/kits/game/chart/ChartWindow.cpp 2008-09-13 10:04:51 UTC (rev 27472) +++ haiku/trunk/src/tests/kits/game/chart/ChartWindow.cpp 2008-09-13 12:28:46 UTC (rev 27473) @@ -952,6 +952,9 @@ break; case FULL_SCREEN_MSG : check_box = dynamic_cast(handler); + if (check_box == NULL) + break; + if (check_box->Value()) fNextSettings.fullscreen_mode = FULLSCREEN_MODE; else @@ -968,6 +971,9 @@ break; case SECOND_THREAD_MSG : check_box = dynamic_cast(handler); + if (check_box == NULL) + break; + fNextSettings.second_thread = (check_box->Value()?true:false); break; case COLORS_RED_MSG : @@ -979,6 +985,9 @@ case COLORS_WHITE_MSG : index = message->what - COLORS_RED_MSG; check_box = dynamic_cast(handler); + if (check_box == NULL) + break; + fNextSettings.colors[index] = (check_box->Value()?true:false); break; case SPECIAL_NONE_MSG : @@ -996,10 +1005,16 @@ break; case STAR_DENSITY_MSG : slider = dynamic_cast(handler); + if (slider == NULL) + break; + fNextSettings.star_density = slider->Value(); break; case REFRESH_RATE_MSG : slider = dynamic_cast(handler); + if (slider == NULL) + break; + fNextSettings.refresh_rate = exp(slider->Value()*0.001*(log(REFRESH_RATE_MAX/REFRESH_RATE_MIN)))* REFRESH_RATE_MIN; break; From axeld at pinc-software.de Sat Sep 13 14:29:23 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Sat, 13 Sep 2008 14:29:23 +0200 CEST Subject: [Haiku-commits] r27206 - haiku/trunk/src/bin/listdev In-Reply-To: <200808260608.m7Q68Qat032527@sheep.berlios.de> Message-ID: <15732831624-BeMail@zon> jackburton at mail.berlios.de wrote: > Modified: > haiku/trunk/src/bin/listdev/listdev.c > Log: > partially reverted the latest change [...] > + uint8 pci_class_base_id = 0; > + uint8 pci_class_sub_id = 0; > + uint8 pci_class_api_id = 0; [...] > } else if (!strcmp(attr.name, B_DEVICE_TYPE) > && attr.type == B_UINT16_TYPE) > - pci_class_base_id = attr.value.ui16; > + pci_class_base_id = attr.value.ui8; > else if (!strcmp(attr.name, B_DEVICE_SUB_TYPE) > && attr.type == B_UINT16_TYPE) > - pci_class_sub_id = attr.value.ui16; > + pci_class_sub_id = attr.value.ui8; > else if (!strcmp(attr.name, B_DEVICE_INTERFACE) > && attr.type == B_UINT16_TYPE) > - pci_class_api_id = attr.value.ui16; > + pci_class_api_id = attr.value.ui8; This change is not correct, and will only work on little endian platforms. Since you effectively don't ask for PCI base/sub/api values, but for device manager IDs that happen to be in a compatible namespace, I would prefer to rename the variables, and just use the uint16 type instead. Bye, Axel. From mmlr at mail.berlios.de Sat Sep 13 14:36:19 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sat, 13 Sep 2008 14:36:19 +0200 Subject: [Haiku-commits] r27474 - haiku/trunk/src/tests/kits/game/chart Message-ID: <200809131236.m8DCaJjx020753@sheep.berlios.de> Author: mmlr Date: 2008-09-13 14:36:17 +0200 (Sat, 13 Sep 2008) New Revision: 27474 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27474&view=rev Modified: haiku/trunk/src/tests/kits/game/chart/ChartView.cpp Log: CID 323 and CID 324: Also check the results of these dynamic_casts, sorry for not combining with the previous commit. Modified: haiku/trunk/src/tests/kits/game/chart/ChartView.cpp =================================================================== --- haiku/trunk/src/tests/kits/game/chart/ChartView.cpp 2008-09-13 12:28:46 UTC (rev 27473) +++ haiku/trunk/src/tests/kits/game/chart/ChartView.cpp 2008-09-13 12:36:17 UTC (rev 27474) @@ -27,6 +27,9 @@ ChartView::Draw(BRect rect) { ChartWindow *window = dynamic_cast(Window()); + if (window == NULL) + return; + if ((window->fOffscreen != 0) && (window->fCurrentSettings.display == DISPLAY_BITMAP)) DrawBitmap(window->fOffscreen, rect, rect); } @@ -58,6 +61,9 @@ InstantView::Draw(BRect rect) { ChartWindow *window = dynamic_cast(Window()); + if (window == NULL) + return; + for (int32 i = 0; i < window->fInstantLoadLevel; i++) { if (i < step) SetHighColor(255, 90, 90); From mmlr at mail.berlios.de Sat Sep 13 15:43:52 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sat, 13 Sep 2008 15:43:52 +0200 Subject: [Haiku-commits] r27475 - haiku/trunk/src/system/kernel/disk_device_manager Message-ID: <200809131343.m8DDhqvl026929@sheep.berlios.de> Author: mmlr Date: 2008-09-13 15:43:50 +0200 (Sat, 13 Sep 2008) New Revision: 27475 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27475&view=rev Modified: haiku/trunk/src/system/kernel/disk_device_manager/KFileDiskDevice.cpp Log: CID 316: If path can be null, path->InitCheck() shouldn't be used. Split it up into two seperate checks instead and return B_BAD_VALUE on a passed NULL path. Modified: haiku/trunk/src/system/kernel/disk_device_manager/KFileDiskDevice.cpp =================================================================== --- haiku/trunk/src/system/kernel/disk_device_manager/KFileDiskDevice.cpp 2008-09-13 12:36:17 UTC (rev 27474) +++ haiku/trunk/src/system/kernel/disk_device_manager/KFileDiskDevice.cpp 2008-09-13 13:43:50 UTC (rev 27475) @@ -187,8 +187,12 @@ status_t KFileDiskDevice::_GetDirectoryPath(partition_id id, KPath *path) { - if (!path || path->InitCheck() != B_OK) + if (path == NULL) + return B_BAD_VALUE; + + if (path->InitCheck() != B_OK) return path->InitCheck(); + status_t error = path->SetPath(kFileDevicesDir); if (error == B_OK) { char idBuffer[12]; From mmlr at mail.berlios.de Sat Sep 13 15:57:41 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sat, 13 Sep 2008 15:57:41 +0200 Subject: [Haiku-commits] r27476 - haiku/trunk/src/system/kernel/disk_device_manager Message-ID: <200809131357.m8DDvfQq028141@sheep.berlios.de> Author: mmlr Date: 2008-09-13 15:57:40 +0200 (Sat, 13 Sep 2008) New Revision: 27476 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27476&view=rev Modified: haiku/trunk/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp Log: * CID 312 and CID 313: The device can be NULL in ReadLockPartition(). * CID 314 and CID 315: Same as above just for WriteLockPartition. Modified: haiku/trunk/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp =================================================================== --- haiku/trunk/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp 2008-09-13 13:43:50 UTC (rev 27475) +++ haiku/trunk/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp 2008-09-13 13:57:40 UTC (rev 27476) @@ -534,7 +534,7 @@ device->Register(); } // lock the device - if (device->ReadLock()) { + if (device && device->ReadLock()) { // final check, if the partition still belongs to the device if (partition->Device() == device) return partition; @@ -563,7 +563,7 @@ device->Register(); } // lock the device - if (device->WriteLock()) { + if (device && device->WriteLock()) { // final check, if the partition still belongs to the device if (partition->Device() == device) return partition; From stippi at mail.berlios.de Sat Sep 13 16:04:18 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Sat, 13 Sep 2008 16:04:18 +0200 Subject: [Haiku-commits] r27477 - haiku/trunk/src/kits/tracker Message-ID: <200809131404.m8DE4IUL028757@sheep.berlios.de> Author: stippi Date: 2008-09-13 16:04:13 +0200 (Sat, 13 Sep 2008) New Revision: 27477 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27477&view=rev Modified: haiku/trunk/src/kits/tracker/QueryPoseView.cpp Log: Free query in error code path. Fixes CID 927. Modified: haiku/trunk/src/kits/tracker/QueryPoseView.cpp =================================================================== --- haiku/trunk/src/kits/tracker/QueryPoseView.cpp 2008-09-13 13:57:40 UTC (rev 27476) +++ haiku/trunk/src/kits/tracker/QueryPoseView.cpp 2008-09-13 14:04:13 UTC (rev 27477) @@ -522,6 +522,7 @@ status_t result = query->Fetch(); if (result != B_OK) { PRINT(("fetch error %s\n", strerror(result))); + delete query; return result; } list->AddItem(query); From mmlr at mail.berlios.de Sat Sep 13 16:27:33 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sat, 13 Sep 2008 16:27:33 +0200 Subject: [Haiku-commits] r27478 - haiku/trunk/src/system/kernel/arch/x86 Message-ID: <200809131427.m8DERXHs000535@sheep.berlios.de> Author: mmlr Date: 2008-09-13 16:27:31 +0200 (Sat, 13 Sep 2008) New Revision: 27478 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27478&view=rev Modified: haiku/trunk/src/system/kernel/arch/x86/arch_vm_translation_map.cpp Log: CID 56: Fix the wrong NULL check. Modified: haiku/trunk/src/system/kernel/arch/x86/arch_vm_translation_map.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/arch_vm_translation_map.cpp 2008-09-13 14:04:13 UTC (rev 27477) +++ haiku/trunk/src/system/kernel/arch/x86/arch_vm_translation_map.cpp 2008-09-13 14:27:31 UTC (rev 27478) @@ -783,7 +783,7 @@ recursive_lock_init(&map->lock, "translation map"); map->arch_data = (vm_translation_map_arch_info *)malloc(sizeof(vm_translation_map_arch_info)); - if (map == NULL) { + if (map->arch_data == NULL) { recursive_lock_destroy(&map->lock); return B_NO_MEMORY; } From mmlr at mail.berlios.de Sat Sep 13 16:41:43 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sat, 13 Sep 2008 16:41:43 +0200 Subject: [Haiku-commits] r27479 - haiku/trunk/src/system/boot/loader/net Message-ID: <200809131441.m8DEfhDC003224@sheep.berlios.de> Author: mmlr Date: 2008-09-13 16:41:42 +0200 (Sat, 13 Sep 2008) New Revision: 27479 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27479&view=rev Modified: haiku/trunk/src/system/boot/loader/net/NetStack.cpp Log: CID 1251: If the NetStack::Init() fails, return the corresponding error instead of setting the global net stack to a deleted value. Modified: haiku/trunk/src/system/boot/loader/net/NetStack.cpp =================================================================== --- haiku/trunk/src/system/boot/loader/net/NetStack.cpp 2008-09-13 14:27:31 UTC (rev 27478) +++ haiku/trunk/src/system/boot/loader/net/NetStack.cpp 2008-09-13 14:41:42 UTC (rev 27479) @@ -88,8 +88,10 @@ return B_NO_MEMORY; status_t error = netStack->Init(); - if (error != B_OK) + if (error != B_OK) { delete netStack; + return error; + } sNetStack = netStack; return B_OK; From mmlr at mail.berlios.de Sat Sep 13 17:22:32 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sat, 13 Sep 2008 17:22:32 +0200 Subject: [Haiku-commits] r27480 - haiku/trunk/src/servers/midi Message-ID: <200809131522.m8DFMWCJ006582@sheep.berlios.de> Author: mmlr Date: 2008-09-13 17:22:30 +0200 (Sat, 13 Sep 2008) New Revision: 27480 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27480&view=rev Modified: haiku/trunk/src/servers/midi/PortDrivers.cpp Log: CID 930: Fix memory leak in error case. Note that this file has a completely different coding style, violating ours for consistency until the whole file can be cleaned up. Modified: haiku/trunk/src/servers/midi/PortDrivers.cpp =================================================================== --- haiku/trunk/src/servers/midi/PortDrivers.cpp 2008-09-13 14:41:42 UTC (rev 27479) +++ haiku/trunk/src/servers/midi/PortDrivers.cpp 2008-09-13 15:22:30 UTC (rev 27480) @@ -100,6 +100,10 @@ if (read(fd, &next, 1) != 1) { perror("Error reading data from driver"); + if (haveSysEx) + { + free(sysexBuf); + } return B_ERROR; } From mmlr at mail.berlios.de Sat Sep 13 17:28:32 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sat, 13 Sep 2008 17:28:32 +0200 Subject: [Haiku-commits] r27481 - haiku/trunk/src/servers/app/drawing/Painter/drawing_modes Message-ID: <200809131528.m8DFSWoW006905@sheep.berlios.de> Author: mmlr Date: 2008-09-13 17:28:31 +0200 (Sat, 13 Sep 2008) New Revision: 27481 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27481&view=rev Modified: haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeSelect.h Log: CID 157: Fix usage of *covers instead of cover which in this case indeed is NULL and should have lead to a crash. Modified: haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeSelect.h =================================================================== --- haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeSelect.h 2008-09-13 15:22:30 UTC (rev 27480) +++ haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeSelect.h 2008-09-13 15:28:31 UTC (rev 27481) @@ -4,6 +4,7 @@ * * DrawingMode implementing B_OP_SELECT on B_RGBA32. * + */ #ifndef DRAWING_MODE_SELECT_H @@ -194,7 +195,7 @@ } else if (cover) { do { if (colors->a > 0 && compare(p, high, low, &color)) { - BLEND_SELECT(p, color.red, color.green, color.blue, *covers); + BLEND_SELECT(p, color.red, color.green, color.blue, cover); } p += 4; ++colors; From mmlr at mail.berlios.de Sat Sep 13 17:30:20 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sat, 13 Sep 2008 17:30:20 +0200 Subject: [Haiku-commits] r27482 - haiku/trunk/src/servers/app/drawing/Painter/drawing_modes Message-ID: <200809131530.m8DFUK50007150@sheep.berlios.de> Author: mmlr Date: 2008-09-13 17:30:19 +0200 (Sat, 13 Sep 2008) New Revision: 27482 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27482&view=rev Modified: haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeSelect.h Log: Remove accidentally introduced whitespace in last commit. Modified: haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeSelect.h =================================================================== --- haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeSelect.h 2008-09-13 15:28:31 UTC (rev 27481) +++ haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeSelect.h 2008-09-13 15:30:19 UTC (rev 27482) @@ -4,7 +4,6 @@ * * DrawingMode implementing B_OP_SELECT on B_RGBA32. * - */ #ifndef DRAWING_MODE_SELECT_H From mmlr at mail.berlios.de Sat Sep 13 17:51:17 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sat, 13 Sep 2008 17:51:17 +0200 Subject: [Haiku-commits] r27483 - haiku/trunk/src/servers/app/drawing Message-ID: <200809131551.m8DFpHAe009295@sheep.berlios.de> Author: mmlr Date: 2008-09-13 17:51:16 +0200 (Sat, 13 Sep 2008) New Revision: 27483 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27483&view=rev Modified: haiku/trunk/src/servers/app/drawing/AccelerantHWInterface.cpp Log: * CID 525: Check the return of _UpdateModeList() as otherwise fModeList can still be NULL although it is used further down. * CID 526: Check the front buffer to be available before using it in SetMode(). Modified: haiku/trunk/src/servers/app/drawing/AccelerantHWInterface.cpp =================================================================== --- haiku/trunk/src/servers/app/drawing/AccelerantHWInterface.cpp 2008-09-13 15:30:19 UTC (rev 27482) +++ haiku/trunk/src/servers/app/drawing/AccelerantHWInterface.cpp 2008-09-13 15:51:16 UTC (rev 27483) @@ -498,6 +498,9 @@ if (!_IsValidMode(mode)) return B_BAD_VALUE; + if (fFrontBuffer == NULL) + return B_NO_INIT; + // just try to set the mode - we let the graphics driver // approve or deny the request, as it should know best @@ -822,8 +825,11 @@ if (version != EDID_VERSION_1) return B_NOT_SUPPORTED; - if (fModeList == NULL) - _UpdateModeList(); + if (fModeList == NULL) { + status = _UpdateModeList(); + if (status != B_OK) + return status; + } status = B_NOT_SUPPORTED; display_mode bestMode; From mmlr at mail.berlios.de Sat Sep 13 17:55:17 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sat, 13 Sep 2008 17:55:17 +0200 Subject: [Haiku-commits] r27484 - haiku/trunk/src/servers/app Message-ID: <200809131555.m8DFtHJb009642@sheep.berlios.de> Author: mmlr Date: 2008-09-13 17:55:15 +0200 (Sat, 13 Sep 2008) New Revision: 27484 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27484&view=rev Modified: haiku/trunk/src/servers/app/View.cpp Log: * CID 1090: Check the view pointer for NULL before dereferencing it. Modified: haiku/trunk/src/servers/app/View.cpp =================================================================== --- haiku/trunk/src/servers/app/View.cpp 2008-09-13 15:51:16 UTC (rev 27483) +++ haiku/trunk/src/servers/app/View.cpp 2008-09-13 15:55:15 UTC (rev 27484) @@ -249,7 +249,7 @@ bool View::RemoveChild(View* view) { - if (view->fParent != this) { + if (view == NULL || view->fParent != this) { printf("View::RemoveChild(%p - %s) - View is not child of " "this (%p) view!\n", view, view ? view->Name() : NULL, this); return false; From mmlr at mail.berlios.de Sat Sep 13 18:26:03 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sat, 13 Sep 2008 18:26:03 +0200 Subject: [Haiku-commits] r27485 - haiku/trunk/src/kits/storage Message-ID: <200809131626.m8DGQ3Uv012785@sheep.berlios.de> Author: mmlr Date: 2008-09-13 18:26:02 +0200 (Sat, 13 Sep 2008) New Revision: 27485 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27485&view=rev Modified: haiku/trunk/src/kits/storage/OffsetFile.cpp Log: Initialize fFile to NULL. Modified: haiku/trunk/src/kits/storage/OffsetFile.cpp =================================================================== --- haiku/trunk/src/kits/storage/OffsetFile.cpp 2008-09-13 15:55:15 UTC (rev 27484) +++ haiku/trunk/src/kits/storage/OffsetFile.cpp 2008-09-13 16:26:02 UTC (rev 27485) @@ -16,7 +16,7 @@ // constructor OffsetFile::OffsetFile() - : fFile(), + : fFile(NULL), fOffset(0), fCurrentPosition(0) { @@ -169,7 +169,3 @@ }; // namespace Storage }; // namespace BPrivate - - - - From mmlr at mail.berlios.de Sat Sep 13 18:30:55 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sat, 13 Sep 2008 18:30:55 +0200 Subject: [Haiku-commits] r27486 - haiku/trunk/src/servers/app Message-ID: <200809131630.m8DGUtq7013799@sheep.berlios.de> Author: mmlr Date: 2008-09-13 18:30:48 +0200 (Sat, 13 Sep 2008) New Revision: 27486 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27486&view=rev Modified: haiku/trunk/src/servers/app/ServerPicture.cpp haiku/trunk/src/servers/app/ServerPicture.h Log: * CID 1012: Fix leaking the OffsetFile in case it fails to initialize. * Use std::nothrow (the rest of the file already used it). * We also have to keep the source file around and properly dispose it, as OffsetFile doesn't take ownership of it. Modified: haiku/trunk/src/servers/app/ServerPicture.cpp =================================================================== --- haiku/trunk/src/servers/app/ServerPicture.cpp 2008-09-13 16:26:02 UTC (rev 27485) +++ haiku/trunk/src/servers/app/ServerPicture.cpp 2008-09-13 16:30:48 UTC (rev 27486) @@ -754,6 +754,7 @@ ServerPicture::ServerPicture() : PictureDataWriter(), + fFile(NULL), fData(NULL), fPictures(NULL), fUsurped(NULL) @@ -768,6 +769,7 @@ ServerPicture::ServerPicture(const ServerPicture &picture) : PictureDataWriter(), + fFile(NULL), fData(NULL), fPictures(NULL), fUsurped(NULL) @@ -793,19 +795,25 @@ ServerPicture::ServerPicture(const char *fileName, const int32 &offset) : PictureDataWriter(), + fFile(NULL), fData(NULL), fPictures(NULL), fUsurped(NULL) { - BPrivate::Storage::OffsetFile *file = - new BPrivate::Storage::OffsetFile(new BFile(fileName, B_READ_WRITE), (off_t)offset); + fFile = new (std::nothrow) BFile(fileName, B_READ_WRITE); + if (fFile == NULL) + return; - if (file == NULL || file->InitCheck() != B_OK) + BPrivate::Storage::OffsetFile *offsetFile = + new (std::nothrow) BPrivate::Storage::OffsetFile(fFile, (off_t)offset); + if (offsetFile == NULL || offsetFile->InitCheck() != B_OK) { + delete offsetFile; return; - - fData = file; + } + + fData = offsetFile; fToken = gTokenSpace.NewToken(kPictureToken, this); - + PictureDataWriter::SetTo(fData); } @@ -813,6 +821,7 @@ ServerPicture::~ServerPicture() { delete fData; + delete fFile; gTokenSpace.RemoveToken(fToken); // We only delete the subpictures list, not the subpictures themselves, @@ -1044,5 +1053,3 @@ fData->Seek(oldPosition, SEEK_SET); return status; } - - Modified: haiku/trunk/src/servers/app/ServerPicture.h =================================================================== --- haiku/trunk/src/servers/app/ServerPicture.h 2008-09-13 16:26:02 UTC (rev 27485) +++ haiku/trunk/src/servers/app/ServerPicture.h 2008-09-13 16:30:48 UTC (rev 27486) @@ -16,6 +16,8 @@ class ServerApp; class View; +class BFile; + namespace BPrivate { class LinkReceiver; class PortLink; @@ -53,6 +55,7 @@ ~ServerPicture(); int32 fToken; + BFile *fFile; BPositionIO *fData; // DrawState *fState; BList *fPictures; From mmlr at mail.berlios.de Sat Sep 13 18:39:25 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sat, 13 Sep 2008 18:39:25 +0200 Subject: [Haiku-commits] r27487 - haiku/trunk/src/servers/app Message-ID: <200809131639.m8DGdPjU026773@sheep.berlios.de> Author: mmlr Date: 2008-09-13 18:39:11 +0200 (Sat, 13 Sep 2008) New Revision: 27487 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27487&view=rev Modified: haiku/trunk/src/servers/app/ServerCursor.cpp Log: CID 18 and CID 19: Fix leaking the cursor data. Modified: haiku/trunk/src/servers/app/ServerCursor.cpp =================================================================== --- haiku/trunk/src/servers/app/ServerCursor.cpp 2008-09-13 16:30:48 UTC (rev 27486) +++ haiku/trunk/src/servers/app/ServerCursor.cpp 2008-09-13 16:39:11 UTC (rev 27487) @@ -173,6 +173,7 @@ //! Frees the heap space allocated for the cursor's image data ServerCursor::~ServerCursor() { + delete fCursorData; } From mmlr at mail.berlios.de Sat Sep 13 19:31:15 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sat, 13 Sep 2008 19:31:15 +0200 Subject: [Haiku-commits] r27488 - haiku/trunk/src/kits/app Message-ID: <200809131731.m8DHVF0Y007983@sheep.berlios.de> Author: mmlr Date: 2008-09-13 19:31:13 +0200 (Sat, 13 Sep 2008) New Revision: 27488 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27488&view=rev Modified: haiku/trunk/src/kits/app/MessageAdapter.cpp Log: CID 225: If the field size was <= 0 the field buffer wasn't allocated but still used in the switch statement. Change that to continue early when a filed size of <= 0 is encountered. Modified: haiku/trunk/src/kits/app/MessageAdapter.cpp =================================================================== --- haiku/trunk/src/kits/app/MessageAdapter.cpp 2008-09-13 16:39:11 UTC (rev 27487) +++ haiku/trunk/src/kits/app/MessageAdapter.cpp 2008-09-13 17:31:13 UTC (rev 27488) @@ -679,15 +679,18 @@ ssize_t fieldSize = sectionHeader.size - sizeof(dano_section_header); uint8 *fieldBuffer = NULL; - if (fieldSize > 0) { + if (fieldSize <= 0) { // there may be no data. we shouldn't fail because of that - fieldBuffer = (uint8 *)malloc(fieldSize); - if (fieldBuffer == NULL) - throw (status_t)B_NO_MEMORY; - - reader(fieldBuffer, fieldSize); + offset += sectionHeader.size; + continue; } + fieldBuffer = (uint8 *)malloc(fieldSize); + if (fieldBuffer == NULL) + throw (status_t)B_NO_MEMORY; + + reader(fieldBuffer, fieldSize); + switch (sectionHeader.code) { case SECTION_OFFSET_TABLE: case SECTION_TARGET_INFORMATION: From mmlr at mail.berlios.de Sat Sep 13 20:00:49 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sat, 13 Sep 2008 20:00:49 +0200 Subject: [Haiku-commits] r27489 - haiku/trunk/src/add-ons/accelerants/intel_extreme Message-ID: <200809131800.m8DI0nxf009773@sheep.berlios.de> Author: mmlr Date: 2008-09-13 20:00:47 +0200 (Sat, 13 Sep 2008) New Revision: 27489 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27489&view=rev Modified: haiku/trunk/src/add-ons/accelerants/intel_extreme/mode.cpp Log: CID 1039: Dereference mode only after checking it for NULL. Modified: haiku/trunk/src/add-ons/accelerants/intel_extreme/mode.cpp =================================================================== --- haiku/trunk/src/add-ons/accelerants/intel_extreme/mode.cpp 2008-09-13 17:31:13 UTC (rev 27488) +++ haiku/trunk/src/add-ons/accelerants/intel_extreme/mode.cpp 2008-09-13 18:00:47 UTC (rev 27489) @@ -529,11 +529,11 @@ { TRACE(("intel_set_display_mode()\n")); - display_mode target = *mode; - if (mode == NULL || intel_propose_display_mode(&target, mode, mode)) return B_BAD_VALUE; + display_mode target = *mode; + uint32 colorMode, bytesPerRow, bitsPerPixel; get_color_space_format(target, colorMode, bytesPerRow, bitsPerPixel); From mmlr at mail.berlios.de Sat Sep 13 20:22:46 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sat, 13 Sep 2008 20:22:46 +0200 Subject: [Haiku-commits] r27490 - haiku/trunk/src/apps/bootman Message-ID: <200809131822.m8DIMkTx011094@sheep.berlios.de> Author: mmlr Date: 2008-09-13 20:22:44 +0200 (Sat, 13 Sep 2008) New Revision: 27490 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27490&view=rev Modified: haiku/trunk/src/apps/bootman/LegacyBootDrive.cpp Log: * CID 145 and CID 146: Use delete[] to delete the arrays. * Also use new(std::nothrow) for the allocation. Modified: haiku/trunk/src/apps/bootman/LegacyBootDrive.cpp =================================================================== --- haiku/trunk/src/apps/bootman/LegacyBootDrive.cpp 2008-09-13 18:00:47 UTC (rev 27489) +++ haiku/trunk/src/apps/bootman/LegacyBootDrive.cpp 2008-09-13 18:22:44 UTC (rev 27490) @@ -382,7 +382,7 @@ return B_IO_ERROR; ssize_t size = kBlockSize * kNumberOfBootLoaderBlocks; - uint8* buffer = new uint8[size]; + uint8* buffer = new(std::nothrow) uint8[size]; if (buffer == NULL) { close(fd); return B_NO_MEMORY; @@ -391,20 +391,20 @@ status_t status = _ReadBlocks(fd, buffer, size); if (status != B_OK) { close(fd); - delete buffer; + delete[] buffer; return B_IO_ERROR; } MasterBootRecord* mbr = (MasterBootRecord*)buffer; if (!_IsValid(mbr)) { close(fd); - delete buffer; + delete[] buffer; return B_BAD_VALUE; } if (file->Write(buffer, size) != size) status = B_IO_ERROR; - delete buffer; + delete[] buffer; close(fd); return status; } @@ -434,7 +434,7 @@ lseek(fd, 0, SEEK_SET); size_t size = kBlockSize * kNumberOfBootLoaderBlocks; - uint8* buffer = new uint8[size]; + uint8* buffer = new(std::nothrow) uint8[size]; if (buffer == NULL) { close(fd); return B_NO_MEMORY; @@ -442,21 +442,21 @@ if (file->Read(buffer, size) != (ssize_t)size) { close(fd); - delete buffer; + delete[] buffer; return B_IO_ERROR; } MasterBootRecord* newMBR = (MasterBootRecord*)buffer; if (!_IsValid(newMBR)) { close(fd); - delete buffer; + delete[] buffer; return B_BAD_VALUE; } _CopyPartitionTable(newMBR, &oldMBR); status_t status = _WriteBlocks(fd, buffer, size); - delete buffer; + delete[] buffer; close(fd); return status; } From mmlr at mail.berlios.de Sat Sep 13 20:25:28 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sat, 13 Sep 2008 20:25:28 +0200 Subject: [Haiku-commits] r27491 - haiku/trunk/src/apps/bootman Message-ID: <200809131825.m8DIPSUU011444@sheep.berlios.de> Author: mmlr Date: 2008-09-13 20:25:26 +0200 (Sat, 13 Sep 2008) New Revision: 27491 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27491&view=rev Modified: haiku/trunk/src/apps/bootman/LegacyBootDrive.cpp Log: Fix previous commit, forgot to inlude for use of std::nothrow. Modified: haiku/trunk/src/apps/bootman/LegacyBootDrive.cpp =================================================================== --- haiku/trunk/src/apps/bootman/LegacyBootDrive.cpp 2008-09-13 18:22:44 UTC (rev 27490) +++ haiku/trunk/src/apps/bootman/LegacyBootDrive.cpp 2008-09-13 18:25:26 UTC (rev 27491) @@ -20,6 +20,7 @@ #include #include +#include #include #include #include From mmlr at mail.berlios.de Sat Sep 13 20:42:05 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sat, 13 Sep 2008 20:42:05 +0200 Subject: [Haiku-commits] r27492 - haiku/trunk/src/add-ons/accelerants/intel_extreme Message-ID: <200809131842.m8DIg5F5012732@sheep.berlios.de> Author: mmlr Date: 2008-09-13 20:42:03 +0200 (Sat, 13 Sep 2008) New Revision: 27492 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27492&view=rev Modified: haiku/trunk/src/add-ons/accelerants/intel_extreme/mode.cpp Log: Fix the build of the intel_extreme.accelerant, I obviously compiled the wrong target when I checked it. Move the target display_mode declaration back above the check but remove the dereferencing assignment. If proposing the display mode succeeds it also initializes target. Thanks luroh for noticing. Modified: haiku/trunk/src/add-ons/accelerants/intel_extreme/mode.cpp =================================================================== --- haiku/trunk/src/add-ons/accelerants/intel_extreme/mode.cpp 2008-09-13 18:25:26 UTC (rev 27491) +++ haiku/trunk/src/add-ons/accelerants/intel_extreme/mode.cpp 2008-09-13 18:42:03 UTC (rev 27492) @@ -529,11 +529,10 @@ { TRACE(("intel_set_display_mode()\n")); + display_mode target; if (mode == NULL || intel_propose_display_mode(&target, mode, mode)) return B_BAD_VALUE; - display_mode target = *mode; - uint32 colorMode, bytesPerRow, bitsPerPixel; get_color_space_format(target, colorMode, bytesPerRow, bitsPerPixel); From stippi at mail.berlios.de Sat Sep 13 20:42:35 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Sat, 13 Sep 2008 20:42:35 +0200 Subject: [Haiku-commits] r27493 - haiku/trunk/src/kits/interface Message-ID: <200809131842.m8DIgZTH012773@sheep.berlios.de> Author: stippi Date: 2008-09-13 20:42:32 +0200 (Sat, 13 Sep 2008) New Revision: 27493 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27493&view=rev Modified: haiku/trunk/src/kits/interface/Slider.cpp Log: * Don't do anything in SetOrientation() if orientation is the same as the current one. * When calculating the thumb and bar frames, handle the case when the object doesn't have a label, but does have an update text. Modified: haiku/trunk/src/kits/interface/Slider.cpp =================================================================== --- haiku/trunk/src/kits/interface/Slider.cpp 2008-09-13 18:42:03 UTC (rev 27492) +++ haiku/trunk/src/kits/interface/Slider.cpp 2008-09-13 18:42:32 UTC (rev 27493) @@ -1177,7 +1177,7 @@ if (Orientation() == B_HORIZONTAL) { frame.left = thumbInset; - frame.top = 6.0 + (Label() ? textHeight + 4.0 : 0.0); + frame.top = 6.0 + (Label() || fUpdateText ? textHeight + 4.0 : 0.0); frame.right -= thumbInset; frame.bottom = frame.top + fBarThickness; } else { @@ -1241,7 +1241,7 @@ if (Orientation() == B_HORIZONTAL) { frame.left = floorf(Position() * (_MaxPosition() - _MinPosition()) + _MinPosition()) - 8; - frame.top = 2 + (Label() ? textHeight + 4 : 0); + frame.top = 2 + (Label() || fUpdateText ? textHeight + 4 : 0); frame.right = frame.left + 17; frame.bottom = frame.top + fBarThickness + 7; } else { @@ -1487,6 +1487,9 @@ void BSlider::SetOrientation(orientation posture) { + if (fOrientation == posture) + return; + fOrientation = posture; InvalidateLayout(); Invalidate(); From stippi at mail.berlios.de Sat Sep 13 21:20:24 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Sat, 13 Sep 2008 21:20:24 +0200 Subject: [Haiku-commits] r27494 - in haiku/trunk: headers/os/interface src/kits/interface Message-ID: <200809131920.m8DJKO7j015990@sheep.berlios.de> Author: stippi Date: 2008-09-13 21:20:18 +0200 (Sat, 13 Sep 2008) New Revision: 27494 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27494&view=rev Modified: haiku/trunk/headers/os/interface/ScrollBar.h haiku/trunk/src/kits/interface/ScrollBar.cpp Log: * Update header indentation. * Added BScrollBar::SetOrientation(). * Improved _DrawArrowButton() to have a good visual result even when the scroll bar does not have the standard width or height. Modified: haiku/trunk/headers/os/interface/ScrollBar.h =================================================================== --- haiku/trunk/headers/os/interface/ScrollBar.h 2008-09-13 18:42:32 UTC (rev 27493) +++ haiku/trunk/headers/os/interface/ScrollBar.h 2008-09-13 19:20:18 UTC (rev 27494) @@ -28,106 +28,112 @@ class BScrollBar : public BView { public: - BScrollBar(BRect frame, const char* name, - BView* target, float min, float max, - orientation direction); - BScrollBar(const char* name, BView* target, - float min, float max, orientation direction); - BScrollBar(BMessage* data); - virtual ~BScrollBar(); - static BArchivable *Instantiate(BMessage* data); - virtual status_t Archive(BMessage *data, bool deep = true) const; + BScrollBar(BRect frame, const char* name, + BView* target, float min, float max, + orientation direction); + BScrollBar(const char* name, BView* target, + float min, float max, orientation direction); + BScrollBar(BMessage* data); + virtual ~BScrollBar(); + static BArchivable* Instantiate(BMessage* data); + virtual status_t Archive(BMessage *data, bool deep = true) const; - virtual void AttachedToWindow(); - void SetValue(float value); - float Value() const; - void SetProportion(float); - float Proportion() const; - virtual void ValueChanged(float newValue); + virtual void AttachedToWindow(); + void SetValue(float value); + float Value() const; + void SetProportion(float); + float Proportion() const; + virtual void ValueChanged(float newValue); - void SetRange(float min, float max); - void GetRange(float *min, float *max) const; - void SetSteps(float smallStep, float largeStep); - void GetSteps(float *smallStep, float *largeStep) const; - void SetTarget(BView *target); - void SetTarget(const char *targetName); - BView *Target() const; - orientation Orientation() const; + void SetRange(float min, float max); + void GetRange(float* _min, float* _max) const; + void SetSteps(float smallStep, float largeStep); + void GetSteps(float* _smallStep, + float* _largeStep) const; + void SetTarget(BView *target); + void SetTarget(const char* targetName); + BView* Target() const; + void SetOrientation(enum orientation orientation); + orientation Orientation() const; - virtual void MessageReceived(BMessage *msg); - virtual void MouseDown(BPoint pt); - virtual void MouseUp(BPoint pt); - virtual void MouseMoved(BPoint pt, uint32 code, const BMessage *msg); - virtual void DetachedFromWindow(); - virtual void Draw(BRect updateRect); - virtual void FrameMoved(BPoint new_position); - virtual void FrameResized(float new_width, float new_height); + virtual void MessageReceived(BMessage* message); + virtual void MouseDown(BPoint pt); + virtual void MouseUp(BPoint pt); + virtual void MouseMoved(BPoint pt, uint32 code, + const BMessage* dragMessage); + virtual void DetachedFromWindow(); + virtual void Draw(BRect updateRect); + virtual void FrameMoved(BPoint new_position); + virtual void FrameResized(float newWidth, float newHeight); - virtual BHandler *ResolveSpecifier(BMessage *msg, int32 index, - BMessage *specifier, int32 form, - const char *property); + virtual BHandler* ResolveSpecifier(BMessage* message, + int32 index, BMessage* specifier, + int32 form, const char* property); - virtual void ResizeToPreferred(); - virtual void GetPreferredSize(float *width, float *height); - virtual void MakeFocus(bool state = true); - virtual void AllAttached(); - virtual void AllDetached(); - virtual status_t GetSupportedSuites(BMessage *data); + virtual void ResizeToPreferred(); + virtual void GetPreferredSize(float* _width, float* _height); + virtual void MakeFocus(bool state = true); + virtual void AllAttached(); + virtual void AllDetached(); + virtual status_t GetSupportedSuites(BMessage* data); - virtual BSize MinSize(); - virtual BSize MaxSize(); - virtual BSize PreferredSize(); + virtual BSize MinSize(); + virtual BSize MaxSize(); + virtual BSize PreferredSize(); - virtual status_t Perform(perform_code d, void *arg); + virtual status_t Perform(perform_code d, void* arg); #if DISABLES_ON_WINDOW_DEACTIVATION - virtual void WindowActivated(bool active); + virtual void WindowActivated(bool active); #endif - private: - class Private; - friend class Private; +private: + class Private; + friend class Private; - friend status_t control_scrollbar(scroll_bar_info *info, BScrollBar *bar); - // for use within the preflet + friend status_t control_scrollbar(scroll_bar_info* info, + BScrollBar *bar); + // for use within the preflet - virtual void _ReservedScrollBar1(); - virtual void _ReservedScrollBar2(); - virtual void _ReservedScrollBar3(); - virtual void _ReservedScrollBar4(); + virtual void _ReservedScrollBar1(); + virtual void _ReservedScrollBar2(); + virtual void _ReservedScrollBar3(); + virtual void _ReservedScrollBar4(); - BScrollBar &operator=(const BScrollBar &); + // disabled + BScrollBar& operator=(const BScrollBar& other); - bool _DoubleArrows() const; - void _UpdateThumbFrame(); - float _ValueFor(BPoint where) const; - int32 _ButtonFor(BPoint where) const; - BRect _ButtonRectFor(int32 button) const; - void _UpdateTargetValue(BPoint where); - void _UpdateArrowButtons(); - void _DrawDisabledBackground(BRect area, - const rgb_color& light, const rgb_color& dark, - const rgb_color& fill); - void _DrawArrowButton(int32 direction, - bool doubleArrows, BRect frame, - const BRect& updateRect, - bool enabled, bool down); + bool _DoubleArrows() const; + void _UpdateThumbFrame(); + float _ValueFor(BPoint where) const; + int32 _ButtonFor(BPoint where) const; + BRect _ButtonRectFor(int32 button) const; + void _UpdateTargetValue(BPoint where); + void _UpdateArrowButtons(); + void _DrawDisabledBackground(BRect area, + const rgb_color& light, + const rgb_color& dark, + const rgb_color& fill); + void _DrawArrowButton(int32 direction, + bool doubleArrows, BRect frame, + const BRect& updateRect, + bool enabled, bool down); - BSize _MinSize() const; + BSize _MinSize() const; - float fMin; - float fMax; - float fSmallStep; - float fLargeStep; - float fValue; - float fProportion; - BView* fTarget; - orientation fOrientation; - char* fTargetName; + float fMin; + float fMax; + float fSmallStep; + float fLargeStep; + float fValue; + float fProportion; + BView* fTarget; + orientation fOrientation; + char* fTargetName; - Private* fPrivateData; + Private* fPrivateData; - uint32 _reserved[3]; + uint32 _reserved[3]; }; #endif // _SCROLL_BAR_H Modified: haiku/trunk/src/kits/interface/ScrollBar.cpp =================================================================== --- haiku/trunk/src/kits/interface/ScrollBar.cpp 2008-09-13 18:42:32 UTC (rev 27493) +++ haiku/trunk/src/kits/interface/ScrollBar.cpp 2008-09-13 19:20:18 UTC (rev 27494) @@ -563,6 +563,18 @@ } +void +BScrollBar::SetOrientation(enum orientation orientation) +{ + if (fOrientation == orientation) + return; + + fOrientation = orientation; + InvalidateLayout(); + Invalidate(); +} + + orientation BScrollBar::Orientation() const { @@ -1610,27 +1622,29 @@ } BPoint tri1, tri2, tri3; - r.InsetBy(4, 4); + float hInset = r.Width() / 3; + float vInset = r.Height() / 3; + r.InsetBy(hInset, vInset); switch (direction) { case ARROW_LEFT: tri1.Set(r.right, r.top); - tri2.Set(r.left + 1, (r.top + r.bottom + 1) /2 ); + tri2.Set(r.right - r.Width() / 1.33, (r.top + r.bottom + 1) /2 ); tri3.Set(r.right, r.bottom + 1); break; case ARROW_RIGHT: tri1.Set(r.left, r.bottom + 1); - tri2.Set(r.right - 1, (r.top + r.bottom + 1) / 2); + tri2.Set(r.left + r.Width() / 1.33, (r.top + r.bottom + 1) / 2); tri3.Set(r.left, r.top); break; case ARROW_UP: tri1.Set(r.left, r.bottom); - tri2.Set((r.left + r.right + 1) / 2, r.top + 1); + tri2.Set((r.left + r.right + 1) / 2, r.bottom - r.Height() / 1.33); tri3.Set(r.right + 1, r.bottom); break; default: tri1.Set(r.left, r.top); - tri2.Set((r.left + r.right + 1) / 2, r.bottom - 1); + tri2.Set((r.left + r.right + 1) / 2, r.top + r.Height() / 1.33); tri3.Set(r.right + 1, r.top); break; } @@ -1642,7 +1656,7 @@ tri3 = tri3 + offset; } - r.InsetBy(-3, -3); + r.InsetBy(-(hInset - 1), -(vInset - 1)); SetHighColor(normal); FillRect(r); @@ -1652,7 +1666,7 @@ arrowShape.LineTo(tri3); SetHighColor(arrow); - SetPenSize(2.0); + SetPenSize(ceilf(hInset / 2.0)); StrokeShape(&arrowShape); SetPenSize(1.0); From stippi at mail.berlios.de Sat Sep 13 21:22:00 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Sat, 13 Sep 2008 21:22:00 +0200 Subject: [Haiku-commits] r27495 - in haiku/trunk/src/tests/kits/interface/layout/widget_layout_test: . tests Message-ID: <200809131922.m8DJM0fT016066@sheep.berlios.de> Author: stippi Date: 2008-09-13 21:21:55 +0200 (Sat, 13 Sep 2008) New Revision: 27495 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27495&view=rev Added: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/ScrollBarTest.cpp haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/ScrollBarTest.h Modified: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/Jamfile haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/WidgetLayoutTest.cpp haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/TODO Log: Added BScrollBar test. Modified: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/Jamfile =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/Jamfile 2008-09-13 19:20:18 UTC (rev 27494) +++ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/Jamfile 2008-09-13 19:21:55 UTC (rev 27495) @@ -27,6 +27,7 @@ MenuBarTest.cpp MenuFieldTest.cpp MenuTest.cpp + ScrollBarTest.cpp SliderTest.cpp : be Modified: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/WidgetLayoutTest.cpp =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/WidgetLayoutTest.cpp 2008-09-13 19:20:18 UTC (rev 27494) +++ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/WidgetLayoutTest.cpp 2008-09-13 19:21:55 UTC (rev 27495) @@ -17,6 +17,7 @@ #include "MenuBarTest.h" #include "MenuFieldTest.h" #include "MenuTest.h" +#include "ScrollBarTest.h" #include "SliderTest.h" #include "StringView.h" #include "Test.h" @@ -46,6 +47,7 @@ { "BMenu", MenuTest::CreateTest }, { "BMenuBar", MenuBarTest::CreateTest }, { "BMenuField", MenuFieldTest::CreateTest }, + { "BScrollBar", ScrollBarTest::CreateTest }, { "BSlider", SliderTest::CreateTest }, { NULL, NULL } }; Added: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/ScrollBarTest.cpp =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/ScrollBarTest.cpp 2008-09-13 19:20:18 UTC (rev 27494) +++ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/ScrollBarTest.cpp 2008-09-13 19:21:55 UTC (rev 27495) @@ -0,0 +1,129 @@ +/* + * Copyright 2008, Stephan A?mus . + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#include "ScrollBarTest.h" + +#include +#include + +#include "RadioButton.h" +#include "TestView.h" + + +// messages +enum { + MSG_ORIENTATION_CHANGED = 'orch' +}; + + +// OrientationRadioButton +class ScrollBarTest::OrientationRadioButton : public LabeledRadioButton { +public: + OrientationRadioButton(const char* label, enum orientation orientation) + : LabeledRadioButton(label), + fOrientation(orientation) + { + } + + enum orientation fOrientation; +}; + + +ScrollBarTest::ScrollBarTest() + : Test("ScrollBar", NULL), + fScrollBar(new BScrollBar("scroll bar", NULL, 0, 100, B_HORIZONTAL)), + fOrientationRadioGroup(NULL) +{ + SetView(fScrollBar); +} + + +ScrollBarTest::~ScrollBarTest() +{ + delete fOrientationRadioGroup; +} + + +Test* +ScrollBarTest::CreateTest() +{ + return new ScrollBarTest; +} + + +void +ScrollBarTest::ActivateTest(View* controls) +{ + // the radio button group for selecting the orientation + + GroupView* vGroup = new GroupView(B_VERTICAL); + vGroup->SetFrame(controls->Bounds()); + vGroup->SetSpacing(0, 4); + controls->AddChild(vGroup); + + fOrientationRadioGroup = new RadioButtonGroup( + new BMessage(MSG_ORIENTATION_CHANGED), this); + + // horizontal + LabeledRadioButton* button = new OrientationRadioButton("Horizontal", + B_HORIZONTAL); + vGroup->AddChild(button); + fOrientationRadioGroup->AddButton(button->GetRadioButton()); + + // vertical + button = new OrientationRadioButton("Vertical", B_VERTICAL); + vGroup->AddChild(button); + fOrientationRadioGroup->AddButton(button->GetRadioButton()); + + // default to horizontal + fOrientationRadioGroup->SelectButton(0L); + + // glue + vGroup->AddChild(new Glue()); +} + + +void +ScrollBarTest::DectivateTest() +{ +} + + +void +ScrollBarTest::MessageReceived(BMessage* message) +{ + switch (message->what) { + case MSG_ORIENTATION_CHANGED: + _UpdateOrientation(); + break; + default: + Test::MessageReceived(message); + break; + } +} + + +void +ScrollBarTest::_UpdateOrientation() +{ + if (fOrientationRadioGroup == NULL) + return; + + // We need to get the parent of the actually selected button, since + // that is the labeled radio button we've derived our + // BorderStyleRadioButton from. + AbstractButton* selectedButton + = fOrientationRadioGroup->SelectedButton(); + View* parent = (selectedButton ? selectedButton->Parent() : NULL); + OrientationRadioButton* button = dynamic_cast( + parent); + if (button) + fScrollBar->SetOrientation(button->fOrientation); +} + + + + + Added: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/ScrollBarTest.h =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/ScrollBarTest.h 2008-09-13 19:20:18 UTC (rev 27494) +++ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/ScrollBarTest.h 2008-09-13 19:21:55 UTC (rev 27495) @@ -0,0 +1,39 @@ +/* + * Copyright 2008, Stephan A?mus . + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef WIDGET_LAYOUT_TEST_SCROLL_BAR_TEST_H +#define WIDGET_LAYOUT_TEST_SCROLL_BAR_TEST_H + + +#include "Test.h" + + +class BScrollBar; +class RadioButtonGroup; + + +class ScrollBarTest : public Test { +public: + ScrollBarTest(); + virtual ~ScrollBarTest(); + + static Test* CreateTest(); + + virtual void ActivateTest(View* controls); + virtual void DectivateTest(); + + virtual void MessageReceived(BMessage* message); + +private: + void _UpdateOrientation(); + +private: + class OrientationRadioButton; + + BScrollBar* fScrollBar; + RadioButtonGroup* fOrientationRadioGroup; +}; + + +#endif // WIDGET_LAYOUT_TEST_SCROLL_BAR_TEST_H Modified: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/TODO =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/TODO 2008-09-13 19:20:18 UTC (rev 27494) +++ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/TODO 2008-09-13 19:21:55 UTC (rev 27495) @@ -1,7 +1,6 @@ ChannelSlider OptionPopup (covered by MenuField ?) RadioButton -ScrollBar ScrollView StringView TabView From mmlr at mail.berlios.de Sat Sep 13 21:26:06 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sat, 13 Sep 2008 21:26:06 +0200 Subject: [Haiku-commits] r27496 - haiku/trunk/src/add-ons/kernel/partitioning_systems/session Message-ID: <200809131926.m8DJQ6Xl016248@sheep.berlios.de> Author: mmlr Date: 2008-09-13 21:26:04 +0200 (Sat, 13 Sep 2008) New Revision: 27496 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27496&view=rev Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/session/session.cpp Log: * CID 874 and CID 875: Fix leaking the session object GetSession() allocates. * CID 876: Fix leaking the disc object in case it fails to initialize. Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/session/session.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/partitioning_systems/session/session.cpp 2008-09-13 19:21:55 UTC (rev 27495) +++ haiku/trunk/src/add-ons/kernel/partitioning_systems/session/session.cpp 2008-09-13 19:26:04 UTC (rev 27496) @@ -52,8 +52,10 @@ Disc *disc = new Disc(fd); if (disc && disc->InitCheck() == B_OK) { *cookie = static_cast(disc); - result = 0.7; - } + result = 0.7; + } + + delete disc; } PRINT(("returning %ld\n", int32(result * 10000))); return result; @@ -89,6 +91,7 @@ child->block_size = session->BlockSize(); child->flags |= session->Flags(); child->type = strdup(session->Type()); + delete session; if (!child->type) { error = B_NO_MEMORY; break; @@ -130,4 +133,3 @@ &sSessionModule, NULL }; - From superstippi at gmx.de Sat Sep 13 21:34:49 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Sat, 13 Sep 2008 21:34:49 +0200 Subject: [Haiku-commits] r27496 - haiku/trunk/src/add-ons/kernel/partitioning_systems/session In-Reply-To: <200809131926.m8DJQ6Xl016248@sheep.berlios.de> References: <200809131926.m8DJQ6Xl016248@sheep.berlios.de> Message-ID: <20080913193449.123350@gmx.net> -------- Original-Nachricht -------- > Datum: Sat, 13 Sep 2008 21:26:06 +0200 > Von: mmlr at mail.berlios.de > An: haiku-commits at lists.berlios.de > Betreff: [Haiku-commits] r27496 - haiku/trunk/src/add-ons/kernel/partitioning_systems/session > Author: mmlr > Date: 2008-09-13 21:26:04 +0200 (Sat, 13 Sep 2008) > New Revision: 27496 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27496&view=rev > > Modified: > haiku/trunk/src/add-ons/kernel/partitioning_systems/session/session.cpp > Log: > * CID 874 and CID 875: Fix leaking the session object GetSession() > allocates. > * CID 876: Fix leaking the disc object in case it fails to initialize. > > Modified: > haiku/trunk/src/add-ons/kernel/partitioning_systems/session/session.cpp > =================================================================== > --- > haiku/trunk/src/add-ons/kernel/partitioning_systems/session/session.cpp 2008-09-13 19:21:55 UTC (rev 27495) > +++ > haiku/trunk/src/add-ons/kernel/partitioning_systems/session/session.cpp 2008-09-13 19:26:04 UTC (rev 27496) > @@ -52,8 +52,10 @@ > Disc *disc = new Disc(fd); > if (disc && disc->InitCheck() == B_OK) { > *cookie = static_cast(disc); > - result = 0.7; > - } > + result = 0.7; > + } > + > + delete disc; That should be in an "else" statement, no? Best regards, -Stephan From mmlr at mail.berlios.de Sat Sep 13 21:38:54 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sat, 13 Sep 2008 21:38:54 +0200 Subject: [Haiku-commits] r27497 - haiku/trunk/src/add-ons/kernel/partitioning_systems/session Message-ID: <200809131938.m8DJcs3s018375@sheep.berlios.de> Author: mmlr Date: 2008-09-13 21:38:52 +0200 (Sat, 13 Sep 2008) New Revision: 27497 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27497&view=rev Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/session/session.cpp Log: Again fix the previous commit. Obviously we only want to delete the disc object if it actually failed to initialize. Thanks Stephan for spotting that. Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/session/session.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/partitioning_systems/session/session.cpp 2008-09-13 19:26:04 UTC (rev 27496) +++ haiku/trunk/src/add-ons/kernel/partitioning_systems/session/session.cpp 2008-09-13 19:38:52 UTC (rev 27497) @@ -53,9 +53,8 @@ if (disc && disc->InitCheck() == B_OK) { *cookie = static_cast(disc); result = 0.7; - } - - delete disc; + } else + delete disc; } PRINT(("returning %ld\n", int32(result * 10000))); return result; From mmlr at mlotz.ch Sat Sep 13 21:39:36 2008 From: mmlr at mlotz.ch (Michael Lotz) Date: Sat, 13 Sep 2008 21:39:36 +0200 Subject: [Haiku-commits] =?windows-1252?q?r27496_-_haiku/trunk/src/add-ons?= =?windows-1252?q?/kernel/partitioning=5Fsystems/session?= In-Reply-To: <20080913193449.123350@gmx.net> Message-ID: <8056144376-BeMail@primary> > > + result = 0.7; > > + } > > + > > + delete disc; > > That should be in an "else" statement, no? Obviously it should, yes. Seems I shouldn't do any code today, I even manage to mess up simple things like that. Thanks for proof-reading. In that case I would've even noticed later on, as I just intended to test that change on my laptop. Regards Michael From stippi at mail.berlios.de Sat Sep 13 21:50:06 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Sat, 13 Sep 2008 21:50:06 +0200 Subject: [Haiku-commits] r27498 - in haiku/trunk/src/tests/kits/interface/layout/widget_layout_test: . tests Message-ID: <200809131950.m8DJo6Ep019443@sheep.berlios.de> Author: stippi Date: 2008-09-13 21:50:01 +0200 (Sat, 13 Sep 2008) New Revision: 27498 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27498&view=rev Added: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/TextControlTest.cpp haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/TextControlTest.h Modified: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/Jamfile haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/WidgetLayoutTest.cpp haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/TODO Log: Added BTextControl test. BTextControl seems to need some love. Modified: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/Jamfile =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/Jamfile 2008-09-13 19:38:52 UTC (rev 27497) +++ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/Jamfile 2008-09-13 19:50:01 UTC (rev 27498) @@ -29,6 +29,7 @@ MenuTest.cpp ScrollBarTest.cpp SliderTest.cpp + TextControlTest.cpp : be ; Modified: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/WidgetLayoutTest.cpp =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/WidgetLayoutTest.cpp 2008-09-13 19:38:52 UTC (rev 27497) +++ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/WidgetLayoutTest.cpp 2008-09-13 19:50:01 UTC (rev 27498) @@ -21,6 +21,7 @@ #include "SliderTest.h" #include "StringView.h" #include "Test.h" +#include "TextControlTest.h" #include "TwoDimensionalSliderView.h" #include "View.h" #include "ViewContainer.h" @@ -49,6 +50,7 @@ { "BMenuField", MenuFieldTest::CreateTest }, { "BScrollBar", ScrollBarTest::CreateTest }, { "BSlider", SliderTest::CreateTest }, + { "BTextControl", TextControlTest::CreateTest }, { NULL, NULL } }; Modified: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/TODO =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/TODO 2008-09-13 19:38:52 UTC (rev 27497) +++ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/TODO 2008-09-13 19:50:01 UTC (rev 27498) @@ -4,5 +4,4 @@ ScrollView StringView TabView -TextControl TextView Added: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/TextControlTest.cpp =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/TextControlTest.cpp 2008-09-13 19:38:52 UTC (rev 27497) +++ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/TextControlTest.cpp 2008-09-13 19:50:01 UTC (rev 27498) @@ -0,0 +1,144 @@ +/* + * Copyright 2008, Stephan A?mus . + * Copyright 2007, Ingo Weinhold . + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#include "TextControlTest.h" + +#include + +#include + +#include "CheckBox.h" +#include "GroupView.h" + + +enum { + MSG_CHANGE_LABEL_TEXT = 'chlt', + MSG_CHANGE_LABEL_FONT = 'chlf' +}; + + +// constructor +TextControlTest::TextControlTest() + : ControlTest("TextControl"), + fLongTextCheckBox(NULL), + fBigFontCheckBox(NULL), + fDefaultFont(NULL), + fBigFont(NULL) +{ + fTextControl = new BTextControl("Label", "Some Text", NULL); + + SetView(fTextControl); +} + + +// destructor +TextControlTest::~TextControlTest() +{ + delete fDefaultFont; + delete fBigFont; +} + + +// CreateTest +Test* +TextControlTest::CreateTest() +{ + return new TextControlTest; +} + + +// ActivateTest +void +TextControlTest::ActivateTest(View* controls) +{ + GroupView* group = new GroupView(B_VERTICAL); + group->SetFrame(controls->Bounds()); + group->SetSpacing(0, 8); + controls->AddChild(group); + + // BMenuField sets its background color to that of its parent in + // AttachedToWindow(). Override. + rgb_color background = ui_color(B_PANEL_BACKGROUND_COLOR); + fTextControl->SetViewColor(background); + fTextControl->SetLowColor(background); + + // long text + fLongTextCheckBox = new LabeledCheckBox("Long label text", + new BMessage(MSG_CHANGE_LABEL_TEXT), this); + group->AddChild(fLongTextCheckBox); + + // big font + fBigFontCheckBox = new LabeledCheckBox("Big label font", + new BMessage(MSG_CHANGE_LABEL_FONT), this); + group->AddChild(fBigFontCheckBox); + + _UpdateLabelText(); + _UpdateLabelFont(); + + group->AddChild(new Glue()); +} + + +// DectivateTest +void +TextControlTest::DectivateTest() +{ +} + + +// MessageReceived +void +TextControlTest::MessageReceived(BMessage* message) +{ + switch (message->what) { + case MSG_CHANGE_LABEL_TEXT: + _UpdateLabelText(); + break; + case MSG_CHANGE_LABEL_FONT: + _UpdateLabelFont(); + break; + default: + Test::MessageReceived(message); + break; + } +} + + +// _UpdateLabelText +void +TextControlTest::_UpdateLabelText() +{ + if (!fLongTextCheckBox || !fTextControl) + return; + + fTextControl->SetLabel(fLongTextCheckBox->IsSelected() + ? "Pretty long menu field label" + : "Short label"); +} + + +// _UpdateLabelFont +void +TextControlTest::_UpdateLabelFont() +{ + if (!fBigFontCheckBox || !fTextControl || !fTextControl->Window()) + return; + + // get default font lazily + if (!fDefaultFont) { + fDefaultFont = new BFont; + fTextControl->GetFont(fDefaultFont); + + fBigFont = new BFont(fDefaultFont); + fBigFont->SetSize(20); + } + + // set font + fTextControl->SetFont(fBigFontCheckBox->IsSelected() + ? fBigFont : fDefaultFont); + fTextControl->InvalidateLayout(); + fTextControl->Invalidate(); +} Added: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/TextControlTest.h =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/TextControlTest.h 2008-09-13 19:38:52 UTC (rev 27497) +++ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/TextControlTest.h 2008-09-13 19:50:01 UTC (rev 27498) @@ -0,0 +1,43 @@ +/* + * Copyright 2008, Stephan A?mus . + * Copyright 2007, Ingo Weinhold . + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef WIDGET_LAYOUT_TEST_TEXT_CONTROL_TEST_H +#define WIDGET_LAYOUT_TEST_TEXT_CONTROL_TEST_H + + +#include "ControlTest.h" + + +class BFont; +class BTextControl; +class LabeledCheckBox; + + +class TextControlTest : public ControlTest { +public: + TextControlTest(); + virtual ~TextControlTest(); + + static Test* CreateTest(); + + virtual void ActivateTest(View* controls); + virtual void DectivateTest(); + + virtual void MessageReceived(BMessage* message); + +private: + void _UpdateLabelText(); + void _UpdateLabelFont(); + +private: + BTextControl* fTextControl; + LabeledCheckBox* fLongTextCheckBox; + LabeledCheckBox* fBigFontCheckBox; + BFont* fDefaultFont; + BFont* fBigFont; +}; + + +#endif // WIDGET_LAYOUT_TEST_TEXT_CONTROL_TEST_H From michael.w.pfeiffer at gmail.com Sat Sep 13 22:02:13 2008 From: michael.w.pfeiffer at gmail.com (Michael Pfeiffer) Date: Sat, 13 Sep 2008 22:02:13 +0200 Subject: [Haiku-commits] r27490 - haiku/trunk/src/apps/bootman In-Reply-To: <200809131822.m8DIMkTx011094@sheep.berlios.de> References: <200809131822.m8DIMkTx011094@sheep.berlios.de> Message-ID: Am 13.09.2008 um 20:22 schrieb mmlr at mail.berlios.de: > Author: mmlr > Date: 2008-09-13 20:22:44 +0200 (Sat, 13 Sep 2008) > New Revision: 27490 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27490&view=rev > > Modified: > haiku/trunk/src/apps/bootman/LegacyBootDrive.cpp > Log: > * CID 145 and CID 146: Use delete[] to delete the arrays. > * Also use new(std::nothrow) for the allocation. > > > Modified: haiku/trunk/src/apps/bootman/LegacyBootDrive.cpp > =================================================================== > --- haiku/trunk/src/apps/bootman/LegacyBootDrive.cpp 2008-09-13 > 18:00:47 UTC (rev 27489) > +++ haiku/trunk/src/apps/bootman/LegacyBootDrive.cpp 2008-09-13 > 18:22:44 UTC (rev 27490) > @@ -382,7 +382,7 @@ > return B_IO_ERROR; > > ssize_t size = kBlockSize * kNumberOfBootLoaderBlocks; > - uint8* buffer = new uint8[size]; > + uint8* buffer = new(std::nothrow) uint8[size]; > if (buffer == NULL) { > close(fd); > return B_NO_MEMORY; > @@ -391,20 +391,20 @@ > status_t status = _ReadBlocks(fd, buffer, size); > if (status != B_OK) { > close(fd); > - delete buffer; > + delete[] buffer; Just curious, is deleting the array this way really required? I mean it's an array of a simple type and I don't even know if there exist a destructor for that. - Michael From axeld at pinc-software.de Sat Sep 13 23:18:50 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Sat, 13 Sep 2008 23:18:50 +0200 CEST Subject: [Haiku-commits] r27490 - haiku/trunk/src/apps/bootman In-Reply-To: Message-ID: <47499743975-BeMail@zon> Michael Pfeiffer wrote: > > - delete buffer; > > + delete[] buffer; > Just curious, is deleting the array this way really required? I mean > it's an array of a simple type and I don't even know if there exist a > destructor for that. For simple types it shouldn't be any actual difference, even though it's certainly clearer to do it. Not using the delete[] will usually only cause the destructors not to be called (as the allocator usually maintains the size itself). Bye, Axel. From mmlr at mail.berlios.de Sat Sep 13 23:20:15 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sat, 13 Sep 2008 23:20:15 +0200 Subject: [Haiku-commits] r27499 - haiku/trunk/src/add-ons/accelerants/intel_extreme Message-ID: <200809132120.m8DLKFDc028040@sheep.berlios.de> Author: mmlr Date: 2008-09-13 23:20:14 +0200 (Sat, 13 Sep 2008) New Revision: 27499 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27499&view=rev Modified: haiku/trunk/src/add-ons/accelerants/intel_extreme/mode.cpp Log: OK, how completely can one mess up a single change? Fixed the intel_extreme accelerant I broke. Modified: haiku/trunk/src/add-ons/accelerants/intel_extreme/mode.cpp =================================================================== --- haiku/trunk/src/add-ons/accelerants/intel_extreme/mode.cpp 2008-09-13 19:50:01 UTC (rev 27498) +++ haiku/trunk/src/add-ons/accelerants/intel_extreme/mode.cpp 2008-09-13 21:20:14 UTC (rev 27499) @@ -529,10 +529,13 @@ { TRACE(("intel_set_display_mode()\n")); - display_mode target; - if (mode == NULL || intel_propose_display_mode(&target, mode, mode)) + if (mode == NULL) return B_BAD_VALUE; + display_mode target = *mode; + if (intel_propose_display_mode(&target, mode, mode)) + return B_BAD_VALUE; + uint32 colorMode, bytesPerRow, bitsPerPixel; get_color_space_format(target, colorMode, bytesPerRow, bitsPerPixel); From axeld at mail.berlios.de Sun Sep 14 10:52:15 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sun, 14 Sep 2008 10:52:15 +0200 Subject: [Haiku-commits] r27500 - haiku/trunk/src/system/kernel/arch/x86 Message-ID: <200809140852.m8E8qFbS014508@sheep.berlios.de> Author: axeld Date: 2008-09-14 10:52:14 +0200 (Sun, 14 Sep 2008) New Revision: 27500 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27500&view=rev Modified: haiku/trunk/src/system/kernel/arch/x86/arch_cpu.cpp Log: * If we're in the kernel debugger, we won't even try to use ACPI to power off, as we cannot do so with interrupts turned off (ACPI needs to allocate memory dynamically). * Turn off interrupts right before going to sleep (_GTS), this at least works in VMware, maybe it also works on real hardware. Modified: haiku/trunk/src/system/kernel/arch/x86/arch_cpu.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/arch_cpu.cpp 2008-09-13 21:20:14 UTC (rev 27499) +++ haiku/trunk/src/system/kernel/arch/x86/arch_cpu.cpp 2008-09-14 08:52:14 UTC (rev 27500) @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -95,13 +96,19 @@ static status_t acpi_shutdown(void) { + if (debug_debugger_running()) + return B_ERROR; + acpi_module_info* acpi; if (get_module(B_ACPI_MODULE_NAME, (module_info**)&acpi) != B_OK) return B_NOT_SUPPORTED; status_t status = acpi->enter_sleep_state(ACPI_POWER_STATE_OFF); - if (status == B_OK) + if (status == B_OK) { + cpu_status state = disable_interrupts(); status = acpi->enter_sleep_state(ACPI_POWER_STATE_OFF); + restore_interrupts(state); + } put_module(B_ACPI_MODULE_NAME); return status; From axeld at mail.berlios.de Sun Sep 14 12:39:30 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sun, 14 Sep 2008 12:39:30 +0200 Subject: [Haiku-commits] r27501 - haiku/trunk/src/add-ons/kernel/file_systems/bfs Message-ID: <200809141039.m8EAdUYb004405@sheep.berlios.de> Author: axeld Date: 2008-09-14 12:39:29 +0200 (Sun, 14 Sep 2008) New Revision: 27501 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27501&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp Log: * Changed the error return by bfs_link() to B_NOT_SUPPORTED. Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp 2008-09-14 08:52:14 UTC (rev 27500) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp 2008-09-14 10:39:29 UTC (rev 27501) @@ -919,8 +919,7 @@ FUNCTION_START(("name = \"%s\"\n", name)); // This one won't be implemented in a binary compatible BFS - - return B_ERROR; + return B_NOT_SUPPORTED; } From axeld at mail.berlios.de Sun Sep 14 13:16:13 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sun, 14 Sep 2008 13:16:13 +0200 Subject: [Haiku-commits] r27502 - haiku/trunk/data/etc/fonts/ttfonts Message-ID: <200809141116.m8EBGDB6016314@sheep.berlios.de> Author: axeld Date: 2008-09-14 13:16:12 +0200 (Sun, 14 Sep 2008) New Revision: 27502 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27502&view=rev Removed: haiku/trunk/data/etc/fonts/ttfonts/Vera.ttf haiku/trunk/data/etc/fonts/ttfonts/VeraBI.ttf haiku/trunk/data/etc/fonts/ttfonts/VeraBd.ttf haiku/trunk/data/etc/fonts/ttfonts/VeraIt.ttf haiku/trunk/data/etc/fonts/ttfonts/VeraMoBI.ttf haiku/trunk/data/etc/fonts/ttfonts/VeraMoBd.ttf haiku/trunk/data/etc/fonts/ttfonts/VeraMoIt.ttf haiku/trunk/data/etc/fonts/ttfonts/VeraMono.ttf haiku/trunk/data/etc/fonts/ttfonts/VeraSe.ttf haiku/trunk/data/etc/fonts/ttfonts/VeraSeBd.ttf Log: * Removed Bitstream Vera fonts, they are replaced by the DejaVu ones. Deleted: haiku/trunk/data/etc/fonts/ttfonts/Vera.ttf Deleted: haiku/trunk/data/etc/fonts/ttfonts/VeraBI.ttf Deleted: haiku/trunk/data/etc/fonts/ttfonts/VeraBd.ttf Deleted: haiku/trunk/data/etc/fonts/ttfonts/VeraIt.ttf Deleted: haiku/trunk/data/etc/fonts/ttfonts/VeraMoBI.ttf Deleted: haiku/trunk/data/etc/fonts/ttfonts/VeraMoBd.ttf Deleted: haiku/trunk/data/etc/fonts/ttfonts/VeraMoIt.ttf Deleted: haiku/trunk/data/etc/fonts/ttfonts/VeraMono.ttf Deleted: haiku/trunk/data/etc/fonts/ttfonts/VeraSe.ttf Deleted: haiku/trunk/data/etc/fonts/ttfonts/VeraSeBd.ttf From laplace at mail.berlios.de Sun Sep 14 14:43:43 2008 From: laplace at mail.berlios.de (laplace at mail.berlios.de) Date: Sun, 14 Sep 2008 14:43:43 +0200 Subject: [Haiku-commits] r27503 - haiku/trunk/src/apps/bootman Message-ID: <200809141243.m8EChhj5027994@sheep.berlios.de> Author: laplace Date: 2008-09-14 14:43:41 +0200 (Sun, 14 Sep 2008) New Revision: 27503 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27503&view=rev Modified: haiku/trunk/src/apps/bootman/LegacyBootDrive.cpp Log: As reported in ticket #2477 the fix in r27149 does not work for NTFS partition. Now all partitions are bootable that do not contain a partitioning system. Modified: haiku/trunk/src/apps/bootman/LegacyBootDrive.cpp =================================================================== --- haiku/trunk/src/apps/bootman/LegacyBootDrive.cpp 2008-09-14 11:16:12 UTC (rev 27502) +++ haiku/trunk/src/apps/bootman/LegacyBootDrive.cpp 2008-09-14 12:43:41 UTC (rev 27503) @@ -170,7 +170,7 @@ bool PartitionRecorder::_Record(BPartition* partition) { - if (!partition->ContainsFileSystem()) + if (partition->ContainsPartitioningSystem()) return false; BPath partitionPath; From mmlr at mlotz.ch Sun Sep 14 15:40:40 2008 From: mmlr at mlotz.ch (Michael Lotz) Date: Sun, 14 Sep 2008 15:40:40 +0200 Subject: [Haiku-commits] r27502 - haiku/trunk/data/etc/fonts/ttfonts In-Reply-To: <200809141116.m8EBGDB6016314@sheep.berlios.de> Message-ID: <3543142434-BeMail@primary> > Author: axeld > Date: 2008-09-14 13:16:12 +0200 (Sun, 14 Sep 2008) > New Revision: 27502 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27502&view=rev > > Removed: > haiku/trunk/data/etc/fonts/ttfonts/Vera.ttf > haiku/trunk/data/etc/fonts/ttfonts/VeraBI.ttf > haiku/trunk/data/etc/fonts/ttfonts/VeraBd.ttf > haiku/trunk/data/etc/fonts/ttfonts/VeraIt.ttf > haiku/trunk/data/etc/fonts/ttfonts/VeraMoBI.ttf > haiku/trunk/data/etc/fonts/ttfonts/VeraMoBd.ttf > haiku/trunk/data/etc/fonts/ttfonts/VeraMoIt.ttf > haiku/trunk/data/etc/fonts/ttfonts/VeraMono.ttf > haiku/trunk/data/etc/fonts/ttfonts/VeraSe.ttf > haiku/trunk/data/etc/fonts/ttfonts/VeraSeBd.ttf > Log: > * Removed Bitstream Vera fonts, they are replaced by the DejaVu ones. Note that the FontManager in the app_server (src/servers/app/ FontManager.cpp) still has the BitStream fonts hardcoded for the fallback default mappings. These should either be updated there or maybe handled in a different way in general so that no font names need to be hardcoded. Regards Michael From mmlr at mail.berlios.de Sun Sep 14 19:51:16 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sun, 14 Sep 2008 19:51:16 +0200 Subject: [Haiku-commits] r27504 - haiku/trunk/src/kits/tracker Message-ID: <200809141751.m8EHpGd3024766@sheep.berlios.de> Author: mmlr Date: 2008-09-14 19:51:13 +0200 (Sun, 14 Sep 2008) New Revision: 27504 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27504&view=rev Modified: haiku/trunk/src/kits/tracker/InfoWindow.cpp Log: Don't build the context menu before checking for NULL. Fixes CID 1077, though the Tracker sources should really be cleaned up to use nothrow and/or exception handling more consistently. Modified: haiku/trunk/src/kits/tracker/InfoWindow.cpp =================================================================== --- haiku/trunk/src/kits/tracker/InfoWindow.cpp 2008-09-14 12:43:41 UTC (rev 27503) +++ haiku/trunk/src/kits/tracker/InfoWindow.cpp 2008-09-14 17:51:13 UTC (rev 27504) @@ -1242,8 +1242,8 @@ if (((modifiers() & B_CONTROL_KEY) != 0) || (buttons & B_SECONDARY_MOUSE_BUTTON) != 0) { // Show contextual menu BPopUpMenu *contextMenu = new BPopUpMenu("FileContext", false, false); - BuildContextMenu(contextMenu); if (contextMenu) { + BuildContextMenu(contextMenu); contextMenu->SetAsyncAutoDestruct(true); contextMenu->Go(ConvertToScreen(point), true, true, ConvertToScreen(fIconRect)); } From mmlr at mail.berlios.de Sun Sep 14 20:09:36 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sun, 14 Sep 2008 20:09:36 +0200 Subject: [Haiku-commits] r27505 - haiku/trunk/src/kits/tracker Message-ID: <200809141809.m8EI9aU6026141@sheep.berlios.de> Author: mmlr Date: 2008-09-14 20:09:35 +0200 (Sun, 14 Sep 2008) New Revision: 27505 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27505&view=rev Modified: haiku/trunk/src/kits/tracker/ContainerWindow.cpp Log: Remove superfluous NULL check as menu being non-NULL is asserted at the top. Fixes CID 1075. Modified: haiku/trunk/src/kits/tracker/ContainerWindow.cpp =================================================================== --- haiku/trunk/src/kits/tracker/ContainerWindow.cpp 2008-09-14 17:51:13 UTC (rev 27504) +++ haiku/trunk/src/kits/tracker/ContainerWindow.cpp 2008-09-14 18:09:35 UTC (rev 27505) @@ -2137,7 +2137,7 @@ if (!poseViewIsQuery && !queryInSelection && item) item->Menu()->RemoveItem(item); - else if ((poseViewIsQuery || queryInSelection) && menu && !item) { + else if ((poseViewIsQuery || queryInSelection) && !item) { // add edit query item after Open item = menu->FindItem(kOpenSelection); From marcusoverhagen at arcor.de Sun Sep 14 20:13:04 2008 From: marcusoverhagen at arcor.de (Marcus Overhagen) Date: Sun, 14 Sep 2008 20:13:04 +0200 Subject: [Haiku-commits] r27463 - haiku/trunk/src/kits/device In-Reply-To: <200809121829.m8CITHGn002057@sheep.berlios.de> References: <200809121829.m8CITHGn002057@sheep.berlios.de> Message-ID: <48CD5430.70103@arcor.de> modeenf at mail.berlios.de schrieb: > Log: > fixes pointed out by Axel, and style changes. Please do not mix style changes with other changes. That makes it very hard to see what logic has changed. regards Marcus From emitrax at gmail.com Sun Sep 14 20:27:32 2008 From: emitrax at gmail.com (Salvatore Benedetto) Date: Sun, 14 Sep 2008 18:27:32 +0000 Subject: [Haiku-commits] r27463 - haiku/trunk/src/kits/device In-Reply-To: <48CD5430.70103@arcor.de> References: <200809121829.m8CITHGn002057@sheep.berlios.de> <48CD5430.70103@arcor.de> Message-ID: 2008/9/14 Marcus Overhagen : > modeenf at mail.berlios.de schrieb: > >> Log: >> fixes pointed out by Axel, and style changes. > > Please do not mix style changes with other changes. > > That makes it very hard to see what logic has changed. We should add this suggestion to one of the development document for (new) developers, perhaps a note in the coding guidelines. -- Salvatore Benedetto (a.k.a. emitrax) Student of Computer Engineer University of Pisa www.haiku-os.it From stippi at mail.berlios.de Sun Sep 14 20:46:29 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Sun, 14 Sep 2008 20:46:29 +0200 Subject: [Haiku-commits] r27506 - haiku/trunk/headers/private/shared Message-ID: <200809141846.m8EIkTGg029148@sheep.berlios.de> Author: stippi Date: 2008-09-14 20:46:26 +0200 (Sun, 14 Sep 2008) New Revision: 27506 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27506&view=rev Added: haiku/trunk/headers/private/shared/FunctionTracer.h Log: This class helps me with tracing function enter/leave output. It is passed a static integer that it uses for indentation. Added: haiku/trunk/headers/private/shared/FunctionTracer.h =================================================================== --- haiku/trunk/headers/private/shared/FunctionTracer.h 2008-09-14 18:09:35 UTC (rev 27505) +++ haiku/trunk/headers/private/shared/FunctionTracer.h 2008-09-14 18:46:26 UTC (rev 27506) @@ -0,0 +1,46 @@ +/* + * Copyright ? 2008 Stephan A?mus + * All rights reserved. Distributed under the terms of the MIT/X11 license. + */ +#ifndef FUNCTION_TRACER_H +#define FUNCTION_TRACER_H + +#include + +#include + +namespace BPrivate { + +class FunctionTracer { +public: + FunctionTracer(const char* className, const char* functionName, + int32& depth) + : fFunctionName(), + fPrepend(), + fFunctionDepth(depth) + { + fFunctionDepth++; + fPrepend.Append(' ', fFunctionDepth * 2); + fFunctionName << className << "::" << functionName << "()"; + + printf("%s%s {\n", fPrepend.String(), fFunctionName.String()); + } + + ~FunctionTracer() + { +// printf("%s - leave\n", fFunctionName.String()); + printf("%s}\n", fPrepend.String()); + fFunctionDepth--; + } + +private: + BString fFunctionName; + BString fPrepend; + int32& fFunctionDepth; +}; + +} // namespace BPrivate + +using BPrivate::FunctionTracer; + +#endif // FUNCTION_TRACER_H From stippi at mail.berlios.de Sun Sep 14 20:52:33 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Sun, 14 Sep 2008 20:52:33 +0200 Subject: [Haiku-commits] r27507 - haiku/trunk/src/kits/interface Message-ID: <200809141852.m8EIqXCi029566@sheep.berlios.de> Author: stippi Date: 2008-09-14 20:52:30 +0200 (Sun, 14 Sep 2008) New Revision: 27507 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27507&view=rev Modified: haiku/trunk/src/kits/interface/BMCPrivate.cpp Log: * Added a comment about the purpose of the code in AttachedToWindow(). * Improved FrameResized(). The "diff" is actually between the new location of the right side (Frame().right) and the location where it probably was in the parent before it is resized (fMenuField->Bounds().right - 2). Could be that this change is wrong, or at least, not yet correct. Will test on a different machine. Modified: haiku/trunk/src/kits/interface/BMCPrivate.cpp =================================================================== --- haiku/trunk/src/kits/interface/BMCPrivate.cpp 2008-09-14 18:46:26 UTC (rev 27506) +++ haiku/trunk/src/kits/interface/BMCPrivate.cpp 2008-09-14 18:52:30 UTC (rev 27507) @@ -116,6 +116,7 @@ { fMenuField = static_cast(Parent()); + // Don't cause the KeyMenuBar to change by being attached BMenuBar *menuBar = Window()->KeyMenuBar(); BMenuBar::AttachedToWindow(); if (fFixedSize) @@ -236,7 +237,7 @@ if (fFixedSize) diff = width - fPreviousWidth; else - diff = Frame().right - fMenuField->Bounds().right; + diff = Frame().right - (fMenuField->Bounds().right - 2); fPreviousWidth = width; @@ -272,7 +273,7 @@ // of the size of the parent menu field as well // NOTE: no worries about follow mode, we follow left and top // in autosize mode - fMenuField->ResizeBy(diff + 2, 0.0); + fMenuField->ResizeBy(diff, 0.0); } BMenuBar::FrameResized(width, height); } From stippi at mail.berlios.de Sun Sep 14 21:01:58 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Sun, 14 Sep 2008 21:01:58 +0200 Subject: [Haiku-commits] r27508 - in haiku/trunk: headers/os/interface src/kits/interface Message-ID: <200809141901.m8EJ1w5v030565@sheep.berlios.de> Author: stippi Date: 2008-09-14 21:01:54 +0200 (Sun, 14 Sep 2008) New Revision: 27508 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27508&view=rev Modified: haiku/trunk/headers/os/interface/MenuField.h haiku/trunk/src/kits/interface/MenuField.cpp Log: Several fixes to BMenuField layout calculations. * The most important fix is that in BMenuField::_ValidateLayoutData(), divider was calculated, but then never used. If the menu field was not using the layout management, it should take the existing fDivider into account, but never did. This caused #2728. * Added some tracing that helped me debug this. * Fixed a bunch of layouting inconsistencies. It will also improve some unnecessary resizing of the menu bar. Will test all of this some more. But in the test app I do have, the BMenuField works more like in BeOS now. Modified: haiku/trunk/headers/os/interface/MenuField.h =================================================================== --- haiku/trunk/headers/os/interface/MenuField.h 2008-09-14 18:52:30 UTC (rev 27507) +++ haiku/trunk/headers/os/interface/MenuField.h 2008-09-14 19:01:54 UTC (rev 27508) @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku, Inc. All Rights Reserved. + * Copyright 2006-2008, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. */ @@ -115,7 +115,7 @@ void DrawLabel(BRect bounds, BRect update); static void InitMenu(BMenu* menu); - int32 _MenuTask(); + int32 _MenuTask(); static int32 _thread_entry(void *arg); void _UpdateFrame(); @@ -123,6 +123,7 @@ BRect frame, bool fixedSize); void _ValidateLayoutData(); + float _MenuBarWidthDiff() const; char* fLabel; BMenu* fMenu; Modified: haiku/trunk/src/kits/interface/MenuField.cpp =================================================================== --- haiku/trunk/src/kits/interface/MenuField.cpp 2008-09-14 18:52:30 UTC (rev 27507) +++ haiku/trunk/src/kits/interface/MenuField.cpp 2008-09-14 19:01:54 UTC (rev 27508) @@ -1,5 +1,5 @@ /* - * Copyright 2001-2006, Haiku, Inc. + * Copyright 2001-2008, Haiku, Inc. * Distributed under the terms of the MIT License. * * Authors: @@ -20,6 +20,21 @@ #include +//#define TRACE_MENU_FIELD +#ifdef TRACE_MENU_FIELD +# include + static int32 sFunctionDepth = -1; +# define CALLED(x...) FunctionTracer _ft("BMenuField", __FUNCTION__, \ + sFunctionDepth) +# define TRACE(x...) { BString _to; \ + _to.Append(' ', (sFunctionDepth + 1) * 2); \ + printf("%s", _to.String()); printf(x); } +#else +# define CALLED(x...) +# define TRACE(x...) +#endif + + class BMenuField::LabelLayoutItem : public BAbstractLayoutItem { public: LabelLayoutItem(BMenuField* parent); @@ -98,6 +113,10 @@ BMenu *menu, uint32 resize, uint32 flags) : BView(frame, name, resize, flags) { + CALLED(); + + TRACE("frame.width: %.2f, height: %.2f\n", frame.Width(), frame.Height()); + InitObject(label); frame.OffsetTo(B_ORIGIN); @@ -280,6 +299,8 @@ void BMenuField::AttachedToWindow() { + CALLED(); + BView* parent = Parent(); if (parent != NULL) { // inherit the color from parent @@ -296,8 +317,14 @@ void BMenuField::AllAttached() { + CALLED(); + + TRACE("width: %.2f, height: %.2f\n", Frame().Width(), Frame().Height()); + ResizeTo(Bounds().Width(), fMenuBar->Bounds().Height() + kVMargin + kVMargin); + + TRACE("width: %.2f, height: %.2f\n", Frame().Width(), Frame().Height()); } @@ -592,18 +619,26 @@ void BMenuField::ResizeToPreferred() { + CALLED(); + + TRACE("fMenuBar->Frame().width: %.2f, height: %.2f\n", + fMenuBar->Frame().Width(), fMenuBar->Frame().Height()); + fMenuBar->ResizeToPreferred(); + TRACE("fMenuBar->Frame().width: %.2f, height: %.2f\n", + fMenuBar->Frame().Width(), fMenuBar->Frame().Height()); + BView::ResizeToPreferred(); if (fFixedSizeMB) { - // we have let the menubar resize itsself, but + // we have let the menubar resize itself, but // in fixed size mode, the menubar is supposed to // be at the right end of the view always. Since // the menu bar is in follow left/right mode then, // resizing ourselfs might have caused the menubar // to be outside now - fMenuBar->ResizeTo(Bounds().Width() - fDivider - 2, + fMenuBar->ResizeTo(Bounds().Width() - _MenuBarWidthDiff(), fMenuBar->Frame().Height()); } } @@ -612,6 +647,8 @@ void BMenuField::GetPreferredSize(float *_width, float *_height) { + CALLED(); + _ValidateLayoutData(); if (_width) @@ -625,6 +662,8 @@ BSize BMenuField::MinSize() { + CALLED(); + _ValidateLayoutData(); return BLayoutUtils::ComposeSize(ExplicitMinSize(), fLayoutData->min); } @@ -633,6 +672,8 @@ BSize BMenuField::MaxSize() { + CALLED(); + _ValidateLayoutData(); return BLayoutUtils::ComposeSize(ExplicitMaxSize(), fLayoutData->min); } @@ -641,6 +682,8 @@ BSize BMenuField::PreferredSize() { + CALLED(); + _ValidateLayoutData(); return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), fLayoutData->min); } @@ -649,6 +692,8 @@ void BMenuField::InvalidateLayout(bool descendants) { + CALLED(); + fLayoutData->valid = false; BView::InvalidateLayout(descendants); @@ -687,6 +732,8 @@ if (!(Flags() & B_SUPPORTS_LAYOUT)) return; + CALLED(); + // If the user set a layout, we let the base class version call its // hook. if (GetLayout()) { @@ -747,6 +794,8 @@ void BMenuField::InitObject(const char *label) { + CALLED(); + fLabel = NULL; fMenu = NULL; fMenuBar = NULL; @@ -773,14 +822,17 @@ void BMenuField::InitObject2() { - font_height fontHeight; - GetFontHeight(&fontHeight); + CALLED(); - // TODO: fix this calculation - float height = floorf(fontHeight.ascent + fontHeight.descent - + fontHeight.leading) + 7; + float height; + fMenuBar->GetPreferredSize(NULL, &height); + fMenuBar->ResizeTo(Bounds().Width() - _MenuBarWidthDiff(), height); - fMenuBar->ResizeTo(Bounds().Width() - fDivider - 2, height); + TRACE("frame(%.1f, %.1f, %.1f, %.1f) (%.2f, %.2f)\n", + fMenuBar->Frame().left, fMenuBar->Frame().top, + fMenuBar->Frame().right, fMenuBar->Frame().bottom, + fMenuBar->Frame().Width(), fMenuBar->Frame().Height()); + fMenuBar->AddFilter(new _BMCFilter_(this, B_MOUSE_DOWN)); } @@ -788,6 +840,8 @@ void BMenuField::DrawLabel(BRect bounds, BRect update) { + CALLED(); + _ValidateLayoutData(); font_height& fh = fLayoutData->font_info; @@ -880,6 +934,8 @@ void BMenuField::_UpdateFrame() { + CALLED(); + if (fLayoutData->label_layout_item && fLayoutData->menu_bar_layout_item) { BRect labelFrame = fLayoutData->label_layout_item->Frame(); BRect menuFrame = fLayoutData->menu_bar_layout_item->Frame(); @@ -905,13 +961,22 @@ void BMenuField::_InitMenuBar(BMenu* menu, BRect frame, bool fixedSize) { + CALLED(); + fMenu = menu; InitMenu(menu); - fMenuBar = new _BMCMenuBar_(BRect(frame.left + fDivider + 1, - frame.top + kVMargin, frame.right - 2, frame.bottom - kVMargin), - fixedSize, this); + frame.left = fDivider + 1; + frame.top = kVMargin; + frame.right -= kVMargin; + frame.bottom -= kVMargin; + TRACE("frame(%.1f, %.1f, %.1f, %.1f) (%.2f, %.2f)\n", + frame.left, frame.top, frame.right, frame.bottom, + frame.Width(), frame.Height()); + + fMenuBar = new _BMCMenuBar_(frame, fixedSize, this); + // by default align the menu bar left in the available space fMenuBar->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_VERTICAL_UNSET)); @@ -926,6 +991,8 @@ void BMenuField::_ValidateLayoutData() { + CALLED(); + if (fLayoutData->valid) return; @@ -946,11 +1013,17 @@ divider = max_c(divider, fDivider); // get the minimal (== preferred) menu bar size + // TODO: BMenu::MinSize() is using the ResizeMode() to decide the + // minimum width. If the mode is B_FOLLOW_LEFT_RIGHT, it will use the + // parent's frame width or window's frame width. So at least the returned + // size is wrong, but appearantly it doesn't have much bad effect. fLayoutData->menu_bar_min = fMenuBar->MinSize(); + TRACE("menu bar min width: %.2f\n", fLayoutData->menu_bar_min.width); + // compute our minimal (== preferred) size - // TODO: The layout is a bit broken. A one pixel wide border is draw around - // the menu bar to give it it's look. When the view has the focus, + // TODO: The layout is a bit broken. A one pixel wide border is drawn + // around the menu bar to give it it's look. When the view has the focus, // additionally a one pixel wide blue frame is drawn around it. In order // to be able to easily visually align the menu bar with the text view of // a text control, the divider must ignore the focus frame, though. Hence @@ -959,17 +1032,27 @@ min.width += 2 * kVMargin - 1; min.height += 2 * kVMargin; - if (fLayoutData->label_width > 0) - min.width += fLayoutData->label_width + 5; + if (divider > 0) + min.width += divider; if (fLayoutData->label_height > min.height) min.height = fLayoutData->label_height; fLayoutData->min = min; fLayoutData->valid = true; + + + TRACE("width: %.2f, height: %.2f\n", min.width, min.height); } +float +BMenuField::_MenuBarWidthDiff() const +{ + return fDivider + kVMargin + 1; +} + + // #pragma mark - From stippi at mail.berlios.de Sun Sep 14 22:28:38 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Sun, 14 Sep 2008 22:28:38 +0200 Subject: [Haiku-commits] r27509 - haiku/trunk/src/kits/interface Message-ID: <200809142028.m8EKScE9005934@sheep.berlios.de> Author: stippi Date: 2008-09-14 22:28:35 +0200 (Sun, 14 Sep 2008) New Revision: 27509 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27509&view=rev Modified: haiku/trunk/src/kits/interface/MenuField.cpp Log: Use the dedicated BView constructor for using layout management. Modified: haiku/trunk/src/kits/interface/MenuField.cpp =================================================================== --- haiku/trunk/src/kits/interface/MenuField.cpp 2008-09-14 19:01:54 UTC (rev 27508) +++ haiku/trunk/src/kits/interface/MenuField.cpp 2008-09-14 20:28:35 UTC (rev 27509) @@ -143,8 +143,7 @@ BMenuField::BMenuField(const char* name, const char* label, BMenu* menu, BMessage* message, uint32 flags) - : BView(BRect(0, 0, -1, -1), name, B_FOLLOW_NONE, - flags | B_FRAME_EVENTS | B_SUPPORTS_LAYOUT) + : BView(name, flags | B_FRAME_EVENTS) { InitObject(label); @@ -156,8 +155,7 @@ BMenuField::BMenuField(const char* label, BMenu* menu, BMessage* message) - : BView(BRect(0, 0, -1, -1), NULL, B_FOLLOW_NONE, - B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS | B_SUPPORTS_LAYOUT) + : BView(NULL, B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS) { InitObject(label); From jackburton at mail.berlios.de Mon Sep 15 08:52:00 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Mon, 15 Sep 2008 08:52:00 +0200 Subject: [Haiku-commits] r27510 - haiku/trunk/src/add-ons/mail_daemon/outbound_protocols/smtp Message-ID: <200809150652.m8F6q0gQ027207@sheep.berlios.de> Author: jackburton Date: 2008-09-15 08:51:59 +0200 (Mon, 15 Sep 2008) New Revision: 27510 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27510&view=rev Modified: haiku/trunk/src/add-ons/mail_daemon/outbound_protocols/smtp/smtp.cpp Log: the 'base' string was leaked. CID 1296 Modified: haiku/trunk/src/add-ons/mail_daemon/outbound_protocols/smtp/smtp.cpp =================================================================== --- haiku/trunk/src/add-ons/mail_daemon/outbound_protocols/smtp/smtp.cpp 2008-09-14 20:28:35 UTC (rev 27509) +++ haiku/trunk/src/add-ons/mail_daemon/outbound_protocols/smtp/smtp.cpp 2008-09-15 06:51:59 UTC (rev 27510) @@ -587,6 +587,8 @@ map challengeMap; SplitChallengeIntoMap(base, challengeMap); + delete[] base; + BString rawResponse = BString("username=") << '"' << login << '"'; rawResponse << ",realm=" << '"' << challengeMap["realm"] << '"'; rawResponse << ",nonce=" << '"' << challengeMap["nonce"] << '"'; From jackburton at mail.berlios.de Mon Sep 15 09:17:28 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Mon, 15 Sep 2008 09:17:28 +0200 Subject: [Haiku-commits] r27511 - haiku/trunk/src/kits/game Message-ID: <200809150717.m8F7HScJ029145@sheep.berlios.de> Author: jackburton Date: 2008-09-15 09:17:27 +0200 (Mon, 15 Sep 2008) New Revision: 27511 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27511&view=rev Modified: haiku/trunk/src/kits/game/GameSoundBuffer.cpp Log: set fPanRamp and fGainRamp to NULL after deleting them, otherwise they could be double-freed. Also dont' check for NULL before calling delete. CID 1230 and 1231 Modified: haiku/trunk/src/kits/game/GameSoundBuffer.cpp =================================================================== --- haiku/trunk/src/kits/game/GameSoundBuffer.cpp 2008-09-15 06:51:59 UTC (rev 27510) +++ haiku/trunk/src/kits/game/GameSoundBuffer.cpp 2008-09-15 07:17:27 UTC (rev 27511) @@ -147,8 +147,9 @@ if (gain < 0.0 || gain > 1.0) return B_BAD_VALUE; - if (fGainRamp) delete fGainRamp; - + delete fGainRamp; + fGainRamp = NULL; + if (duration > 100000) fGainRamp = InitRamp(&fGain, gain, fFormat.frame_rate, duration); else @@ -171,9 +172,9 @@ if (pan < -1.0 || pan > 1.0) return B_BAD_VALUE; - if (fPanRamp) - delete fPanRamp; - + delete fPanRamp; + fPanRamp = NULL; + if (duration < 100000) { fPan = pan; From jackburton at mail.berlios.de Mon Sep 15 09:36:01 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Mon, 15 Sep 2008 09:36:01 +0200 Subject: [Haiku-commits] r27512 - haiku/trunk/src/add-ons/translators/rtf Message-ID: <200809150736.m8F7a1Xe030629@sheep.berlios.de> Author: jackburton Date: 2008-09-15 09:35:58 +0200 (Mon, 15 Sep 2008) New Revision: 27512 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27512&view=rev Modified: haiku/trunk/src/add-ons/translators/rtf/convert.cpp Log: BTextView::FlattenRunArray() doesn't take ownership of the passed array. Fixes CID 904 Modified: haiku/trunk/src/add-ons/translators/rtf/convert.cpp =================================================================== --- haiku/trunk/src/add-ons/translators/rtf/convert.cpp 2008-09-15 07:17:27 UTC (rev 27511) +++ haiku/trunk/src/add-ons/translators/rtf/convert.cpp 2008-09-15 07:35:58 UTC (rev 27512) @@ -357,7 +357,11 @@ delete run; } - return BTextView::FlattenRunArray(array, &_size); + void *flattenedRunArray = BTextView::FlattenRunArray(array, &_size); + + delete array; + + return flattenedRunArray; } From jackburton at mail.berlios.de Mon Sep 15 09:37:05 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Mon, 15 Sep 2008 09:37:05 +0200 Subject: [Haiku-commits] r27513 - haiku/trunk/src/add-ons/translators/rtf Message-ID: <200809150737.m8F7b5PW030674@sheep.berlios.de> Author: jackburton Date: 2008-09-15 09:37:03 +0200 (Mon, 15 Sep 2008) New Revision: 27513 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27513&view=rev Modified: haiku/trunk/src/add-ons/translators/rtf/convert.cpp Log: delete -> free(), as the array is allocated with malloc Modified: haiku/trunk/src/add-ons/translators/rtf/convert.cpp =================================================================== --- haiku/trunk/src/add-ons/translators/rtf/convert.cpp 2008-09-15 07:35:58 UTC (rev 27512) +++ haiku/trunk/src/add-ons/translators/rtf/convert.cpp 2008-09-15 07:37:03 UTC (rev 27513) @@ -359,7 +359,7 @@ void *flattenedRunArray = BTextView::FlattenRunArray(array, &_size); - delete array; + free(array); return flattenedRunArray; } From jackburton at mail.berlios.de Mon Sep 15 09:49:29 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Mon, 15 Sep 2008 09:49:29 +0200 Subject: [Haiku-commits] r27514 - haiku/trunk/src/add-ons/translators/rtf Message-ID: <200809150749.m8F7nT1Q031700@sheep.berlios.de> Author: jackburton Date: 2008-09-15 09:49:27 +0200 (Mon, 15 Sep 2008) New Revision: 27514 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27514&view=rev Modified: haiku/trunk/src/add-ons/translators/rtf/Jamfile haiku/trunk/src/add-ons/translators/rtf/convert.cpp Log: use MemoryDeleter to make sure we free 'flattenedRuns' on error, in every case. CID 905 Modified: haiku/trunk/src/add-ons/translators/rtf/Jamfile =================================================================== --- haiku/trunk/src/add-ons/translators/rtf/Jamfile 2008-09-15 07:37:03 UTC (rev 27513) +++ haiku/trunk/src/add-ons/translators/rtf/Jamfile 2008-09-15 07:49:27 UTC (rev 27514) @@ -8,6 +8,8 @@ SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) shared ] ; +UsePrivateHeaders shared ; + Translator RTF-Translator : # RTFTranslator classes main.cpp Modified: haiku/trunk/src/add-ons/translators/rtf/convert.cpp =================================================================== --- haiku/trunk/src/add-ons/translators/rtf/convert.cpp 2008-09-15 07:37:03 UTC (rev 27513) +++ haiku/trunk/src/add-ons/translators/rtf/convert.cpp 2008-09-15 07:49:27 UTC (rev 27514) @@ -16,6 +16,8 @@ #include #include +#include + #include #include #include @@ -573,6 +575,8 @@ return status; } + BPrivate::MemoryDeleter _(flattenedRuns); + // put out styles TranslatorStyledTextStyleHeader styleHeader; @@ -584,7 +588,7 @@ status = swap_data(B_UINT32_TYPE, &styleHeader, sizeof(styleHeader), B_SWAP_HOST_TO_BENDIAN); - if (status != B_OK) + if (status != B_OK) return status; written = target.Write(&styleHeader, sizeof(styleHeader)); @@ -596,8 +600,6 @@ // output actual style information written = target.Write(flattenedRuns, flattenedSize); - free(flattenedRuns); - if (written < B_OK) return written; if (written != flattenedSize) From jackburton at mail.berlios.de Mon Sep 15 10:01:44 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Mon, 15 Sep 2008 10:01:44 +0200 Subject: [Haiku-commits] r27515 - haiku/trunk/src/add-ons/input_server/devices/keyboard Message-ID: <200809150801.m8F81iL3000319@sheep.berlios.de> Author: jackburton Date: 2008-09-15 10:01:33 +0200 (Mon, 15 Sep 2008) New Revision: 27515 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27515&view=rev Modified: haiku/trunk/src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.cpp Log: free the allocated strings in error case. CID 864 Modified: haiku/trunk/src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.cpp =================================================================== --- haiku/trunk/src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.cpp 2008-09-15 07:49:27 UTC (rev 27514) +++ haiku/trunk/src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.cpp 2008-09-15 08:01:33 UTC (rev 27515) @@ -745,8 +745,11 @@ keymap->GetChars(keycode, 0, 0, &rawString, &rawNumBytes); BMessage *msg = new BMessage; - if (msg == NULL) + if (msg == NULL) { + free(string); + free(rawString); continue; + } if (numBytes > 0) msg->what = isKeyDown ? B_KEY_DOWN : B_KEY_UP; From jackburton at mail.berlios.de Mon Sep 15 12:30:54 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Mon, 15 Sep 2008 12:30:54 +0200 Subject: [Haiku-commits] r27516 - haiku/trunk/src/add-ons/translators/gif Message-ID: <200809151030.m8FAUsrd023125@sheep.berlios.de> Author: jackburton Date: 2008-09-15 12:30:45 +0200 (Mon, 15 Sep 2008) New Revision: 27516 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27516&view=rev Modified: haiku/trunk/src/add-ons/translators/gif/GIFLoad.cpp haiku/trunk/src/add-ons/translators/gif/GIFLoad.h Log: Style changes. No functional change Modified: haiku/trunk/src/add-ons/translators/gif/GIFLoad.cpp =================================================================== --- haiku/trunk/src/add-ons/translators/gif/GIFLoad.cpp 2008-09-15 08:01:33 UTC (rev 27515) +++ haiku/trunk/src/add-ons/translators/gif/GIFLoad.cpp 2008-09-15 10:30:45 UTC (rev 27516) @@ -23,8 +23,8 @@ extern bool debug; GIFLoad::GIFLoad(BPositionIO *input, BPositionIO *output) { - this->input = input; - this->output = output; + fInput = input; + fOutput = output; Init(); if (!ReadGIFHeader()) { @@ -32,10 +32,10 @@ return; } - if (debug) printf("GIFLoad::GIFLoad() - Image dimensions are %d x %d\n", width, height); + if (debug) printf("GIFLoad::GIFLoad() - Image dimensions are %d x %d\n", fWidth, fHeight); unsigned char c; - if (input->Read(&c, 1) < 1) { + if (fInput->Read(&c, 1) < 1) { fatalerror = true; return; } @@ -47,11 +47,11 @@ } else { if (debug) printf("GIFLoad::GIFLoad() - Found a single image and leaving\n"); } - if (scanline != NULL) free(scanline); + if (fScanLine != NULL) free(fScanLine); return; } else if (c == 0x21) { unsigned char d; - if (input->Read(&d, 1) < 1) { + if (fInput->Read(&d, 1) < 1) { fatalerror = true; return; } @@ -82,7 +82,7 @@ return; } } - if (input->Read(&c, 1) < 1) { + if (fInput->Read(&c, 1) < 1) { fatalerror = true; return; } @@ -92,55 +92,55 @@ void GIFLoad::Init() { fatalerror = false; - scanline = NULL; - palette = NULL; - input->Seek(0, SEEK_SET); - head_memblock = NULL; + fScanLine = NULL; + fPalette = NULL; + fInput->Seek(0, SEEK_SET); + fHeadMemblock = NULL; } bool GIFLoad::ReadGIFHeader() { // Standard header unsigned char header[13]; - if (input->Read(header, 13) < 13) return false; - width = header[6] + (header[7] << 8); - height = header[8] + (header[9] << 8); + if (fInput->Read(header, 13) < 13) return false; + fWidth = header[6] + (header[7] << 8); + fHeight = header[8] + (header[9] << 8); - palette = new LoadPalette(); + fPalette = new LoadPalette(); // Global palette if (header[10] & 0x80) { - palette->size_in_bits = (header[10] & 0x07) + 1; - if (debug) printf("GIFLoad::ReadGIFHeader() - Found %d bit global palette\n", palette->size_in_bits); - int s = 1 << palette->size_in_bits; - palette->size = s; + fPalette->size_in_bits = (header[10] & 0x07) + 1; + if (debug) printf("GIFLoad::ReadGIFHeader() - Found %d bit global palette\n", fPalette->size_in_bits); + int s = 1 << fPalette->size_in_bits; + fPalette->size = s; unsigned char gp[256 * 3]; - if (input->Read(gp, s * 3) < s * 3) return false; + if (fInput->Read(gp, s * 3) < s * 3) return false; for (int x = 0; x < s; x++) { - palette->SetColor(x, gp[x * 3], gp[x * 3 + 1], gp[x * 3 + 2]); + fPalette->SetColor(x, gp[x * 3], gp[x * 3 + 1], gp[x * 3 + 2]); } - palette->backgroundindex = header[11]; + fPalette->backgroundindex = header[11]; } else { // Install BeOS system palette in case local palette isn't present color_map *map = (color_map *)system_colors(); for (int x = 0; x < 256; x++) { - palette->SetColor(x, map->color_list[x].red, map->color_list[x].green, + fPalette->SetColor(x, map->color_list[x].red, map->color_list[x].green, map->color_list[x].blue); } - palette->size = 256; - palette->size_in_bits = 8; + fPalette->size = 256; + fPalette->size_in_bits = 8; } return true; } bool GIFLoad::ReadGIFLoopBlock() { unsigned char length; - if (input->Read(&length, 1) < 1) return false; - input->Seek(length, SEEK_CUR); + if (fInput->Read(&length, 1) < 1) return false; + fInput->Seek(length, SEEK_CUR); do { - if (input->Read(&length, 1) < 1) { + if (fInput->Read(&length, 1) < 1) { return false; } - input->Seek(length, SEEK_CUR); + fInput->Seek(length, SEEK_CUR); } while (length != 0); return true; @@ -148,10 +148,10 @@ bool GIFLoad::ReadGIFControlBlock() { unsigned char data[6]; - if (input->Read(data, 6) < 6) return false; + if (fInput->Read(data, 6) < 6) return false; if (data[1] & 0x01) { - palette->usetransparent = true; - palette->transparentindex = data[4]; + fPalette->usetransparent = true; + fPalette->transparentindex = data[4]; if (debug) printf("GIFLoad::ReadGIFControlBlock() - Transparency active, using palette index %d\n", data[4]); } return true; @@ -162,8 +162,8 @@ unsigned char length; char comment_data[256]; do { - if (input->Read(&length, 1) < 1) return false; - if (input->Read(comment_data, length) < length) return false; + if (fInput->Read(&length, 1) < 1) return false; + if (fInput->Read(comment_data, length) < length) return false; comment_data[length] = 0x00; if (debug) printf("%s", comment_data); } while (length != 0x00); @@ -175,63 +175,63 @@ if (debug) printf("GIFLoad::ReadGIFUnknownBlock() - Found: %d\n", c); unsigned char length; do { - if (input->Read(&length, 1) < 1) return false; - input->Seek(length, SEEK_CUR); + if (fInput->Read(&length, 1) < 1) return false; + fInput->Seek(length, SEEK_CUR); } while (length != 0x00); return true; } bool GIFLoad::ReadGIFImageHeader() { unsigned char data[9]; - if (input->Read(data, 9) < 9) return false; + if (fInput->Read(data, 9) < 9) return false; int local_width = data[4] + (data[5] << 8); int local_height = data[6] + (data[7] << 8); - if (width != local_width || height != local_height) { + if (fWidth != local_width || fHeight != local_height) { if (debug) printf("GIFLoad::ReadGIFImageHeader() - Local dimensions do not match global, setting to %d x %d\n", local_width, local_height); - width = local_width; - height = local_height; + fWidth = local_width; + fHeight = local_height; } - scanline = (uint32 *)malloc(width * 4); - if (scanline == NULL) { + fScanLine = (uint32 *)malloc(fWidth * 4); + if (fScanLine == NULL) { if (debug) printf("GIFLoad::ReadGIFImageHeader() - Could not allocate scanline\n"); return false; } - BRect rect(0, 0, width - 1, height - 1); + BRect rect(0, 0, fWidth - 1, fHeight - 1); TranslatorBitmap header; header.magic = B_HOST_TO_BENDIAN_INT32(B_TRANSLATOR_BITMAP); header.bounds.left = B_HOST_TO_BENDIAN_FLOAT(rect.left); header.bounds.top = B_HOST_TO_BENDIAN_FLOAT(rect.top); header.bounds.right = B_HOST_TO_BENDIAN_FLOAT(rect.right); header.bounds.bottom = B_HOST_TO_BENDIAN_FLOAT(rect.bottom); - header.rowBytes = B_HOST_TO_BENDIAN_INT32(width * 4); + header.rowBytes = B_HOST_TO_BENDIAN_INT32(fWidth * 4); header.colors = (color_space)B_HOST_TO_BENDIAN_INT32(B_RGBA32); - header.dataSize = B_HOST_TO_BENDIAN_INT32(width * 4 * height); - if (output->Write(&header, 32) < 32) return false; + header.dataSize = B_HOST_TO_BENDIAN_INT32(fWidth * 4 * fHeight); + if (fOutput->Write(&header, 32) < 32) return false; // Has local palette if (data[8] & 0x80) { - palette->size_in_bits = (data[8] & 0x07) + 1; - int s = 1 << palette->size_in_bits; - palette->size = s; + fPalette->size_in_bits = (data[8] & 0x07) + 1; + int s = 1 << fPalette->size_in_bits; + fPalette->size = s; if (debug) printf("GIFLoad::ReadGIFImageHeader() - Found %d bit local palette\n", - palette->size_in_bits); + fPalette->size_in_bits); unsigned char lp[256 * 3]; - if (input->Read(lp, s * 3) < s * 3) return false; + if (fInput->Read(lp, s * 3) < s * 3) return false; for (int x = 0; x < s; x++) { - palette->SetColor(x, lp[x * 3], lp[x * 3 + 1], lp[x * 3 + 2]); + fPalette->SetColor(x, lp[x * 3], lp[x * 3 + 1], lp[x * 3 + 2]); } } if (data[8] & 0x40) { - interlaced = true; + fInterlaced = true; if (debug) printf("GIFLoad::ReadGIFImageHeader() - Image is interlaced\n"); } else { - interlaced = false; + fInterlaced = false; if (debug) printf("GIFLoad::ReadGIFImageHeader() - Image is not interlaced\n"); } return true; @@ -241,87 +241,87 @@ unsigned char new_entry[4096]; unsigned char cs; - input->Read(&cs, 1); - if (cs == palette->size_in_bits) { - if (!InitFrame(palette->size_in_bits)) return false; - } else if (cs > palette->size_in_bits) { - if (debug) printf("GIFLoad::ReadGIFImageData() - Code_size should be %d, not %d, allowing it\n", code_size, cs); + fInput->Read(&cs, 1); + if (cs == fPalette->size_in_bits) { + if (!InitFrame(fPalette->size_in_bits)) return false; + } else if (cs > fPalette->size_in_bits) { + if (debug) printf("GIFLoad::ReadGIFImageData() - Code_size should be %d, not %d, allowing it\n", fCodeSize, cs); if (!InitFrame(cs)) return false; - } else if (cs < palette->size_in_bits) { - if (debug) printf("GIFLoad::ReadGIFImageData() - Code_size should be %d, not %d\n", code_size, cs); + } else if (cs < fPalette->size_in_bits) { + if (debug) printf("GIFLoad::ReadGIFImageData() - Code_size should be %d, not %d\n", fCodeSize, cs); return false; } if (debug) printf("GIFLoad::ReadGIFImageData() - Starting LZW\n"); - while ((new_code = NextCode()) != -1 && new_code != end_code) { - if (new_code == clear_code) { + while ((fNewCode = NextCode()) != -1 && fNewCode != fEndCode) { + if (fNewCode == fClearCode) { ResetTable(); - new_code = NextCode(); - old_code[0] = new_code; - old_code_length = 1; - if (!OutputColor(old_code, 1)) goto bad_end; - if (new_code == -1 || new_code == end_code) { - if (debug) printf("GIFLoad::ReadGIFImageData() - Premature end_code or error\n"); + fNewCode = NextCode(); + fOldCode[0] = fNewCode; + fOldCodeLength = 1; + if (!OutputColor(fOldCode, 1)) goto bad_end; + if (fNewCode == -1 || fNewCode == fEndCode) { + if (debug) printf("GIFLoad::ReadGIFImageData() - Premature fEndCode or error\n"); goto bad_end; } continue; } // Explicitly check for lack of clear code at start of file - if (old_code_length == 0) { - old_code[0] = new_code; - old_code_length = 1; - if (!OutputColor(old_code, 1)) goto bad_end; + if (fOldCodeLength == 0) { + fOldCode[0] = fNewCode; + fOldCodeLength = 1; + if (!OutputColor(fOldCode, 1)) goto bad_end; continue; } - if (table[new_code] != NULL) { // Does exist in table - if (!OutputColor(table[new_code], entry_size[new_code])) goto bad_end; + if (fTable[fNewCode] != NULL) { // Does exist in table + if (!OutputColor(fTable[fNewCode], fEntrySize[fNewCode])) goto bad_end; - //memcpy(new_entry, old_code, old_code_length); - for (int x = 0; x < old_code_length; x++) { - new_entry[x] = old_code[x]; + //memcpy(new_entry, fOldCode, fOldCodeLength); + for (int x = 0; x < fOldCodeLength; x++) { + new_entry[x] = fOldCode[x]; } - //memcpy(new_entry + old_code_length, table[new_code], 1); - new_entry[old_code_length] = *table[new_code]; + //memcpy(new_entry + fOldCodeLength, fTable[fNewCode], 1); + new_entry[fOldCodeLength] = *fTable[fNewCode]; } else { // Does not exist in table - //memcpy(new_entry, old_code, old_code_length); - for (int x = 0; x < old_code_length; x++) { - new_entry[x] = old_code[x]; + //memcpy(new_entry, fOldCode, fOldCodeLength); + for (int x = 0; x < fOldCodeLength; x++) { + new_entry[x] = fOldCode[x]; } - //memcpy(new_entry + old_code_length, old_code, 1); - new_entry[old_code_length] = *old_code; + //memcpy(new_entry + fOldCodeLength, fOldCode, 1); + new_entry[fOldCodeLength] = *fOldCode; - if (!OutputColor(new_entry, old_code_length + 1)) goto bad_end; + if (!OutputColor(new_entry, fOldCodeLength + 1)) goto bad_end; } - table[next_code] = MemblockAllocate(old_code_length + 1); + fTable[fNextCode] = MemblockAllocate(fOldCodeLength + 1); - //memcpy(table[next_code], new_entry, old_code_length + 1); - for (int x = 0; x < old_code_length + 1; x++) { - table[next_code][x] = new_entry[x]; + //memcpy(fTable[fNextCode], new_entry, fOldCodeLength + 1); + for (int x = 0; x < fOldCodeLength + 1; x++) { + fTable[fNextCode][x] = new_entry[x]; } - entry_size[next_code] = old_code_length + 1; + fEntrySize[fNextCode] = fOldCodeLength + 1; - //memcpy(old_code, table[new_code], entry_size[new_code]); - for (int x = 0; x < entry_size[new_code]; x++) { - old_code[x] = table[new_code][x]; + //memcpy(fOldCode, fTable[fNewCode], fEntrySize[fNewCode]); + for (int x = 0; x < fEntrySize[fNewCode]; x++) { + fOldCode[x] = fTable[fNewCode][x]; } - old_code_length = entry_size[new_code]; - next_code++; + fOldCodeLength = fEntrySize[fNewCode]; + fNextCode++; - if (next_code > max_code && BITS != 12) { - BITS++; - max_code = (1 << BITS) - 1; + if (fNextCode > fMaxCode && fBits != 12) { + fBits++; + fMaxCode = (1 << fBits) - 1; } } MemblockDeleteAll(); - if (new_code == -1) return false; + if (fNewCode == -1) return false; if (debug) printf("GIFLoad::ReadGIFImageData() - Done\n"); return true; @@ -332,57 +332,57 @@ } short GIFLoad::NextCode() { - while (bit_count < BITS) { - if (byte_count == 0) { - if (input->Read(&byte_count, 1) < 1) return -1; - if (byte_count == 0) return end_code; - if (input->Read(byte_buffer + (255 - byte_count), byte_count) < byte_count) return -1; + while (fBitCount < fBits) { + if (fByteCount == 0) { + if (fInput->Read(&fByteCount, 1) < 1) return -1; + if (fByteCount == 0) return fEndCode; + if (fInput->Read(fByteBuffer + (255 - fByteCount), fByteCount) < fByteCount) return -1; } - bit_buffer |= (unsigned int)byte_buffer[255 - byte_count] << bit_count; - byte_count--; - bit_count += 8; + fBitBuffer |= (unsigned int)fByteBuffer[255 - fByteCount] << fBitCount; + fByteCount--; + fBitCount += 8; } - short s = bit_buffer & ((1 << BITS) - 1); - bit_buffer >>= BITS; - bit_count -= BITS; + short s = fBitBuffer & ((1 << fBits) - 1); + fBitBuffer >>= fBits; + fBitCount -= fBits; return s; } void GIFLoad::ResetTable() { - BITS = code_size + 1; - next_code = clear_code + 2; - max_code = (1 << BITS) - 1; + fBits = fCodeSize + 1; + fNextCode = fClearCode + 2; + fMaxCode = (1 << fBits) - 1; MemblockDeleteAll(); for (int x = 0; x < 4096; x++) { - table[x] = NULL; - if (x < (1 << code_size)) { - table[x] = MemblockAllocate(1); - table[x][0] = x; - entry_size[x] = 1; + fTable[x] = NULL; + if (x < (1 << fCodeSize)) { + fTable[x] = MemblockAllocate(1); + fTable[x][0] = x; + fEntrySize[x] = 1; } } } bool GIFLoad::InitFrame(int size) { - code_size = size; - if (code_size == 1) code_size++; - BITS = code_size + 1; - clear_code = 1 << code_size; - end_code = clear_code + 1; - next_code = clear_code + 2; - max_code = (1 << BITS) - 1; - pass = 0; - if (interlaced) row = gl_pass_starts_at[0]; - else row = 0; + fCodeSize = size; + if (fCodeSize == 1) fCodeSize++; + fBits = fCodeSize + 1; + fClearCode = 1 << fCodeSize; + fEndCode = fClearCode + 1; + fNextCode = fClearCode + 2; + fMaxCode = (1 << fBits) - 1; + fPass = 0; + if (fInterlaced) fRow = gl_pass_starts_at[0]; + else fRow = 0; - bit_count = 0; - bit_buffer = 0; - byte_count = 0; - old_code_length = 0; - new_code = 0; - scanline_position = 0; + fBitCount = 0; + fBitBuffer = 0; + fByteCount = 0; + fOldCodeLength = 0; + fNewCode = 0; + fScanlinePosition = 0; ResetTable(); return true; @@ -391,14 +391,14 @@ // Do 4k mallocs, keep them in a linked list, do a first fit across them // when a new request comes along uchar *GIFLoad::MemblockAllocate(int size) { - if (head_memblock == NULL) { - head_memblock = new Memblock(); - uchar *value = head_memblock->data; - head_memblock->offset = size; - head_memblock->next = NULL; + if (fHeadMemblock == NULL) { + fHeadMemblock = new Memblock(); + uchar *value = fHeadMemblock->data; + fHeadMemblock->offset = size; + fHeadMemblock->next = NULL; return value; } else { - Memblock *block = head_memblock; + Memblock *block = fHeadMemblock; Memblock *last = NULL; while (block != NULL) { if (4096 - block->offset > size) { @@ -422,14 +422,14 @@ // Delete the linked list void GIFLoad::MemblockDeleteAll() { Memblock *block = NULL; - while (head_memblock != NULL) { - block = head_memblock->next; - delete head_memblock; - head_memblock = block; + while (fHeadMemblock != NULL) { + block = fHeadMemblock->next; + delete fHeadMemblock; + fHeadMemblock = block; } } GIFLoad::~GIFLoad() { - delete palette; + delete fPalette; } Modified: haiku/trunk/src/add-ons/translators/gif/GIFLoad.h =================================================================== --- haiku/trunk/src/add-ons/translators/gif/GIFLoad.h 2008-09-15 08:01:33 UTC (rev 27515) +++ haiku/trunk/src/add-ons/translators/gif/GIFLoad.h 2008-09-15 10:30:45 UTC (rev 27516) @@ -31,7 +31,7 @@ class GIFLoad { public: - GIFLoad(BPositionIO *input, BPositionIO *output); + GIFLoad(BPositionIO *fInput, BPositionIO *fOutput); ~GIFLoad(); bool fatalerror; @@ -53,50 +53,50 @@ void MemblockDeleteAll(); inline bool OutputColor(unsigned char *string, int size) { - int bpr = width << 2; + int bpr = fWidth << 2; for (int x = 0; x < size; x++) { - scanline[scanline_position] = palette->ColorForIndex(string[x]); - scanline_position++; + fScanLine[fScanlinePosition] = fPalette->ColorForIndex(string[x]); + fScanlinePosition++; - if (scanline_position >= width) { - if (output->WriteAt(32 + (row * bpr), scanline, bpr) < bpr) return false; - scanline_position = 0; - if (interlaced) { - row += gl_increment_pass_by[pass]; - while (row >= height) { - pass++; - if (pass > 3) return true; - row = gl_pass_starts_at[pass]; + if (fScanlinePosition >= fWidth) { + if (fOutput->WriteAt(32 + (fRow * bpr), fScanLine, bpr) < bpr) return false; + fScanlinePosition = 0; + if (fInterlaced) { + fRow += gl_increment_pass_by[fPass]; + while (fRow >= fHeight) { + fPass++; + if (fPass > 3) return true; + fRow = gl_pass_starts_at[fPass]; } - } else row++; + } else fRow++; } } return true; } - BPositionIO *input, *output; - LoadPalette *palette; - bool interlaced; - int pass, row, width, height; + BPositionIO *fInput, *fOutput; + LoadPalette *fPalette; + bool fInterlaced; + int fPass, fRow, fWidth, fHeight; - unsigned char old_code[4096]; - int old_code_length; - short new_code; - int BITS, max_code, code_size; - short clear_code, end_code, next_code; + unsigned char fOldCode[4096]; + int fOldCodeLength; + short fNewCode; + int fBits, fMaxCode, fCodeSize; + short fClearCode, fEndCode, fNextCode; - unsigned char *table[4096]; - short entry_size[4096]; - Memblock *head_memblock; + unsigned char *fTable[4096]; + short fEntrySize[4096]; + Memblock *fHeadMemblock; - int bit_count; - unsigned int bit_buffer; - unsigned char byte_count; - unsigned char byte_buffer[255]; + int fBitCount; + unsigned int fBitBuffer; + unsigned char fByteCount; + unsigned char fByteBuffer[255]; - uint32 *scanline; - int scanline_position; + uint32 *fScanLine; + int fScanlinePosition; }; #endif From jackburton at mail.berlios.de Mon Sep 15 12:38:49 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Mon, 15 Sep 2008 12:38:49 +0200 Subject: [Haiku-commits] r27517 - haiku/trunk/src/add-ons/translators/gif Message-ID: <200809151038.m8FAcneU000670@sheep.berlios.de> Author: jackburton Date: 2008-09-15 12:38:46 +0200 (Mon, 15 Sep 2008) New Revision: 27517 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27517&view=rev Modified: haiku/trunk/src/add-ons/translators/gif/GIFLoad.cpp Log: more style changes Modified: haiku/trunk/src/add-ons/translators/gif/GIFLoad.cpp =================================================================== --- haiku/trunk/src/add-ons/translators/gif/GIFLoad.cpp 2008-09-15 10:30:45 UTC (rev 27516) +++ haiku/trunk/src/add-ons/translators/gif/GIFLoad.cpp 2008-09-15 10:38:46 UTC (rev 27517) @@ -22,7 +22,9 @@ extern bool debug; -GIFLoad::GIFLoad(BPositionIO *input, BPositionIO *output) { + +GIFLoad::GIFLoad(BPositionIO *input, BPositionIO *output) +{ fInput = input; fOutput = output; Init(); @@ -90,7 +92,10 @@ if (debug) printf("GIFLoad::GIFLoad() - Done\n"); } -void GIFLoad::Init() { + +void +GIFLoad::Init() +{ fatalerror = false; fScanLine = NULL; fPalette = NULL; @@ -98,7 +103,10 @@ fHeadMemblock = NULL; } -bool GIFLoad::ReadGIFHeader() { + +bool +GIFLoad::ReadGIFHeader() +{ // Standard header unsigned char header[13]; if (fInput->Read(header, 13) < 13) return false; @@ -131,7 +139,10 @@ return true; } -bool GIFLoad::ReadGIFLoopBlock() { + +bool +GIFLoad::ReadGIFLoopBlock() +{ unsigned char length; if (fInput->Read(&length, 1) < 1) return false; fInput->Seek(length, SEEK_CUR); @@ -146,7 +157,10 @@ return true; } -bool GIFLoad::ReadGIFControlBlock() { + +bool +GIFLoad::ReadGIFControlBlock() +{ unsigned char data[6]; if (fInput->Read(data, 6) < 6) return false; if (data[1] & 0x01) { @@ -157,7 +171,10 @@ return true; } -bool GIFLoad::ReadGIFCommentBlock() { + +bool +GIFLoad::ReadGIFCommentBlock() +{ if (debug) printf("GIFLoad::ReadGIFCommentBlock() - Found:\n"); unsigned char length; char comment_data[256]; @@ -171,7 +188,10 @@ return true; } -bool GIFLoad::ReadGIFUnknownBlock(unsigned char c) { + +bool +GIFLoad::ReadGIFUnknownBlock(unsigned char c) +{ if (debug) printf("GIFLoad::ReadGIFUnknownBlock() - Found: %d\n", c); unsigned char length; do { @@ -181,7 +201,10 @@ return true; } -bool GIFLoad::ReadGIFImageHeader() { + +bool +GIFLoad::ReadGIFImageHeader() +{ unsigned char data[9]; if (fInput->Read(data, 9) < 9) return false; @@ -237,7 +260,10 @@ return true; } -bool GIFLoad::ReadGIFImageData() { + +bool +GIFLoad::ReadGIFImageData() +{ unsigned char new_entry[4096]; unsigned char cs; @@ -331,7 +357,10 @@ return false; } -short GIFLoad::NextCode() { + +short +GIFLoad::NextCode() +{ while (fBitCount < fBits) { if (fByteCount == 0) { if (fInput->Read(&fByteCount, 1) < 1) return -1; @@ -349,7 +378,10 @@ return s; } -void GIFLoad::ResetTable() { + +void +GIFLoad::ResetTable() +{ fBits = fCodeSize + 1; fNextCode = fClearCode + 2; fMaxCode = (1 << fBits) - 1; @@ -365,7 +397,10 @@ } } -bool GIFLoad::InitFrame(int size) { + +bool +GIFLoad::InitFrame(int size) +{ fCodeSize = size; if (fCodeSize == 1) fCodeSize++; fBits = fCodeSize + 1; @@ -388,9 +423,12 @@ return true; } + // Do 4k mallocs, keep them in a linked list, do a first fit across them // when a new request comes along -uchar *GIFLoad::MemblockAllocate(int size) { +uchar * +GIFLoad::MemblockAllocate(int size) +{ if (fHeadMemblock == NULL) { fHeadMemblock = new Memblock(); uchar *value = fHeadMemblock->data; @@ -419,8 +457,11 @@ } } + // Delete the linked list -void GIFLoad::MemblockDeleteAll() { +void +GIFLoad::MemblockDeleteAll() +{ Memblock *block = NULL; while (fHeadMemblock != NULL) { block = fHeadMemblock->next; @@ -429,7 +470,9 @@ } } -GIFLoad::~GIFLoad() { + +GIFLoad::~GIFLoad() +{ delete fPalette; } From jackburton at mail.berlios.de Mon Sep 15 12:44:46 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Mon, 15 Sep 2008 12:44:46 +0200 Subject: [Haiku-commits] r27518 - haiku/trunk/src/add-ons/translators/gif Message-ID: <200809151044.m8FAikdP007489@sheep.berlios.de> Author: jackburton Date: 2008-09-15 12:44:43 +0200 (Mon, 15 Sep 2008) New Revision: 27518 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27518&view=rev Modified: haiku/trunk/src/add-ons/translators/gif/GIFLoad.cpp Log: set fScanLine to NULL after freeing it. Modified: haiku/trunk/src/add-ons/translators/gif/GIFLoad.cpp =================================================================== --- haiku/trunk/src/add-ons/translators/gif/GIFLoad.cpp 2008-09-15 10:38:46 UTC (rev 27517) +++ haiku/trunk/src/add-ons/translators/gif/GIFLoad.cpp 2008-09-15 10:44:43 UTC (rev 27518) @@ -49,7 +49,8 @@ } else { if (debug) printf("GIFLoad::GIFLoad() - Found a single image and leaving\n"); } - if (fScanLine != NULL) free(fScanLine); + free(fScanLine); + fScanLine = NULL; return; } else if (c == 0x21) { unsigned char d; From jackburton at mail.berlios.de Mon Sep 15 14:00:56 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Mon, 15 Sep 2008 14:00:56 +0200 Subject: [Haiku-commits] r27519 - haiku/trunk/src/add-ons/translators/gif Message-ID: <200809151200.m8FC0uJp022188@sheep.berlios.de> Author: jackburton Date: 2008-09-15 14:00:52 +0200 (Mon, 15 Sep 2008) New Revision: 27519 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27519&view=rev Modified: haiku/trunk/src/add-ons/translators/gif/GIFLoad.cpp Log: Other small style changes Modified: haiku/trunk/src/add-ons/translators/gif/GIFLoad.cpp =================================================================== --- haiku/trunk/src/add-ons/translators/gif/GIFLoad.cpp 2008-09-15 10:44:43 UTC (rev 27518) +++ haiku/trunk/src/add-ons/translators/gif/GIFLoad.cpp 2008-09-15 12:00:52 UTC (rev 27519) @@ -24,17 +24,23 @@ GIFLoad::GIFLoad(BPositionIO *input, BPositionIO *output) + : + fatalerror(false), + fInput(input), + fOutput(output), + fHeadMemblock(NULL), + fPalette(NULL), + fScanLine(NULL) { - fInput = input; - fOutput = output; - Init(); - + fInput->Seek(0, SEEK_SET); + if (!ReadGIFHeader()) { fatalerror = true; return; } - if (debug) printf("GIFLoad::GIFLoad() - Image dimensions are %d x %d\n", fWidth, fHeight); + if (debug) + printf("GIFLoad::GIFLoad() - Image dimensions are %d x %d\n", fWidth, fHeight); unsigned char c; if (fInput->Read(&c, 1) < 1) { @@ -44,10 +50,12 @@ while (c != 0x3b) { if (c == 0x2c) { if ((!ReadGIFImageHeader()) || (!ReadGIFImageData())) { - if (debug) printf("GIFLoad::GIFLoad() - A fatal error occurred\n"); + if (debug) + printf("GIFLoad::GIFLoad() - A fatal error occurred\n"); fatalerror = true; } else { - if (debug) printf("GIFLoad::GIFLoad() - Found a single image and leaving\n"); + if (debug) + printf("GIFLoad::GIFLoad() - Found a single image and leaving\n"); } free(fScanLine); fScanLine = NULL; @@ -90,21 +98,11 @@ return; } } - if (debug) printf("GIFLoad::GIFLoad() - Done\n"); + if (debug) + printf("GIFLoad::GIFLoad() - Done\n"); } -void -GIFLoad::Init() -{ - fatalerror = false; - fScanLine = NULL; - fPalette = NULL; - fInput->Seek(0, SEEK_SET); - fHeadMemblock = NULL; -} - - bool GIFLoad::ReadGIFHeader() { @@ -118,12 +116,14 @@ // Global palette if (header[10] & 0x80) { fPalette->size_in_bits = (header[10] & 0x07) + 1; - if (debug) printf("GIFLoad::ReadGIFHeader() - Found %d bit global palette\n", fPalette->size_in_bits); + if (debug) + printf("GIFLoad::ReadGIFHeader() - Found %d bit global palette\n", fPalette->size_in_bits); int s = 1 << fPalette->size_in_bits; fPalette->size = s; unsigned char gp[256 * 3]; - if (fInput->Read(gp, s * 3) < s * 3) return false; + if (fInput->Read(gp, s * 3) < s * 3) + return false; for (int x = 0; x < s; x++) { fPalette->SetColor(x, gp[x * 3], gp[x * 3 + 1], gp[x * 3 + 2]); } @@ -163,11 +163,13 @@ GIFLoad::ReadGIFControlBlock() { unsigned char data[6]; - if (fInput->Read(data, 6) < 6) return false; + if (fInput->Read(data, 6) < 6) + return false; if (data[1] & 0x01) { fPalette->usetransparent = true; fPalette->transparentindex = data[4]; - if (debug) printf("GIFLoad::ReadGIFControlBlock() - Transparency active, using palette index %d\n", data[4]); + if (debug) + printf("GIFLoad::ReadGIFControlBlock() - Transparency active, using palette index %d\n", data[4]); } return true; } @@ -180,12 +182,16 @@ unsigned char length; char comment_data[256]; do { - if (fInput->Read(&length, 1) < 1) return false; - if (fInput->Read(comment_data, length) < length) return false; + if (fInput->Read(&length, 1) < 1) + return false; + if (fInput->Read(comment_data, length) < length) + return false; comment_data[length] = 0x00; - if (debug) printf("%s", comment_data); + if (debug) + printf("%s", comment_data); } while (length != 0x00); - if (debug) printf("\n"); + if (debug) + printf("\n"); return true; } @@ -193,10 +199,12 @@ bool GIFLoad::ReadGIFUnknownBlock(unsigned char c) { - if (debug) printf("GIFLoad::ReadGIFUnknownBlock() - Found: %d\n", c); + if (debug) + printf("GIFLoad::ReadGIFUnknownBlock() - Found: %d\n", c); unsigned char length; do { - if (fInput->Read(&length, 1) < 1) return false; + if (fInput->Read(&length, 1) < 1) + return false; fInput->Seek(length, SEEK_CUR); } while (length != 0x00); return true; @@ -207,15 +215,17 @@ GIFLoad::ReadGIFImageHeader() { unsigned char data[9]; - if (fInput->Read(data, 9) < 9) return false; + if (fInput->Read(data, 9) < 9) + return false; - int local_width = data[4] + (data[5] << 8); - int local_height = data[6] + (data[7] << 8); - if (fWidth != local_width || fHeight != local_height) { - if (debug) printf("GIFLoad::ReadGIFImageHeader() - Local dimensions do not match global, setting to %d x %d\n", - local_width, local_height); - fWidth = local_width; - fHeight = local_height; + int localWidth = data[4] + (data[5] << 8); + int localHeight = data[6] + (data[7] << 8); + if (fWidth != localWidth || fHeight != localHeight) { + if (debug) + printf("GIFLoad::ReadGIFImageHeader() - Local dimensions do not match global, setting to %d x %d\n", + localWidth, localHeight); + fWidth = localWidth; + fHeight = localHeight; } fScanLine = (uint32 *)malloc(fWidth * 4); @@ -234,18 +244,21 @@ header.rowBytes = B_HOST_TO_BENDIAN_INT32(fWidth * 4); header.colors = (color_space)B_HOST_TO_BENDIAN_INT32(B_RGBA32); header.dataSize = B_HOST_TO_BENDIAN_INT32(fWidth * 4 * fHeight); - if (fOutput->Write(&header, 32) < 32) return false; + if (fOutput->Write(&header, 32) < 32) + return false; // Has local palette if (data[8] & 0x80) { fPalette->size_in_bits = (data[8] & 0x07) + 1; int s = 1 << fPalette->size_in_bits; fPalette->size = s; - if (debug) printf("GIFLoad::ReadGIFImageHeader() - Found %d bit local palette\n", - fPalette->size_in_bits); + if (debug) + printf("GIFLoad::ReadGIFImageHeader() - Found %d bit local palette\n", + fPalette->size_in_bits); unsigned char lp[256 * 3]; - if (fInput->Read(lp, s * 3) < s * 3) return false; + if (fInput->Read(lp, s * 3) < s * 3) + return false; for (int x = 0; x < s; x++) { fPalette->SetColor(x, lp[x * 3], lp[x * 3 + 1], lp[x * 3 + 2]); } @@ -253,10 +266,12 @@ if (data[8] & 0x40) { fInterlaced = true; - if (debug) printf("GIFLoad::ReadGIFImageHeader() - Image is interlaced\n"); + if (debug) + printf("GIFLoad::ReadGIFImageHeader() - Image is interlaced\n"); } else { fInterlaced = false; - if (debug) printf("GIFLoad::ReadGIFImageHeader() - Image is not interlaced\n"); + if (debug) + printf("GIFLoad::ReadGIFImageHeader() - Image is not interlaced\n"); } return true; } @@ -265,21 +280,26 @@ bool GIFLoad::ReadGIFImageData() { - unsigned char new_entry[4096]; + unsigned char newEntry[4096]; unsigned char cs; fInput->Read(&cs, 1); if (cs == fPalette->size_in_bits) { - if (!InitFrame(fPalette->size_in_bits)) return false; + if (!InitFrame(fPalette->size_in_bits)) + return false; } else if (cs > fPalette->size_in_bits) { - if (debug) printf("GIFLoad::ReadGIFImageData() - Code_size should be %d, not %d, allowing it\n", fCodeSize, cs); - if (!InitFrame(cs)) return false; + if (debug) + printf("GIFLoad::ReadGIFImageData() - Code_size should be %d, not %d, allowing it\n", fCodeSize, cs); + if (!InitFrame(cs)) + return false; } else if (cs < fPalette->size_in_bits) { - if (debug) printf("GIFLoad::ReadGIFImageData() - Code_size should be %d, not %d\n", fCodeSize, cs); + if (debug) + printf("GIFLoad::ReadGIFImageData() - Code_size should be %d, not %d\n", fCodeSize, cs); return false; } - if (debug) printf("GIFLoad::ReadGIFImageData() - Starting LZW\n"); + if (debug) + printf("GIFLoad::ReadGIFImageData() - Starting LZW\n"); while ((fNewCode = NextCode()) != -1 && fNewCode != fEndCode) { if (fNewCode == fClearCode) { @@ -289,7 +309,8 @@ fOldCodeLength = 1; if (!OutputColor(fOldCode, 1)) goto bad_end; if (fNewCode == -1 || fNewCode == fEndCode) { - if (debug) printf("GIFLoad::ReadGIFImageData() - Premature fEndCode or error\n"); + if (debug) + printf("GIFLoad::ReadGIFImageData() - Premature fEndCode or error\n"); goto bad_end; } continue; @@ -299,36 +320,39 @@ if (fOldCodeLength == 0) { fOldCode[0] = fNewCode; fOldCodeLength = 1; - if (!OutputColor(fOldCode, 1)) goto bad_end; + if (!OutputColor(fOldCode, 1)) + goto bad_end; continue; } if (fTable[fNewCode] != NULL) { // Does exist in table - if (!OutputColor(fTable[fNewCode], fEntrySize[fNewCode])) goto bad_end; + if (!OutputColor(fTable[fNewCode], fEntrySize[fNewCode])) + goto bad_end; - //memcpy(new_entry, fOldCode, fOldCodeLength); + //memcpy(newEntry, fOldCode, fOldCodeLength); for (int x = 0; x < fOldCodeLength; x++) { - new_entry[x] = fOldCode[x]; + newEntry[x] = fOldCode[x]; } - //memcpy(new_entry + fOldCodeLength, fTable[fNewCode], 1); - new_entry[fOldCodeLength] = *fTable[fNewCode]; + //memcpy(newEntry + fOldCodeLength, fTable[fNewCode], 1); + newEntry[fOldCodeLength] = *fTable[fNewCode]; } else { // Does not exist in table - //memcpy(new_entry, fOldCode, fOldCodeLength); + //memcpy(newEntry, fOldCode, fOldCodeLength); for (int x = 0; x < fOldCodeLength; x++) { - new_entry[x] = fOldCode[x]; + newEntry[x] = fOldCode[x]; } - //memcpy(new_entry + fOldCodeLength, fOldCode, 1); - new_entry[fOldCodeLength] = *fOldCode; + //memcpy(newEntry + fOldCodeLength, fOldCode, 1); + newEntry[fOldCodeLength] = *fOldCode; - if (!OutputColor(new_entry, fOldCodeLength + 1)) goto bad_end; + if (!OutputColor(newEntry, fOldCodeLength + 1)) + goto bad_end; } fTable[fNextCode] = MemblockAllocate(fOldCodeLength + 1); - //memcpy(fTable[fNextCode], new_entry, fOldCodeLength + 1); + //memcpy(fTable[fNextCode], newEntry, fOldCodeLength + 1); for (int x = 0; x < fOldCodeLength + 1; x++) { - fTable[fNextCode][x] = new_entry[x]; + fTable[fNextCode][x] = newEntry[x]; } fEntrySize[fNextCode] = fOldCodeLength + 1; @@ -348,12 +372,15 @@ } MemblockDeleteAll(); - if (fNewCode == -1) return false; - if (debug) printf("GIFLoad::ReadGIFImageData() - Done\n"); + if (fNewCode == -1) + return false; + if (debug) + printf("GIFLoad::ReadGIFImageData() - Done\n"); return true; bad_end: - if (debug) printf("GIFLoad::ReadGIFImageData() - Reached a bad end\n"); + if (debug) + printf("GIFLoad::ReadGIFImageData() - Reached a bad end\n"); MemblockDeleteAll(); return false; } @@ -403,15 +430,18 @@ GIFLoad::InitFrame(int size) { fCodeSize = size; - if (fCodeSize == 1) fCodeSize++; + if (fCodeSize == 1) + fCodeSize++; fBits = fCodeSize + 1; fClearCode = 1 << fCodeSize; fEndCode = fClearCode + 1; fNextCode = fClearCode + 2; fMaxCode = (1 << fBits) - 1; fPass = 0; - if (fInterlaced) fRow = gl_pass_starts_at[0]; - else fRow = 0; + if (fInterlaced) + fRow = gl_pass_starts_at[0]; + else + fRow = 0; fBitCount = 0; fBitBuffer = 0; From jackburton at mail.berlios.de Mon Sep 15 14:04:36 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Mon, 15 Sep 2008 14:04:36 +0200 Subject: [Haiku-commits] r27520 - haiku/trunk/src/add-ons/translators/gif Message-ID: <200809151204.m8FC4awB022437@sheep.berlios.de> Author: jackburton Date: 2008-09-15 14:04:34 +0200 (Mon, 15 Sep 2008) New Revision: 27520 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27520&view=rev Modified: haiku/trunk/src/add-ons/translators/gif/GIFLoad.h Log: this was supposed to be part of the previous commit Modified: haiku/trunk/src/add-ons/translators/gif/GIFLoad.h =================================================================== --- haiku/trunk/src/add-ons/translators/gif/GIFLoad.h 2008-09-15 12:00:52 UTC (rev 27519) +++ haiku/trunk/src/add-ons/translators/gif/GIFLoad.h 2008-09-15 12:04:34 UTC (rev 27520) @@ -44,7 +44,6 @@ bool ReadGIFCommentBlock(); bool ReadGIFUnknownBlock(unsigned char c); - void Init(); bool InitFrame(int size); short NextCode(); void ResetTable(); From jackburton at mail.berlios.de Mon Sep 15 14:11:59 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Mon, 15 Sep 2008 14:11:59 +0200 Subject: [Haiku-commits] r27521 - haiku/trunk/src/kits/textencoding Message-ID: <200809151211.m8FCBxYD023023@sheep.berlios.de> Author: jackburton Date: 2008-09-15 14:11:58 +0200 (Mon, 15 Sep 2008) New Revision: 27521 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27521&view=rev Modified: haiku/trunk/src/kits/textencoding/utf8_conversions.cpp Log: delete -> delete[]. CID 121 Modified: haiku/trunk/src/kits/textencoding/utf8_conversions.cpp =================================================================== --- haiku/trunk/src/kits/textencoding/utf8_conversions.cpp 2008-09-15 12:04:34 UTC (rev 27520) +++ haiku/trunk/src/kits/textencoding/utf8_conversions.cpp 2008-09-15 12:11:58 UTC (rev 27521) @@ -95,7 +95,7 @@ &outputLeft); iconv_close(iso8859_1to); } - delete original; + delete[] original; break; } From jackburton at mail.berlios.de Mon Sep 15 14:15:57 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Mon, 15 Sep 2008 14:15:57 +0200 Subject: [Haiku-commits] r27522 - haiku/trunk/src/kits/tracker Message-ID: <200809151215.m8FCFvqN023245@sheep.berlios.de> Author: jackburton Date: 2008-09-15 14:15:54 +0200 (Mon, 15 Sep 2008) New Revision: 27522 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27522&view=rev Modified: haiku/trunk/src/kits/tracker/AttributeStream.cpp Log: delete -> delete[]. CID 151 Modified: haiku/trunk/src/kits/tracker/AttributeStream.cpp =================================================================== --- haiku/trunk/src/kits/tracker/AttributeStream.cpp 2008-09-15 12:11:58 UTC (rev 27521) +++ haiku/trunk/src/kits/tracker/AttributeStream.cpp 2008-09-15 12:15:54 UTC (rev 27522) @@ -456,7 +456,7 @@ { char *newBuffer = new char[size]; if (!fReadFrom->Fill(newBuffer)) { - delete newBuffer; + delete[] newBuffer; return NULL; } From jackburton at mail.berlios.de Mon Sep 15 14:19:33 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Mon, 15 Sep 2008 14:19:33 +0200 Subject: [Haiku-commits] r27523 - haiku/trunk/src/add-ons/mail_daemon/inbound_protocols/pop3 Message-ID: <200809151219.m8FCJXA3023331@sheep.berlios.de> Author: jackburton Date: 2008-09-15 14:19:31 +0200 (Mon, 15 Sep 2008) New Revision: 27523 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27523&view=rev Modified: haiku/trunk/src/add-ons/mail_daemon/inbound_protocols/pop3/SimpleMailProtocol.cpp Log: delete -> delete[]. CID 141 Modified: haiku/trunk/src/add-ons/mail_daemon/inbound_protocols/pop3/SimpleMailProtocol.cpp =================================================================== --- haiku/trunk/src/add-ons/mail_daemon/inbound_protocols/pop3/SimpleMailProtocol.cpp 2008-09-15 12:15:54 UTC (rev 27522) +++ haiku/trunk/src/add-ons/mail_daemon/inbound_protocols/pop3/SimpleMailProtocol.cpp 2008-09-15 12:19:31 UTC (rev 27523) @@ -43,7 +43,7 @@ password = passwd; error = Login(settings->FindString("username"), password, settings->FindInt32("auth_method")); - delete passwd; + delete[] passwd; if (error < B_OK) { runner->Stop(); From jackburton at mail.berlios.de Mon Sep 15 14:26:45 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Mon, 15 Sep 2008 14:26:45 +0200 Subject: [Haiku-commits] r27524 - haiku/trunk/src/servers/app Message-ID: <200809151226.m8FCQjjY024057@sheep.berlios.de> Author: jackburton Date: 2008-09-15 14:26:43 +0200 (Mon, 15 Sep 2008) New Revision: 27524 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27524&view=rev Modified: haiku/trunk/src/servers/app/FontManager.cpp Log: cleanup and return in error case, otherwise a stale style pointer could be added to the family. CID 1246 Modified: haiku/trunk/src/servers/app/FontManager.cpp =================================================================== --- haiku/trunk/src/servers/app/FontManager.cpp 2008-09-15 12:19:31 UTC (rev 27523) +++ haiku/trunk/src/servers/app/FontManager.cpp 2008-09-15 12:26:43 UTC (rev 27524) @@ -541,7 +541,7 @@ if (error != 0) return B_ERROR; - FontFamily *family = _FindFamily(face->family_name); + FontFamily *family = _FindFamily(face->family_name); if (family != NULL && family->HasStyle(face->style_name)) { // prevent adding the same style twice // (this indicates a problem with the installed fonts maybe?) @@ -562,9 +562,12 @@ FTRACE(("\tadd style: %s, %s\n", face->family_name, face->style_name)); // the FontStyle takes over ownership of the FT_Face object - FontStyle *style = new FontStyle(nodeRef, path.Path(), face); - if (!family->AddStyle(style)) + FontStyle *style = new FontStyle(nodeRef, path.Path(), face); + if (!family->AddStyle(style)) { delete style; + delete family; + return B_NO_MEMORY; + } directory.styles.AddItem(style); fStyleHashTable.AddItem(style); From jackburton at mail.berlios.de Mon Sep 15 14:44:08 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Mon, 15 Sep 2008 14:44:08 +0200 Subject: [Haiku-commits] r27525 - haiku/trunk/src/apps/deskbar Message-ID: <200809151244.m8FCi8fq025386@sheep.berlios.de> Author: jackburton Date: 2008-09-15 14:44:07 +0200 (Mon, 15 Sep 2008) New Revision: 27525 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27525&view=rev Modified: haiku/trunk/src/apps/deskbar/StatusView.cpp Log: moved the NULL check before dereferencing the view pointer. CID 1063 Modified: haiku/trunk/src/apps/deskbar/StatusView.cpp =================================================================== --- haiku/trunk/src/apps/deskbar/StatusView.cpp 2008-09-15 12:26:43 UTC (rev 27524) +++ haiku/trunk/src/apps/deskbar/StatusView.cpp 2008-09-15 12:44:07 UTC (rev 27525) @@ -1365,9 +1365,10 @@ BView *view = NULL; for (int32 i = startIndex ; i < count ; i++){ fShelf->ReplicantAt(i, &view); - BPoint loc = LocationForReplicant(i, view->Frame().Width()); - if (view && (view->Frame().LeftTop() != loc)) { - view->MoveTo(loc); + if (view != NULL) { + BPoint loc = LocationForReplicant(i, view->Frame().Width()); + if (view->Frame().LeftTop() != loc) + view->MoveTo(loc); } } } From bonefish at mail.berlios.de Mon Sep 15 14:48:00 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Mon, 15 Sep 2008 14:48:00 +0200 Subject: [Haiku-commits] r27526 - in haiku/trunk: headers/private/debug src/kits/debug Message-ID: <200809151248.m8FCm0oT025926@sheep.berlios.de> Author: bonefish Date: 2008-09-15 14:47:59 +0200 (Mon, 15 Sep 2008) New Revision: 27526 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27526&view=rev Modified: haiku/trunk/headers/private/debug/debug_support.h haiku/trunk/src/kits/debug/SymbolLookup.cpp haiku/trunk/src/kits/debug/SymbolLookup.h haiku/trunk/src/kits/debug/debug_support.cpp Log: Added functionality for iterating through the symbols of a debugged team's image to libdebug. Modified: haiku/trunk/headers/private/debug/debug_support.h =================================================================== --- haiku/trunk/headers/private/debug/debug_support.h 2008-09-15 12:44:07 UTC (rev 27525) +++ haiku/trunk/headers/private/debug/debug_support.h 2008-09-15 12:47:59 UTC (rev 27526) @@ -55,6 +55,7 @@ // symbol lookup support typedef struct debug_symbol_lookup_context debug_symbol_lookup_context; +typedef struct debug_symbol_iterator debug_symbol_iterator; status_t debug_create_symbol_lookup_context(debug_context *debugContext, debug_symbol_lookup_context **lookupContext); @@ -66,7 +67,15 @@ int32 symbolNameSize, char *imageName, int32 imageNameSize, bool *exactMatch); +status_t debug_create_image_symbol_iterator( + debug_symbol_lookup_context* lookupContext, image_id imageID, + debug_symbol_iterator** _iterator); +void debug_delete_image_symbol_iterator(debug_symbol_iterator* iterator); +status_t debug_next_image_symbol(debug_symbol_iterator* iterator, + char* nameBuffer, size_t nameBufferLength, int32* _symbolType, + void** _symbolLocation, size_t* _symbolSize); + #ifdef __cplusplus } // extern "C" #endif Modified: haiku/trunk/src/kits/debug/SymbolLookup.cpp =================================================================== --- haiku/trunk/src/kits/debug/SymbolLookup.cpp 2008-09-15 12:44:07 UTC (rev 27525) +++ haiku/trunk/src/kits/debug/SymbolLookup.cpp 2008-09-15 12:47:59 UTC (rev 27526) @@ -1,5 +1,5 @@ /* - * Copyright 2005, Ingo Weinhold, bonefish at users.sf.net. + * Copyright 2005-2008, Ingo Weinhold, ingo_weinhold at gmx.de. * Distributed under the terms of the MIT License. */ @@ -278,6 +278,55 @@ return B_OK; } + +// InitSymbolIterator +status_t +SymbolLookup::InitSymbolIterator(image_id imageID, SymbolIterator& iterator) +{ + // find the image + const image_t* image = _FindImageByID(imageID); + if (image == NULL) + return B_ENTRY_NOT_FOUND; + + iterator.image = image; + iterator.symbolCount = Read(image->symhash[1]); + iterator.textDelta = image->regions->delta; + iterator.currentIndex = -1; + + return B_OK; +} + + +// NextSymbol +status_t +SymbolLookup::NextSymbol(SymbolIterator& iterator, const char** _symbolName, + addr_t* _symbolAddress, size_t* _symbolSize, int32* _symbolType) +{ + const image_t* image = iterator.image; + + while (true) { + if (++iterator.currentIndex >= iterator.symbolCount) + return B_ENTRY_NOT_FOUND; + + const struct Elf32_Sym* symbol = &Read(image->syms[ + iterator.currentIndex]); + if ((ELF32_ST_TYPE(symbol->st_info) != STT_FUNC + && ELF32_ST_TYPE(symbol->st_info) != STT_OBJECT) + || symbol->st_value == 0) { + continue; + } + + *_symbolName = SYMNAME(image, symbol); + *_symbolAddress = symbol->st_value + iterator.textDelta; + *_symbolSize = symbol->st_size; + *_symbolType = ELF32_ST_TYPE(symbol->st_info) == STT_FUNC + ? B_SYMBOL_TYPE_TEXT : B_SYMBOL_TYPE_DATA; + + return B_OK; + } +} + + // _FindImageAtAddress const image_t * SymbolLookup::_FindImageAtAddress(addr_t address) @@ -297,3 +346,18 @@ return NULL; } + +// _FindImageByID +const image_t* +SymbolLookup::_FindImageByID(image_id id) +{ + // iterate through the images + for (const image_t *image = &Read(*Read(fDebugArea->loaded_images->head)); + image; + image = &Read(*image->next)) { + if (image->id == id) + return image; + } + + return NULL; +} Modified: haiku/trunk/src/kits/debug/SymbolLookup.h =================================================================== --- haiku/trunk/src/kits/debug/SymbolLookup.h 2008-09-15 12:44:07 UTC (rev 27525) +++ haiku/trunk/src/kits/debug/SymbolLookup.h 2008-09-15 12:47:59 UTC (rev 27526) @@ -1,5 +1,5 @@ /* - * Copyright 2005, Ingo Weinhold, bonefish at users.sf.net. + * Copyright 2005-2008, Ingo Weinhold, ingo_weinhold at gmx.de. * Distributed under the terms of the MIT License. */ @@ -8,10 +8,12 @@ #include +#include #include #include + //#define TRACE_DEBUG_SYMBOL_LOOKUP #ifdef TRACE_DEBUG_SYMBOL_LOOKUP # define TRACE(x) printf x @@ -19,9 +21,11 @@ # define TRACE(x) ; #endif + struct image_t; struct runtime_loader_debug_area; + namespace BPrivate { // Exception @@ -43,6 +47,7 @@ status_t fError; }; + // Area class Area : public DoublyLinkedListLinkImpl { public: @@ -81,6 +86,7 @@ int32 fSize; }; + // RemoteMemoryAccessor class RemoteMemoryAccessor { public: @@ -111,6 +117,16 @@ AreaList fAreas; }; + +// SymbolIterator +struct SymbolIterator { + const image_t* image; + int32 symbolCount; + size_t textDelta; + int32 currentIndex; +}; + + // SymbolLookup class SymbolLookup : private RemoteMemoryAccessor { public: @@ -122,8 +138,13 @@ status_t LookupSymbolAddress(addr_t address, addr_t *_baseAddress, const char **_symbolName, const char **_imageName, bool *_exactMatch); + status_t InitSymbolIterator(image_id imageID, SymbolIterator& iterator); + status_t NextSymbol(SymbolIterator& iterator, const char** _symbolName, + addr_t* _symbolAddress, size_t* _symbolSize, int32* _symbolType); + private: const image_t *_FindImageAtAddress(addr_t address); + const image_t *_FindImageByID(image_id id); const runtime_loader_debug_area *fDebugArea; }; Modified: haiku/trunk/src/kits/debug/debug_support.cpp =================================================================== --- haiku/trunk/src/kits/debug/debug_support.cpp 2008-09-15 12:44:07 UTC (rev 27525) +++ haiku/trunk/src/kits/debug/debug_support.cpp 2008-09-15 12:47:59 UTC (rev 27526) @@ -1,5 +1,5 @@ /* - * Copyright 2005, Ingo Weinhold, bonefish at users.sf.net. + * Copyright 2005-2008, Ingo Weinhold, ingo_weinhold at gmx.de. * Distributed under the terms of the MIT License. */ @@ -13,14 +13,20 @@ #include "arch_debug_support.h" #include "SymbolLookup.h" + using std::nothrow; + struct debug_symbol_lookup_context { debug_context context; SymbolLookup *lookup; }; +struct debug_symbol_iterator : BPrivate::SymbolIterator { + debug_symbol_lookup_context* lookup_context; +}; + // init_debug_context status_t init_debug_context(debug_context *context, team_id team, port_id nubPort) @@ -317,8 +323,8 @@ const char *_symbolName; const char *_imageName; try { - status_t error = lookup->LookupSymbolAddress((addr_t)address, &_baseAddress, - &_symbolName, &_imageName, exactMatch); + status_t error = lookup->LookupSymbolAddress((addr_t)address, + &_baseAddress, &_symbolName, &_imageName, exactMatch); if (error != B_OK) return error; } catch (BPrivate::Exception exception) { @@ -351,3 +357,83 @@ return B_OK; } + + +status_t +debug_create_image_symbol_iterator(debug_symbol_lookup_context* lookupContext, + image_id imageID, debug_symbol_iterator** _iterator) +{ + if (!lookupContext || !lookupContext->lookup) + return B_BAD_VALUE; + SymbolLookup *lookup = lookupContext->lookup; + + debug_symbol_iterator* iterator = new(std::nothrow) debug_symbol_iterator; + if (iterator == NULL) + return B_NO_MEMORY; + + status_t error; + try { + error = lookup->InitSymbolIterator(imageID, *iterator); + } catch (BPrivate::Exception exception) { + error = exception.Error(); + } + + if (error != B_OK) { + delete iterator; + return error; + } + + iterator->lookup_context = lookupContext; + + *_iterator = iterator; + return B_OK; +} + + +void +debug_delete_image_symbol_iterator(debug_symbol_iterator* iterator) +{ + delete iterator; +} + + +// debug_next_image_symbol +status_t +debug_next_image_symbol(debug_symbol_iterator* iterator, char* nameBuffer, + size_t nameBufferLength, int32* _symbolType, void** _symbolLocation, + size_t* _symbolSize) +{ + if (iterator == NULL || iterator->lookup_context == NULL + || iterator->lookup_context->lookup == NULL) { + return B_BAD_VALUE; + } + debug_symbol_lookup_context* lookupContext = iterator->lookup_context; + + const char* symbolName; + addr_t symbolLocation; + + try { + status_t error = lookupContext->lookup->NextSymbol( + *iterator, &symbolName, &symbolLocation, _symbolSize, _symbolType); + if (error != B_OK) + return error; + } catch (BPrivate::Exception exception) { + return exception.Error(); + } + + *_symbolLocation = (void*)symbolLocation; + + // symbolName is a remote address: We read the string from the + // remote memory. The reason for not using the cloned area is that + // we don't trust that the data therein is valid (i.e. null-terminated) + // and thus strlcpy() could segfault when hitting the cloned area end. + if (symbolName != NULL) { + ssize_t sizeRead = debug_read_string(&lookupContext->context, + symbolName, nameBuffer, nameBufferLength); + if (sizeRead < 0) + return sizeRead; + } else + nameBuffer[0] = '\0'; + + return B_OK; +} From bonefish at mail.berlios.de Mon Sep 15 14:59:50 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Mon, 15 Sep 2008 14:59:50 +0200 Subject: [Haiku-commits] r27527 - in haiku/trunk: headers/private/kernel src/system/kernel Message-ID: <200809151259.m8FCxo6L026717@sheep.berlios.de> Author: bonefish Date: 2008-09-15 14:59:49 +0200 (Mon, 15 Sep 2008) New Revision: 27527 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27527&view=rev Modified: haiku/trunk/headers/private/kernel/port.h haiku/trunk/src/system/kernel/port.cpp Log: Added (kernel private) B_PEEK_PORT_MESSAGE flag for read_port_etc(). When specified, the message is read but not removed from the port. Modified: haiku/trunk/headers/private/kernel/port.h =================================================================== --- haiku/trunk/headers/private/kernel/port.h 2008-09-15 12:47:59 UTC (rev 27526) +++ haiku/trunk/headers/private/kernel/port.h 2008-09-15 12:59:49 UTC (rev 27527) @@ -15,6 +15,14 @@ #define PORT_FLAG_USE_USER_MEMCPY 0x80000000 +// port flags +enum { + // read_port_etc() flags + B_PEEK_PORT_MESSAGE = 0x100 // read the message, but don't remove it; + // kernel-only; memory must be locked +}; + + #ifdef __cplusplus extern "C" { #endif @@ -29,7 +37,8 @@ // currently private API status_t writev_port_etc(port_id id, int32 msgCode, const iovec *msgVecs, - size_t vecCount, size_t bufferSize, uint32 flags, bigtime_t timeout); + size_t vecCount, size_t bufferSize, uint32 flags, + bigtime_t timeout); // temp: test void port_test(void); Modified: haiku/trunk/src/system/kernel/port.cpp =================================================================== --- haiku/trunk/src/system/kernel/port.cpp 2008-09-15 12:47:59 UTC (rev 27526) +++ haiku/trunk/src/system/kernel/port.cpp 2008-09-15 12:59:49 UTC (rev 27527) @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -369,7 +370,7 @@ // #pragma mark - public kernel API -port_id +port_id create_port(int32 queueLength, const char *name) { cpu_status state; @@ -575,7 +576,7 @@ RELEASE_PORT_LOCK(sPorts[slot]); - // update the first free slot hint in the array + // update the first free slot hint in the array GRAB_PORT_LIST_LOCK(); if (slot < sFirstFreeSlot) sFirstFreeSlot = slot; @@ -959,7 +960,8 @@ cpu_status state; sem_id cachedSem; status_t status; - bool userCopy = (flags & PORT_FLAG_USE_USER_MEMCPY) > 0; + bool userCopy = (flags & PORT_FLAG_USE_USER_MEMCPY) != 0; + bool peekOnly = !userCopy && (flags & B_PEEK_PORT_MESSAGE) != 0; port_msg *msg; size_t size; int slot; @@ -1024,6 +1026,19 @@ return B_BAD_PORT_ID; } + if (peekOnly) { + size = min_c(bufferSize, msg->size); + if (_msgCode != NULL) + *_msgCode = msg->code; + if (size > 0) + cbuf_memcpy_from_chain(msgBuffer, msg->buffer_chain, 0, size); + RELEASE_PORT_LOCK(sPorts[slot]); + restore_interrupts(state); + release_sem_etc(cachedSem, 1, B_DO_NOT_RESCHEDULE); + // we only peeked, but didn't grab the message + return size; + } + list_remove_link(msg); sPorts[slot].total_count++; @@ -1122,7 +1137,7 @@ return B_BAD_PORT_ID; } - // store sem_id in local variable + // store sem_id in local variable cachedSem = sPorts[slot].write_sem; RELEASE_PORT_LOCK(sPorts[slot]); @@ -1204,7 +1219,7 @@ notify_port_select_events(slot, B_EVENT_READ); - // store sem_id in local variable + // store sem_id in local variable cachedSem = sPorts[slot].read_sem; RELEASE_PORT_LOCK(sPorts[slot]); From jackburton at mail.berlios.de Mon Sep 15 15:02:41 2008 From: jackburton at mail.berlios.de (jackburton at mail.berlios.de) Date: Mon, 15 Sep 2008 15:02:41 +0200 Subject: [Haiku-commits] r27528 - haiku/trunk/src/add-ons/translators/gif Message-ID: <200809151302.m8FD2fr7027129@sheep.berlios.de> Author: jackburton Date: 2008-09-15 15:02:39 +0200 (Mon, 15 Sep 2008) New Revision: 27528 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27528&view=rev Modified: haiku/trunk/src/add-ons/translators/gif/GIFTranslator.cpp Log: simplified this weird code, while also fixing CID 1059 Modified: haiku/trunk/src/add-ons/translators/gif/GIFTranslator.cpp =================================================================== --- haiku/trunk/src/add-ons/translators/gif/GIFTranslator.cpp 2008-09-15 12:59:49 UTC (rev 27527) +++ haiku/trunk/src/add-ons/translators/gif/GIFTranslator.cpp 2008-09-15 13:02:39 UTC (rev 27528) @@ -186,20 +186,18 @@ bigtime_t now = system_time(); // Going from BBitmap to GIF if (!is_gif) { - BBitmap **b = (BBitmap **)malloc(4); - *b = NULL; - err = GetBitmap(inSource, b); - if (err != B_OK) return err; - GIFSave *gs = new GIFSave(*b, outDestination); + BBitmap *bitmap = NULL; + err = GetBitmap(inSource, &bitmap); + if (err != B_OK) + return err; + GIFSave *gs = new GIFSave(bitmap, outDestination); if (gs->fatalerror) { delete gs; - if (*b != NULL) delete *b; - delete b; + delete bitmap; return B_NO_MEMORY; } delete gs; - delete *b; - delete b; + delete bitmap; } else { // GIF to BBitmap GIFLoad *gl = new GIFLoad(inSource, outDestination); if (gl->fatalerror) { From bonefish at mail.berlios.de Mon Sep 15 15:09:15 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Mon, 15 Sep 2008 15:09:15 +0200 Subject: [Haiku-commits] r27529 - in haiku/trunk: headers/private/kernel/arch src/system/kernel src/system/kernel/arch/m68k src/system/kernel/arch/ppc src/system/kernel/arch/x86 src/system/kernel/debug src/system/kernel/device_manager Message-ID: <200809151309.m8FD9F6F027454@sheep.berlios.de> Author: bonefish Date: 2008-09-15 15:09:14 +0200 (Mon, 15 Sep 2008) New Revision: 27529 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27529&view=rev Modified: haiku/trunk/headers/private/kernel/arch/debug.h haiku/trunk/src/system/kernel/arch/m68k/arch_debug.cpp haiku/trunk/src/system/kernel/arch/ppc/arch_debug.cpp haiku/trunk/src/system/kernel/arch/x86/arch_debug.cpp haiku/trunk/src/system/kernel/debug/tracing.cpp haiku/trunk/src/system/kernel/device_manager/io_requests.cpp haiku/trunk/src/system/kernel/heap.cpp Log: Added new parameter "skipIframes" to arch_debug_get_stack_trace(). That many iframes are supposed to be skipped before recording the stack trace. Currently implemented for x86 only. Modified: haiku/trunk/headers/private/kernel/arch/debug.h =================================================================== --- haiku/trunk/headers/private/kernel/arch/debug.h 2008-09-15 13:02:39 UTC (rev 27528) +++ haiku/trunk/headers/private/kernel/arch/debug.h 2008-09-15 13:09:14 UTC (rev 27529) @@ -22,7 +22,7 @@ status_t arch_debug_init(kernel_args *args); void *arch_debug_get_caller(void); int32 arch_debug_get_stack_trace(addr_t* returnAddresses, int32 maxCount, - int32 skipFrames, bool userOnly); + int32 skipIframes, int32 skipFrames, bool userOnly); void *arch_debug_get_interrupt_pc(); bool arch_debug_contains_call(struct thread *thread, const char *symbol, addr_t start, addr_t end); Modified: haiku/trunk/src/system/kernel/arch/m68k/arch_debug.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/m68k/arch_debug.cpp 2008-09-15 13:02:39 UTC (rev 27528) +++ haiku/trunk/src/system/kernel/arch/m68k/arch_debug.cpp 2008-09-15 13:09:14 UTC (rev 27529) @@ -286,8 +286,9 @@ int32 arch_debug_get_stack_trace(addr_t* returnAddresses, int32 maxCount, - int32 skipFrames, bool userOnly) + int32 skipIframes, int32 skipFrames, bool userOnly) { +// TODO: Support skipIframes! struct iframe_stack *frameStack; addr_t framePointer; int32 count = 0; Modified: haiku/trunk/src/system/kernel/arch/ppc/arch_debug.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/ppc/arch_debug.cpp 2008-09-15 13:02:39 UTC (rev 27528) +++ haiku/trunk/src/system/kernel/arch/ppc/arch_debug.cpp 2008-09-15 13:09:14 UTC (rev 27529) @@ -286,6 +286,15 @@ } +int32 +arch_debug_get_stack_trace(addr_t* returnAddresses, int32 maxCount, + int32 skipIframes, int32 skipFrames, bool userOnly) +{ + // TODO: Implement! + return 0; +} + + void* arch_debug_get_interrupt_pc() { Modified: haiku/trunk/src/system/kernel/arch/x86/arch_debug.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/arch_debug.cpp 2008-09-15 13:02:39 UTC (rev 27528) +++ haiku/trunk/src/system/kernel/arch/x86/arch_debug.cpp 2008-09-15 13:09:14 UTC (rev 27529) @@ -746,12 +746,27 @@ } +/*! Captures a stack trace (the return addresses) of the current thread. + \param returnAddresses The array the return address shall be written to. + \param maxCount The maximum number of return addresses to be captured. + \param skipIframes The number of interrupt frames that shall be skipped. If + greater than 0, \a skipFrames is ignored. + \param skipFrames The number of stack frames that shall be skipped. + \param userOnly If \c true, only userland return addresses are captured. + \return The number of return addresses written to the given array. +*/ int32 arch_debug_get_stack_trace(addr_t* returnAddresses, int32 maxCount, - int32 skipFrames, bool userOnly) + int32 skipIframes, int32 skipFrames, bool userOnly) { - // always skip our own frame - skipFrames++; + // Keep skipping normal stack frames until we've skipped the iframes we're + // supposed to skip. + if (skipIframes > 0) { + skipFrames = INT_MAX; + } else { + // always skip our own frame + skipFrames++; + } struct thread* thread = thread_get_current_thread(); int32 count = 0; @@ -769,6 +784,11 @@ struct iframe *frame = (struct iframe*)ebp; eip = frame->eip; nextEbp = frame->ebp; + + if (skipIframes > 0) { + if (--skipIframes == 0) + skipFrames = 1; + } } else { if (get_next_frame(ebp, &nextEbp, &eip) != B_OK) break; Modified: haiku/trunk/src/system/kernel/debug/tracing.cpp =================================================================== --- haiku/trunk/src/system/kernel/debug/tracing.cpp 2008-09-15 13:02:39 UTC (rev 27528) +++ haiku/trunk/src/system/kernel/debug/tracing.cpp 2008-09-15 13:09:14 UTC (rev 27529) @@ -1158,7 +1158,8 @@ if (stackTrace != NULL) { stackTrace->depth = arch_debug_get_stack_trace( - stackTrace->return_addresses, maxCount, skipFrames + 1, userOnly); + stackTrace->return_addresses, maxCount, 0, skipFrames + 1, + userOnly); } return stackTrace; Modified: haiku/trunk/src/system/kernel/device_manager/io_requests.cpp =================================================================== --- haiku/trunk/src/system/kernel/device_manager/io_requests.cpp 2008-09-15 13:02:39 UTC (rev 27528) +++ haiku/trunk/src/system/kernel/device_manager/io_requests.cpp 2008-09-15 13:09:14 UTC (rev 27529) @@ -1224,7 +1224,7 @@ // this makes certain assumptions about how the code for the functions // ends up in the kernel object. addr_t returnAddresses[5]; - int32 depth = arch_debug_get_stack_trace(returnAddresses, 5, 1, false); + int32 depth = arch_debug_get_stack_trace(returnAddresses, 5, 0, 1, false); // find the first return address inside the VIP allocator int32 i = 0; Modified: haiku/trunk/src/system/kernel/heap.cpp =================================================================== --- haiku/trunk/src/system/kernel/heap.cpp 2008-09-15 13:02:39 UTC (rev 27528) +++ haiku/trunk/src/system/kernel/heap.cpp 2008-09-15 13:09:14 UTC (rev 27529) @@ -267,7 +267,7 @@ // this makes certain assumptions about how the code for the functions // ends up in the kernel object. addr_t returnAddresses[5]; - int32 depth = arch_debug_get_stack_trace(returnAddresses, 5, 1, false); + int32 depth = arch_debug_get_stack_trace(returnAddresses, 5, 0, 1, false); for (int32 i = 0; i < depth; i++) { if (returnAddresses[i] < (addr_t)&get_caller || returnAddresses[i] > (addr_t)&malloc_referenced_release) { From bonefish at mail.berlios.de Mon Sep 15 15:18:12 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Mon, 15 Sep 2008 15:18:12 +0200 Subject: [Haiku-commits] r27530 - haiku/trunk/src/system/kernel/arch/x86 Message-ID: <200809151318.m8FDICGv028090@sheep.berlios.de> Author: bonefish Date: 2008-09-15 15:18:11 +0200 (Mon, 15 Sep 2008) New Revision: 27530 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27530&view=rev Modified: haiku/trunk/src/system/kernel/arch/x86/arch_int.c Log: For the time being allow page faults to happen when interrupts are disabled, as long as a fault handler is installed for the thread. It allows user_memcpy() to be invoked with interrupts disabled -- in this case it will simply fail, when the address is valid, but not mapped yet. This is a more desirable behavior for debug facilities, though in all other cases it is likely a bug. We should probably introduce a thread flag to discriminate these situations. Modified: haiku/trunk/src/system/kernel/arch/x86/arch_int.c =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/arch_int.c 2008-09-15 13:09:14 UTC (rev 27529) +++ haiku/trunk/src/system/kernel/arch/x86/arch_int.c 2008-09-15 13:18:11 UTC (rev 27530) @@ -849,8 +849,19 @@ "address %p from eip %p\n", (void *)cr2, (void *)frame->eip); return; } else if ((frame->flags & 0x200) == 0) { - // if the interrupts were disabled, and we are not running the kernel startup - // the page fault was not allowed to happen and we must panic + // interrupts disabled + + // If a page fault handler is installed, we're allowed to be here. + // TODO: Now we are generally allowing user_memcpy() with interrupts + // disabled, which in most cases is a bug. We should add some thread + // flag allowing to explicitly indicate that this handling is desired. + if (thread && thread->fault_handler != 0) { + frame->eip = thread->fault_handler; + return; + } + + // If we are not running the kernel startup the page fault was not + // allowed to happen and we must panic. panic("page fault, but interrupts were disabled. Touching address " "%p from eip %p\n", (void *)cr2, (void *)frame->eip); return; From bonefish at mail.berlios.de Mon Sep 15 15:36:32 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Mon, 15 Sep 2008 15:36:32 +0200 Subject: [Haiku-commits] r27531 - in haiku/trunk: headers/os/kernel headers/private/kernel src/system/kernel src/system/kernel/debug Message-ID: <200809151336.m8FDaWRi029508@sheep.berlios.de> Author: bonefish Date: 2008-09-15 15:36:31 +0200 (Mon, 15 Sep 2008) New Revision: 27531 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27531&view=rev Modified: haiku/trunk/headers/os/kernel/debugger.h haiku/trunk/headers/private/kernel/user_debugger.h haiku/trunk/src/system/kernel/debug/Jamfile haiku/trunk/src/system/kernel/debug/user_debugger.cpp haiku/trunk/src/system/kernel/scheduler.cpp haiku/trunk/src/system/kernel/thread.cpp Log: * Extended the debugger API by sampling-based profiling support. This is still pretty much work in progress. * Introduced init_thread_debug_info() which is used instead of clear_thread_debug_info() when the thread is created. The latter requires former initialization. * user_debug_thread_deleted() is now already invoked in thread_exit(), not in the undertaker. Modified: haiku/trunk/headers/os/kernel/debugger.h =================================================================== --- haiku/trunk/headers/os/kernel/debugger.h 2008-09-15 13:18:11 UTC (rev 27530) +++ haiku/trunk/headers/os/kernel/debugger.h 2008-09-15 13:36:31 UTC (rev 27531) @@ -146,6 +146,9 @@ // handed over to another debugger; // the new debugger can just invoke // install_team_debugger() + + B_DEBUG_START_PROFILER, // start/stop sampling + B_DEBUG_STOP_PROFILER // } debug_nub_message; // messages sent to the debugger @@ -168,6 +171,9 @@ B_DEBUGGER_MESSAGE_IMAGE_CREATED, // an image has been created B_DEBUGGER_MESSAGE_IMAGE_DELETED, // an image has been deleted + B_DEBUGGER_MESSAGE_PROFILER_STOPPED, // a profiled thread is going to + // exit + B_DEBUGGER_MESSAGE_HANDED_OVER, // the debugged team has been // handed over to another debugger } debug_debugger_message; @@ -346,6 +352,35 @@ // no parameters, no reply +// B_DEBUG_START_PROFILER + +struct debug_profile_function { + addr_t base; // function base address + size_t size; // function size +}; + +typedef struct { + port_id reply_port; // port to send the reply to + thread_id thread; // thread to profile + bigtime_t interval; // sample interval + int32 function_count; // number of functions we count hits for + struct debug_profile_function functions[1]; + // functions that shall be tracked +} debug_nub_start_profiler; + +typedef struct { + status_t error; +} debug_nub_start_profiler_reply; + +// B_DEBUG_STOP_PROFILER + +typedef struct { + port_id reply_port; // port to send the reply to + thread_id thread; // thread to profile +} debug_nub_stop_profiler; + +// reply is debug_profiler_stopped + // union of all messages structures sent to the debug nub thread typedef union { debug_nub_read_memory read_memory; @@ -363,6 +398,8 @@ debug_nub_get_signal_masks get_signal_masks; debug_nub_set_signal_handler set_signal_handler; debug_nub_get_signal_handler get_signal_handler; + debug_nub_start_profiler start_profiler; + debug_nub_stop_profiler stop_profiler; } debug_nub_message_data; @@ -495,6 +532,18 @@ image_info info; // info for the image } debug_image_deleted; +// B_DEBUGGER_MESSAGE_PROFILER_STOPPED + +typedef struct { + debug_origin origin; + int32 function_count; + bigtime_t interval; // actual sample interval (might + // differ from the requested one) + int64 total_ticks; // total number of sample ticks + int64 missed_ticks; // ticks that didn't hit a function + int64 function_ticks[1]; // number of hits for each function +} debug_profiler_stopped; + // B_DEBUGGER_MESSAGE_HANDED_OVER typedef struct { @@ -521,6 +570,7 @@ debug_thread_deleted thread_deleted; debug_image_created image_created; debug_image_deleted image_deleted; + debug_profiler_stopped profiler_stopped; // dynamic size! debug_handed_over handed_over; debug_origin origin; // for convenience (no real message) Modified: haiku/trunk/headers/private/kernel/user_debugger.h =================================================================== --- haiku/trunk/headers/private/kernel/user_debugger.h 2008-09-15 13:18:11 UTC (rev 27530) +++ haiku/trunk/headers/private/kernel/user_debugger.h 2008-09-15 13:36:31 UTC (rev 27531) @@ -11,6 +11,17 @@ #include +#include + + +// limits +#define B_DEBUG_MAX_PROFILE_FUNCTIONS 100000 +#define B_DEBUG_MIN_PROFILE_INTERVAL 1000 /* in us */ +#define B_DEBUG_STACK_TRACE_DEPTH 5 + + +struct function_profile_info; + // Team related debugging data. // // Locking policy: @@ -61,6 +72,28 @@ // the signals the debugger wishes not to be notified of, when they // occur the next time + struct { + bigtime_t interval; + // sampling interval + union { + bigtime_t interval_left; + // when unscheduled: the time left of the current sampling + // interval + bigtime_t timer_end; + // when running: the absolute time the timer is supposed to go + // off + }; + int32 function_count; + // number of tracked functions + struct function_profile_info* functions; + // array of tracked functions + debug_profiler_stopped* result; + // the result message to be sent to the debugger when profiling end; + // contains the current hit counts for all functions + timer* installed_timer; + // when running and being profiled: the CPU's profiling timer + } profile; + struct arch_thread_debug_info arch_info; }; @@ -135,8 +168,8 @@ void clear_team_debug_info(struct team_debug_info *info, bool initLock); void destroy_team_debug_info(struct team_debug_info *info); -void clear_thread_debug_info(struct thread_debug_info *info, - bool dying); +void init_thread_debug_info(struct thread_debug_info *info); +void clear_thread_debug_info(struct thread_debug_info *info, bool dying); void destroy_thread_debug_info(struct thread_debug_info *info); void user_debug_prepare_for_exec(); @@ -159,13 +192,17 @@ void user_debug_update_new_thread_flags(thread_id threadID); void user_debug_thread_created(thread_id threadID); void user_debug_thread_deleted(team_id teamID, thread_id threadID); +void user_debug_thread_exiting(struct thread* thread); void user_debug_image_created(const image_info *imageInfo); void user_debug_image_deleted(const image_info *imageInfo); void user_debug_breakpoint_hit(bool software); void user_debug_watchpoint_hit(); void user_debug_single_stepped(); +void user_debug_thread_unscheduled(struct thread* thread); +void user_debug_thread_scheduled(struct thread* thread); + // syscalls void _user_debugger(const char *message); Modified: haiku/trunk/src/system/kernel/debug/Jamfile =================================================================== --- haiku/trunk/src/system/kernel/debug/Jamfile 2008-09-15 13:18:11 UTC (rev 27530) +++ haiku/trunk/src/system/kernel/debug/Jamfile 2008-09-15 13:36:31 UTC (rev 27531) @@ -3,6 +3,7 @@ UsePrivateHeaders [ FDirName kernel debug ] syslog_daemon ; UsePrivateHeaders [ FDirName graphics common ] ; UsePrivateHeaders [ FDirName graphics vesa ] ; +UsePrivateHeaders shared ; KernelMergeObject kernel_debug.o : blue_screen.cpp Modified: haiku/trunk/src/system/kernel/debug/user_debugger.cpp =================================================================== --- haiku/trunk/src/system/kernel/debug/user_debugger.cpp 2008-09-15 13:18:11 UTC (rev 27530) +++ haiku/trunk/src/system/kernel/debug/user_debugger.cpp 2008-09-15 13:36:31 UTC (rev 27531) @@ -1,5 +1,5 @@ /* - * Copyright 2005-2006, Ingo Weinhold, bonefish at users.sf.net. + * Copyright 2005-2008, Ingo Weinhold, ingo_weinhold at gmx.de. * Distributed under the terms of the MIT License. */ @@ -8,12 +8,18 @@ #include #include +#include + +#include +#include +#include #include #include #include #include #include #include +#include #include #include #include @@ -21,8 +27,8 @@ #include #include #include -#include +#include #include //#define TRACE_USER_DEBUGGER @@ -33,21 +39,31 @@ #endif +struct function_profile_info : debug_profile_function { + int32 index; +}; + + static port_id sDefaultDebuggerPort = -1; // accessed atomically +static timer sProfilingTimers[B_MAX_CPU_COUNT]; + // a profiling timer for each CPU -- used when a profiled thread is running + // on that CPU + +static int32 profiling_event(timer* unused); static status_t ensure_debugger_installed(team_id teamID, port_id *port = NULL); static void get_team_debug_info(team_debug_info &teamDebugInfo); -static ssize_t -kill_interruptable_read_port(port_id port, int32 *code, void *buffer, - size_t bufferSize) -{ - return read_port_etc(port, code, buffer, bufferSize, - B_KILL_CAN_INTERRUPT, 0); -} +struct ProfileFunctionComparator { + inline bool operator()(const function_profile_info& a, + const function_profile_info& b) const + { + return a.base < b.base; + } +}; static status_t @@ -272,15 +288,41 @@ void +init_thread_debug_info(struct thread_debug_info *info) +{ + if (info) { + arch_clear_thread_debug_info(&info->arch_info); + info->flags = B_THREAD_DEBUG_DEFAULT_FLAGS; + info->debug_port = -1; + info->ignore_signals = 0; + info->ignore_signals_once = 0; + info->profile.functions = NULL; + info->profile.result = NULL; + info->profile.installed_timer = NULL; + } +} + + +/*! Invoked with thread lock being held. +*/ +void clear_thread_debug_info(struct thread_debug_info *info, bool dying) { if (info) { + // cancel profiling timer + if (info->profile.installed_timer != NULL) { + cancel_timer(info->profile.installed_timer); + info->profile.installed_timer = NULL; + } + arch_clear_thread_debug_info(&info->arch_info); atomic_set(&info->flags, B_THREAD_DEBUG_DEFAULT_FLAGS | (dying ? B_THREAD_DEBUG_DYING : 0)); info->debug_port = -1; info->ignore_signals = 0; info->ignore_signals_once = 0; + info->profile.functions = NULL; + info->profile.result = NULL; } } @@ -289,6 +331,9 @@ destroy_thread_debug_info(struct thread_debug_info *info) { if (info) { + free(info->profile.functions); + free(info->profile.result); + arch_destroy_thread_debug_info(&info->arch_info); if (info->debug_port >= 0) { @@ -510,8 +555,10 @@ // read a command from the debug port int32 command; debugged_thread_message_data commandMessage; - ssize_t commandMessageSize = kill_interruptable_read_port(port, - &command, &commandMessage, sizeof(commandMessage)); + ssize_t commandMessageSize = read_port_etc(port, &command, + &commandMessage, sizeof(commandMessage), B_KILL_CAN_INTERRUPT, + 0); + if (commandMessageSize < 0) { error = commandMessageSize; TRACE(("thread_hit_debug_event(): thread: %ld, failed " @@ -929,6 +976,58 @@ void +user_debug_thread_exiting(struct thread* thread) +{ + InterruptsLocker interruptsLocker; + SpinLocker teamLocker(gTeamSpinlock); + + struct team* team = thread->team; + + GRAB_TEAM_DEBUG_INFO_LOCK(team->debug_info); + + int32 teamDebugFlags = atomic_get(&team->debug_info.flags); + port_id debuggerPort = team->debug_info.debugger_port; + + RELEASE_TEAM_DEBUG_INFO_LOCK(team->debug_info); + + teamLocker.Unlock(); + + // check, if a debugger is installed + if ((teamDebugFlags & B_TEAM_DEBUG_DEBUGGER_INSTALLED) == 0 + || debuggerPort < 0) { + return; + } + + // detach the profile info and mark the thread dying + SpinLocker threadLocker(gThreadSpinlock); + + thread_debug_info& threadDebugInfo = thread->debug_info; + if (threadDebugInfo.profile.functions == NULL) + return; + + int32 functionCount = threadDebugInfo.profile.function_count; + function_profile_info* profileFunctions = threadDebugInfo.profile.functions; + debug_profiler_stopped* profileResult = threadDebugInfo.profile.result; + threadDebugInfo.profile.functions = NULL; + threadDebugInfo.profile.result = NULL; + + atomic_or(&threadDebugInfo.flags, B_THREAD_DEBUG_DYING); + + threadLocker.Unlock(); + interruptsLocker.Unlock(); + + // notify the debugger + size_t messageSize = sizeof(debug_profiler_stopped) + + 8 * (functionCount - 1); + debugger_write(debuggerPort, B_DEBUGGER_MESSAGE_PROFILER_STOPPED, + profileResult, messageSize, false); + + free(profileFunctions); + free(profileResult); +} + + +void user_debug_image_created(const image_info *imageInfo) { // check, if a debugger is installed and is interested in image events @@ -1035,6 +1134,105 @@ } +static void +schedule_profiling_timer(struct thread* thread, bigtime_t interval) +{ + struct timer* timer = &sProfilingTimers[thread->cpu->cpu_num]; + thread->debug_info.profile.installed_timer = timer; + thread->debug_info.profile.timer_end = system_time() + interval; + add_timer(timer, &profiling_event, interval, + B_ONE_SHOT_RELATIVE_TIMER | B_TIMER_ACQUIRE_THREAD_LOCK); +} + + +static function_profile_info* +find_profiled_function(const thread_debug_info& debugInfo, addr_t address) +{ + // binary search the function + function_profile_info* functions = debugInfo.profile.functions; + int32 lower = 0; + int32 upper = debugInfo.profile.function_count; + + while (lower < upper) { + int32 mid = (lower + upper) / 2; + if (address >= functions[mid].base + functions[mid].size) + lower = mid + 1; + else + upper = mid; + } + + if (lower == debugInfo.profile.function_count) + return NULL; + + function_profile_info* function = &functions[lower]; + if (address >= function->base && address < function->base + function->size) + return function; + return NULL; +} + + +static int32 +profiling_event(timer* /*unused*/) +{ + struct thread* thread = thread_get_current_thread(); + thread_debug_info& debugInfo = thread->debug_info; + + if (debugInfo.profile.functions != NULL) { + // Find the hit function and increment the tick counter. We + addr_t returnAddresses[B_DEBUG_STACK_TRACE_DEPTH]; + int32 count = arch_debug_get_stack_trace(returnAddresses, + B_DEBUG_STACK_TRACE_DEPTH, 1, 0, false); + + function_profile_info* function = NULL; + for (int32 i = 0; i < count; i++) { + function = find_profiled_function(debugInfo, returnAddresses[i]); + if (function != NULL) + break; + } + + if (function != NULL) + debugInfo.profile.result->function_ticks[function->index]++; + else + debugInfo.profile.result->missed_ticks++; + debugInfo.profile.result->total_ticks++; + + // reschedule timer + schedule_profiling_timer(thread, debugInfo.profile.interval); + } else + debugInfo.profile.installed_timer = NULL; + + return B_HANDLED_INTERRUPT; +} + + +void +user_debug_thread_unscheduled(struct thread* thread) +{ + // if running, cancel the profiling timer + struct timer* timer = thread->debug_info.profile.installed_timer; + if (timer != NULL) { + // track remaining time + bigtime_t left = thread->debug_info.profile.timer_end - system_time(); + thread->debug_info.profile.interval_left = max_c(left, 0); + thread->debug_info.profile.installed_timer = NULL; + + // cancel timer + cancel_timer(timer); + } +} + + +void +user_debug_thread_scheduled(struct thread* thread) +{ + if (thread->debug_info.profile.functions != NULL) { + // install profiling timer + schedule_profiling_timer(thread, + thread->debug_info.profile.interval_left); + } +} + + /** \brief Called by the debug nub thread of a team to broadcast a message * that are initialized for debugging (and thus have a debug port). */ @@ -1335,11 +1533,11 @@ while (true) { int32 command; debug_nub_message_data message; - ssize_t messageSize = kill_interruptable_read_port(port, &command, - &message, sizeof(message)); + ssize_t messageSize = read_port_etc(port, &command, &message, + sizeof(message), B_PEEK_PORT_MESSAGE | B_KILL_CAN_INTERRUPT, 0); if (messageSize < 0) { - // The port is not longer valid or we were interrupted by a kill + // The port is no longer valid or we were interrupted by a kill // signal: If we are still listed in the team's debug info as nub // thread, we need to update that. nub_thread_cleanup(nubThread); @@ -1359,9 +1557,13 @@ debug_nub_set_watchpoint_reply set_watchpoint; debug_nub_get_signal_masks_reply get_signal_masks; debug_nub_get_signal_handler_reply get_signal_handler; + debug_nub_start_profiler_reply start_profiler; + debug_profiler_stopped stop_profiler; } reply; + void* replyToSend = &reply; int32 replySize = 0; port_id replyPort = -1; + bool removeCommandMessage = true; // process the command switch (command) { @@ -1901,13 +2103,210 @@ break; } + + case B_DEBUG_START_PROFILER: + { + // get the parameters + thread_id threadID = message.start_profiler.thread; + replyPort = message.start_profiler.reply_port; + int32 functionCount = message.start_profiler.function_count; + status_t result = B_OK; + + TRACE(("nub thread %ld: B_DEBUG_START_PROFILER: " + "thread: %ld, %ld functions\n", nubThread->id, threadID, + functionCount)); + + if (functionCount < 1 + || functionCount > B_DEBUG_MAX_PROFILE_FUNCTIONS) { + result = B_BAD_VALUE; + } + + // allocate memory for the complete message + debug_nub_start_profiler* profileMessage = NULL; + size_t size = 0; + if (result == B_OK) { + size = (addr_t)&message.start_profiler.functions[ + functionCount] + - (addr_t)&message.start_profiler; + profileMessage = (debug_nub_start_profiler*)malloc(size); + if (profileMessage == NULL) + result = B_NO_MEMORY; + } + MemoryDeleter profileMessageDeleter(profileMessage); + + // read the complete message from the port + if (result == B_OK) { + int32 dummy; + ssize_t bytesRead = read_port_etc(port, &dummy, + profileMessage, size, B_RELATIVE_TIMEOUT, 0); + if (bytesRead < 0) { + result = bytesRead; + } else { + removeCommandMessage = false; + + if ((size_t)bytesRead != size) + result = B_BAD_VALUE; + } + } + + // allocate memory for the function infos + function_profile_info* profileFunctions = NULL; + if (result == B_OK) { + profileFunctions = (function_profile_info*)malloc( + sizeof(function_profile_info) * functionCount); + if (profileFunctions == NULL) + result = B_NO_MEMORY; + } + MemoryDeleter profileFunctionsDeleter(profileFunctions); + + // allocate memory for the reply + debug_profiler_stopped* profileResult = NULL; + size_t profileResultSize = 0; + if (result == B_OK) { + profileResultSize = sizeof(debug_profiler_stopped) + + 8 * (functionCount - 1); + profileResult + = (debug_profiler_stopped*)malloc(profileResultSize); + if (profileResult == NULL) + result = B_NO_MEMORY; + } + MemoryDeleter profileResultDeleter(profileResult); + + // transfer the function array from the message + if (result == B_OK) { + for (int32 i = 0; i < functionCount; i++) { + profileFunctions[i].base + = profileMessage->functions[i].base; + profileFunctions[i].size + = profileMessage->functions[i].size; + profileFunctions[i].index = i; + } + } + + // sort the functions and prepare the reply + if (result == B_OK) { + std::sort(profileFunctions, + profileFunctions + functionCount, + ProfileFunctionComparator()); + + memset(profileResult, 0, profileResultSize); + profileResult->origin.thread = threadID; + profileResult->origin.team = nubThread->team->id; + profileResult->origin.nub_port = -1; + profileResult->interval = max_c(profileMessage->interval, + B_DEBUG_MIN_PROFILE_INTERVAL); + profileResult->function_count = functionCount; + } + + // get the thread and set the profile info + cpu_status state = disable_interrupts(); + GRAB_THREAD_LOCK(); + + struct thread *thread + = thread_get_thread_struct_locked(threadID); + if (thread && thread->team == nubThread->team) { + thread_debug_info &threadDebugInfo = thread->debug_info; + if (threadDebugInfo.profile.functions == NULL) { + threadDebugInfo.profile.interval + = profileResult->interval; + threadDebugInfo.profile.interval_left + = threadDebugInfo.profile.interval; + threadDebugInfo.profile.function_count = functionCount; + threadDebugInfo.profile.functions = profileFunctions; + threadDebugInfo.profile.result = profileResult; + threadDebugInfo.profile.installed_timer = NULL; + } else + result = B_BAD_VALUE; + } else + result = B_BAD_THREAD_ID; + + RELEASE_THREAD_LOCK(); + restore_interrupts(state); + + // if all went well, keep the allocated structures + if (result == B_OK) { + profileFunctionsDeleter.Detach(); + profileResultDeleter.Detach(); + } + + // send a reply to the debugger + reply.start_profiler.error = result; + sendReply = true; + replySize = sizeof(reply.start_profiler); + + break; + } + + case B_DEBUG_STOP_PROFILER: + { + // get the parameters + thread_id threadID = message.stop_profiler.thread; + replyPort = message.stop_profiler.reply_port; + status_t result = B_OK; + + TRACE(("nub thread %ld: B_DEBUG_STOP_PROFILER: " + "thread: %ld\n", nubThread->id, threadID)); + + function_profile_info* profileFunctions = NULL; + debug_profiler_stopped* profileResult = NULL; + int32 functionCount = 0; + + // get the thread and detach the profile info + cpu_status state = disable_interrupts(); + GRAB_THREAD_LOCK(); + + struct thread *thread + = thread_get_thread_struct_locked(threadID); + if (thread && thread->team == nubThread->team) { + thread_debug_info &threadDebugInfo = thread->debug_info; + if (threadDebugInfo.profile.functions != NULL) { + functionCount = threadDebugInfo.profile.function_count; + profileFunctions = threadDebugInfo.profile.functions; + profileResult = threadDebugInfo.profile.result; + threadDebugInfo.profile.functions = NULL; + threadDebugInfo.profile.result = NULL; + } else + result = B_BAD_VALUE; + } else + result = B_BAD_THREAD_ID; + + RELEASE_THREAD_LOCK(); + restore_interrupts(state); + + // prepare the reply + if (result == B_OK) { + replyToSend = profileResult; + replySize = sizeof(debug_profiler_stopped) + + 8 * (functionCount - 1); + } else { + reply.stop_profiler.origin.thread = result; + reply.stop_profiler.total_ticks = 0; + reply.stop_profiler.missed_ticks = 0; + replySize = sizeof(reply.stop_profiler); + } + sendReply = true; + + free(profileFunctions); + // profileResult is the reply to be sent and will be deleted + // after sending. + } } + // We only peeked the command message -- unless the command handler did + // that already, we need to remove the message from the port. + if (removeCommandMessage) { + int32 dummy; + read_port_etc(port, &dummy, NULL, 0, B_RELATIVE_TIMEOUT, 0); + } + // send the reply, if necessary if (sendReply) { status_t error = kill_interruptable_write_port(replyPort, command, - &reply, replySize); + replyToSend, replySize); + if (replyToSend != &reply) + free(replyToSend); + if (error != B_OK) { // The debugger port is either not longer existing or we got // interrupted by a kill signal. In either case we terminate. Modified: haiku/trunk/src/system/kernel/scheduler.cpp =================================================================== --- haiku/trunk/src/system/kernel/scheduler.cpp 2008-09-15 13:18:11 UTC (rev 27530) +++ haiku/trunk/src/system/kernel/scheduler.cpp 2008-09-15 13:36:31 UTC (rev 27531) @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -539,11 +540,20 @@ static void context_switch(struct thread *fromThread, struct thread *toThread) { + if ((fromThread->flags & THREAD_FLAGS_DEBUGGER_INSTALLED) != 0) + user_debug_thread_unscheduled(fromThread); + toThread->cpu = fromThread->cpu; fromThread->cpu = NULL; arch_thread_set_current_thread(toThread); arch_thread_context_switch(fromThread, toThread); + + // Looks weird, but is correct. fromThread had been unscheduled earlier, + // but is back now. The notification for a thread scheduled the first time + // happens in thread.cpp:thread_kthread_entry(). + if ((fromThread->flags & THREAD_FLAGS_DEBUGGER_INSTALLED) != 0) + user_debug_thread_scheduled(fromThread); } Modified: haiku/trunk/src/system/kernel/thread.cpp =================================================================== --- haiku/trunk/src/system/kernel/thread.cpp 2008-09-15 13:18:11 UTC (rev 27530) +++ haiku/trunk/src/system/kernel/thread.cpp 2008-09-15 13:36:31 UTC (rev 27531) @@ -301,6 +301,11 @@ { struct thread *thread = thread_get_current_thread(); + // The thread is new and has been scheduled the first time. Notify the user + // debugger code. + if ((thread->flags & THREAD_FLAGS_DEBUGGER_INSTALLED) != 0) + user_debug_thread_scheduled(thread); + // simulates the thread spinlock release that would occur if the thread had been // rescheded from. The resched didn't happen because the thread is new. RELEASE_THREAD_LOCK(); @@ -386,7 +391,7 @@ thread->next_state = B_THREAD_SUSPENDED; // init debug structure - clear_thread_debug_info(&thread->debug_info, false); + init_thread_debug_info(&thread->debug_info); snprintf(stack_name, B_OS_NAME_LENGTH, "%s_%ld_kstack", attributes.name, thread->id); @@ -578,12 +583,6 @@ if (entry.deathSem >= 0) release_sem_etc(entry.deathSem, 1, B_DO_NOT_RESCHEDULE); - // notify the debugger - if (entry.teamID >= 0 - && entry.teamID != team_get_kernel_team_id()) { - user_debug_thread_deleted(entry.teamID, thread->id); - } - // free the thread structure thread_enqueue(thread, &dead_q); // TODO: Use the slab allocator! @@ -1353,6 +1352,8 @@ struct death_entry* threadDeathEntry = NULL; if (team != team_get_kernel_team()) { + user_debug_thread_exiting(thread); + if (team->main_thread == thread) { // this was the main thread in this team, so we will delete that as well deleteTeam = true; @@ -1531,6 +1532,10 @@ delete_sem(cachedExitSem); } + // notify the debugger + if (teamID != team_get_kernel_team_id()) + user_debug_thread_deleted(teamID, thread->id); + // enqueue in the undertaker list and reschedule for the last time UndertakerEntry undertakerEntry(thread, teamID, cachedDeathSem); From dlmcpaul at mail.berlios.de Mon Sep 15 15:37:52 2008 From: dlmcpaul at mail.berlios.de (dlmcpaul at BerliOS) Date: Mon, 15 Sep 2008 15:37:52 +0200 Subject: [Haiku-commits] r27532 - in haiku/trunk/src/add-ons/media/plugins/mp4_reader: . libMP4 Message-ID: <200809151337.m8FDbq03029584@sheep.berlios.de> Author: dlmcpaul Date: 2008-09-15 15:37:51 +0200 (Mon, 15 Sep 2008) New Revision: 27532 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27532&view=rev Modified: haiku/trunk/src/add-ons/media/plugins/mp4_reader/libMP4/MP4Parser.cpp haiku/trunk/src/add-ons/media/plugins/mp4_reader/mp4_reader.cpp Log: changes to handle avcodec aac Modified: haiku/trunk/src/add-ons/media/plugins/mp4_reader/libMP4/MP4Parser.cpp =================================================================== --- haiku/trunk/src/add-ons/media/plugins/mp4_reader/libMP4/MP4Parser.cpp 2008-09-15 13:36:31 UTC (rev 27531) +++ haiku/trunk/src/add-ons/media/plugins/mp4_reader/libMP4/MP4Parser.cpp 2008-09-15 13:37:51 UTC (rev 27532) @@ -1085,6 +1085,9 @@ uint32 buffer; uint32 temp; + // remember where the tag 5 starts + uint32 extendedAudioConfig = offset; + switch (ESDSType) { case 64: // AAC // Attempt to read AAC Header @@ -1114,10 +1117,14 @@ // SampleRate is in 16.16 format pAudioDescription->theAudioSampleEntry.SampleRate = aac_sampling_rate[theAACHeader.sampleRateIndex] * 65536 ; pAudioDescription->theAudioSampleEntry.ChannelCount = theAACHeader.totalChannels; + + // Reset decoder Config memory + memcpy(pAudioDescription->theDecoderConfig, &pAudioDescription->theDecoderConfig[extendedAudioConfig], pAudioDescription->DecoderConfigSize-extendedAudioConfig+1); + break; case 107: // MP3 - pAudioDescription->codecSubType = 'mp3'; + pAudioDescription->codecSubType = '.mp3'; // Only set this for mp3, we calc it normally if (NeededBufferSize > pAudioDescription->BufferSize) { @@ -1172,7 +1179,6 @@ void WAVEAtom::OnProcessMetaData() { - } char *WAVEAtom::OnGetAtomName() @@ -1182,8 +1188,8 @@ void WAVEAtom::OnOverrideAudioDescription(AudioDescription *pAudioDescription) { - pAudioDescription->codecSubType = 'mp3'; - pAudioDescription->FrameSize = 0; + pAudioDescription->codecSubType = '.mp3'; + pAudioDescription->FrameSize = 1; } void WAVEAtom::OnOverrideVideoDescription(VideoDescription *pVideoDescription) @@ -1196,7 +1202,7 @@ theHeader.NoEntries = 0; theAudioDescription.codecid = 0; theAudioDescription.codecSubType = 0; - theAudioDescription.FrameSize = 0; + theAudioDescription.FrameSize = 1; theAudioDescription.BufferSize = 0; theAudioDescription.BitRate = 0; theAudioDescription.theDecoderConfig = NULL; Modified: haiku/trunk/src/add-ons/media/plugins/mp4_reader/mp4_reader.cpp =================================================================== --- haiku/trunk/src/add-ons/media/plugins/mp4_reader/mp4_reader.cpp 2008-09-15 13:36:31 UTC (rev 27531) +++ haiku/trunk/src/add-ons/media/plugins/mp4_reader/mp4_reader.cpp 2008-09-15 13:37:51 UTC (rev 27532) @@ -47,7 +47,6 @@ #define ERROR(a...) fprintf(stderr, a) - struct mp4_cookie { unsigned stream; char * buffer; @@ -73,7 +72,6 @@ uint32 frame_size; }; - mp4Reader::mp4Reader() : theFileReader(0) { @@ -140,7 +138,6 @@ strcpy(mff->pretty_name, "MPEG-4 (MP4) file format"); } - status_t mp4Reader::AllocateCookie(int32 streamNumber, void **_cookie) { @@ -184,11 +181,11 @@ delete cookie; return B_ERROR; } - codecID = B_BENDIAN_TO_HOST_INT32(audio_format->compression); // frame_count is actually sample_count for audio - makes media_player happy but david sad cookie->frame_count = theFileReader->getFrameCount(cookie->stream) * audio_format->FrameSize; cookie->duration = theFileReader->getAudioDuration(cookie->stream); + cookie->frame_size = audio_format->FrameSize; cookie->audio = true; @@ -225,6 +222,8 @@ || audio_format->compression == AUDIO_RAW || audio_format->compression == AUDIO_TWOS1 || audio_format->compression == AUDIO_TWOS2) { + + codecID = B_BENDIAN_TO_HOST_INT32(audio_format->compression); description.family = B_BEOS_FORMAT_FAMILY; description.u.beos.format = B_BEOS_FORMAT_RAW_AUDIO; if (B_OK != formats.GetFormatFor(description, format)) @@ -267,13 +266,21 @@ format->u.raw_audio.buffer_size = stream_header->suggested_buffer_size; } else { + printf("codecid %s codecsubtype %s\n",&audio_format->compression,&audio_format->codecSubType); + description.family = B_QUICKTIME_FORMAT_FAMILY; - description.u.quicktime.codec = audio_format->compression; + + if (audio_format->codecSubType != 0) { + codecID = audio_format->codecSubType; + } else { + codecID = audio_format->compression; + } + description.u.quicktime.codec = codecID; if (B_OK != formats.GetFormatFor(description, format)) { format->type = B_MEDIA_ENCODED_AUDIO; } - switch (audio_format->compression) { + switch (description.u.quicktime.codec) { case AUDIO_MS_PCM02: TRACE("MS PCM02\n"); format->u.raw_audio.format |= B_AUDIO_FORMAT_CHANNEL_ORDER_WAVE; @@ -288,15 +295,28 @@ format->u.encoded_audio.output.channel_count = audio_format->NoOfChannels; break; case AUDIO_MPEG3_CBR: + case '.mp3': TRACE("MP3\n"); format->u.encoded_audio.bit_rate = 8 * cookie->frames_per_sec_rate / cookie->frames_per_sec_scale; format->u.encoded_audio.output.frame_rate = cookie->frames_per_sec_rate / cookie->frames_per_sec_scale; format->u.encoded_audio.output.channel_count = audio_format->NoOfChannels; + format->u.encoded_audio.output.buffer_size = audio_format->BufferSize; + + format->u.encoded_audio.output.format = media_raw_audio_format::B_AUDIO_SHORT; + format->u.encoded_audio.output.byte_order = B_HOST_IS_LENDIAN ? B_MEDIA_LITTLE_ENDIAN : B_MEDIA_BIG_ENDIAN; + + TRACE("Audio NoOfChannels %d, SampleSize %d, SampleRate %f, FrameSize %ld\n",audio_format->NoOfChannels, audio_format->SampleSize, audio_format->SampleRate, audio_format->FrameSize); + + TRACE("Audio frame_rate %f, channel_count %ld, format %ld, buffer_size %ld, frame_size %ld, bit_rate %f\n", + format->u.encoded_audio.output.frame_rate, format->u.encoded_audio.output.channel_count, format->u.encoded_audio.output.format,format->u.encoded_audio.output.buffer_size, format->u.encoded_audio.frame_size, format->u.encoded_audio.bit_rate); + + TRACE("Track %d MP4 Audio FrameCount %ld Duration %Ld\n",cookie->stream,theFileReader->getFrameCount(cookie->stream),cookie->duration); break; case 'mp4a': - codecID = B_BENDIAN_TO_HOST_INT32('aac '); + codecID = 'aac '; + case 'aac ': case 'alac': - TRACE("AAC audio (mp4a) or ALAC audio\n"); + TRACE("AAC audio or ALAC audio\n"); format->u.encoded_audio.output.frame_rate = cookie->frames_per_sec_rate / cookie->frames_per_sec_scale; @@ -309,8 +329,6 @@ // ALAC is 4096 samples per frame format->u.encoded_audio.frame_size = audio_format->FrameSize; - cookie->frame_size = audio_format->FrameSize; - format->u.encoded_audio.output.buffer_size = audio_format->BufferSize; // Average BitRate = (TotalBytes * 8 * (SampleRate / FrameSize)) / TotalFrames @@ -338,11 +356,12 @@ format->u.encoded_audio.bit_rate = 8 * cookie->frames_per_sec_rate / cookie->frames_per_sec_scale; format->u.encoded_audio.output.frame_rate = cookie->frames_per_sec_rate / cookie->frames_per_sec_scale; format->u.encoded_audio.output.channel_count = audio_format->NoOfChannels; + format->u.encoded_audio.output.buffer_size = audio_format->BufferSize; break; } } - // Set the DecoderConfigSize + // Set the DecoderConfig size = audio_format->DecoderConfigSize; data = audio_format->theDecoderConfig; if (size > 0) { @@ -357,8 +376,8 @@ #ifdef TRACE_MP4_READER if (data) { uint8 *p = (uint8 *)data; - TRACE("extra_data: %ld: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", - size , p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9]); + TRACE("extra_data: %ld: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", + size , p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15], p[16], p[17]); } #endif @@ -533,6 +552,8 @@ } else { ERROR("No stream Info for stream %d\n",cookie->stream); } + + TRACE("GetStreamInfo (%d) fc %Ld duration %Ld extra %ld\n",cookie->stream,*frameCount,*duration,*infoSize); } return B_OK; } From bonefish at mail.berlios.de Mon Sep 15 15:45:44 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Mon, 15 Sep 2008 15:45:44 +0200 Subject: [Haiku-commits] r27533 - in haiku/trunk/src: bin bin/debug bin/debug/strace tools/gensyscalls Message-ID: <200809151345.m8FDji9q030702@sheep.berlios.de> Author: bonefish Date: 2008-09-15 15:45:43 +0200 (Mon, 15 Sep 2008) New Revision: 27533 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27533&view=rev Added: haiku/trunk/src/bin/debug/ haiku/trunk/src/bin/debug/Jamfile haiku/trunk/src/bin/debug/debug_utils.cpp haiku/trunk/src/bin/debug/debug_utils.h haiku/trunk/src/bin/debug/profile.cpp haiku/trunk/src/bin/debug/strace/ Removed: haiku/trunk/src/bin/strace/ Modified: haiku/trunk/src/bin/Jamfile haiku/trunk/src/bin/debug/strace/Jamfile haiku/trunk/src/bin/debug/strace/strace.cpp haiku/trunk/src/tools/gensyscalls/Jamfile Log: * Moved strace sourced to src/bin/debug/. * Factored a few functions out of strace that can be reused. * Added the beginnings of a "profile" command. It is very much work in progress, though it is already able to profile the main thread of a program. Modified: haiku/trunk/src/bin/Jamfile =================================================================== --- haiku/trunk/src/bin/Jamfile 2008-09-15 13:37:51 UTC (rev 27532) +++ haiku/trunk/src/bin/Jamfile 2008-09-15 13:45:43 UTC (rev 27533) @@ -207,7 +207,6 @@ SubInclude HAIKU_TOP src bin screenmode ; SubInclude HAIKU_TOP src bin sed ; SubInclude HAIKU_TOP src bin sharutils ; -SubInclude HAIKU_TOP src bin strace ; SubInclude HAIKU_TOP src bin unrar ; SubInclude HAIKU_TOP src bin vim ; SubInclude HAIKU_TOP src bin zic ; @@ -215,6 +214,9 @@ # RCS commands SubInclude HAIKU_TOP src bin rcs ; +# debugging tools +SubInclude HAIKU_TOP src bin debug ; + # Network command line tools SubInclude HAIKU_TOP src bin network ; Added: haiku/trunk/src/bin/debug/Jamfile =================================================================== --- haiku/trunk/src/bin/debug/Jamfile 2008-09-15 13:37:51 UTC (rev 27532) +++ haiku/trunk/src/bin/debug/Jamfile 2008-09-15 13:45:43 UTC (rev 27533) @@ -0,0 +1,20 @@ +SubDir HAIKU_TOP src bin debug ; + +UsePrivateHeaders debug ; +UsePrivateHeaders libroot ; +UsePrivateHeaders shared ; +UsePrivateSystemHeaders ; + +StaticLibrary debug_utils.a : debug_utils.cpp ; + +BinCommand profile + : profile.cpp + : + debug_utils.a + libdebug.so + $(TARGET_LIBSTDC++) + be +; + + +HaikuSubInclude strace ; Added: haiku/trunk/src/bin/debug/debug_utils.cpp =================================================================== --- haiku/trunk/src/bin/debug/debug_utils.cpp 2008-09-15 13:37:51 UTC (rev 27532) +++ haiku/trunk/src/bin/debug/debug_utils.cpp 2008-09-15 13:45:43 UTC (rev 27533) @@ -0,0 +1,183 @@ +/* + * Copyright 2005-2008, Ingo Weinhold, ingo_weinhold at gmx.de. + * Distributed under the terms of the MIT License. + */ + +#include "debug_utils.h" + +#include +#include +#include + +#include + +#include + +#include +#include + + +extern const char* __progname; +static const char* kCommandName = __progname; + + +// find_program +static status_t +find_program(const char* programName, std::string& resolvedPath) +{ + // If the program name is absolute, then there's nothing to do. + // If the program name consists of more than one path element, then we + // consider it a relative path and don't search in PATH either. + if (*programName == '/' || strchr(programName, '/')) { + resolvedPath = programName; + return B_OK; + } + + // get the PATH environment variable + const char* paths = getenv("PATH"); + if (!paths) + return B_ENTRY_NOT_FOUND; + + // iterate through the paths + do { + const char* pathEnd = strchr(paths, ':'); + int pathLen = (pathEnd ? pathEnd - paths : strlen(paths)); + + // We skip empty paths. + if (pathLen > 0) { + // get the program path + std::string path(paths, pathLen); + path += "/"; + path += programName; + + // stat() the path to be sure, there is a file + struct stat st; + if (stat(path.c_str(), &st) == 0 && S_ISREG(st.st_mode)) { + resolvedPath = path; + return B_OK; + } + } + + paths = (pathEnd ? pathEnd + 1 : NULL); + } while (paths); + + // not found in PATH + return B_ENTRY_NOT_FOUND; +} + + +// #pragma mark - + + +// load_program +thread_id +load_program(const char* const* args, int32 argCount, bool traceLoading) +{ + // clone the argument vector so that we can change it + const char** mutableArgs = new const char*[argCount]; + for (int i = 0; i < argCount; i++) + mutableArgs[i] = args[i]; + + // resolve the program path + std::string programPath; + status_t error = find_program(args[0], programPath); + if (error != B_OK) { + delete[] mutableArgs; + return error; + } + mutableArgs[0] = programPath.c_str(); + + // count environment variables + int envCount = 0; + while (environ[envCount] != NULL) + envCount++; + + // flatten the program args and environment + char** flatArgs = NULL; + size_t flatArgsSize; + error = __flatten_process_args(mutableArgs, argCount, environ, envCount, + &flatArgs, &flatArgsSize); + + // load the program + thread_id thread; + if (error == B_OK) { + thread = _kern_load_image(flatArgs, flatArgsSize, argCount, envCount, + B_NORMAL_PRIORITY, (traceLoading ? 0 : B_WAIT_TILL_LOADED), -1, 0); + + free(flatArgs); + } else + thread = error; + + delete[] mutableArgs; + + return thread; +} + + +// set_team_debugging_flags +void +set_team_debugging_flags(port_id nubPort, int32 flags) +{ + debug_nub_set_team_flags message; + message.flags = flags; + + while (true) { + status_t error = write_port(nubPort, B_DEBUG_MESSAGE_SET_TEAM_FLAGS, + &message, sizeof(message)); + if (error == B_OK) + return; + + if (error != B_INTERRUPTED) { + fprintf(stderr, "%s: Failed to set team debug flags: %s\n", + kCommandName, strerror(error)); + exit(1); + } + } +} + + +// set_thread_debugging_flags +void +set_thread_debugging_flags(port_id nubPort, thread_id thread, int32 flags) +{ + debug_nub_set_thread_flags message; + message.thread = thread; + message.flags = flags; + + while (true) { + status_t error = write_port(nubPort, B_DEBUG_MESSAGE_SET_THREAD_FLAGS, + &message, sizeof(message)); + if (error == B_OK) + return; + + if (error != B_INTERRUPTED) { + fprintf(stderr, "%s: Failed to set thread debug flags: %s\n", + kCommandName, strerror(error)); + exit(1); + } + } +} + + +// continue_thread +void +continue_thread(port_id nubPort, thread_id thread) +{ + debug_nub_continue_thread message; + message.thread = thread; + message.handle_event = B_THREAD_DEBUG_HANDLE_EVENT; + message.single_step = false; + + while (true) { + status_t error = write_port(nubPort, B_DEBUG_MESSAGE_CONTINUE_THREAD, + &message, sizeof(message)); + if (error == B_OK) + return; + + if (error != B_INTERRUPTED) { + fprintf(stderr, "%s: Failed to run thread %ld: %s\n", + kCommandName, thread, strerror(error)); + exit(1); + } + } +} Added: haiku/trunk/src/bin/debug/debug_utils.h =================================================================== --- haiku/trunk/src/bin/debug/debug_utils.h 2008-09-15 13:37:51 UTC (rev 27532) +++ haiku/trunk/src/bin/debug/debug_utils.h 2008-09-15 13:45:43 UTC (rev 27533) @@ -0,0 +1,20 @@ +/* + * Copyright 2005-2008, Ingo Weinhold, ingo_weinhold at gmx.de. + * Distributed under the terms of the MIT License. + */ +#ifndef BIN_DEBUG_DEBUG_UTILS_H +#define BIN_DEBUG_DEBUG_UTILS_H + +#include + + +thread_id load_program(const char* const* args, int32 argCount, + bool traceLoading); + +void set_team_debugging_flags(port_id nubPort, int32 flags); +void set_thread_debugging_flags(port_id nubPort, thread_id thread, + int32 flags); +void continue_thread(port_id nubPort, thread_id thread); + + +#endif // BIN_DEBUG_DEBUG_UTILS_H Added: haiku/trunk/src/bin/debug/profile.cpp =================================================================== --- haiku/trunk/src/bin/debug/profile.cpp 2008-09-15 13:37:51 UTC (rev 27532) +++ haiku/trunk/src/bin/debug/profile.cpp 2008-09-15 13:45:43 UTC (rev 27533) @@ -0,0 +1,403 @@ +/* + * Copyright 2008, Ingo Weinhold, ingo_weinhold at gmx.de. + * Distributed under the terms of the MIT License. + */ + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include + +#include "debug_utils.h" + + +extern const char* __progname; +static const char* kCommandName = __progname; + + +class Symbol { +public: + Symbol(addr_t base, size_t size, const char* name) + : + base(base), + size(size), + name(name) + { + } + + const char* Name() const { return name.String(); } + + addr_t base; + size_t size; + BString name; +}; + + +// TODO: Adjust! +static const char* kUsage = + "Usage: %s [ ] \n" + "Executes the given command line and print an analysis of\n" + "the user and kernel times of all threads that ran during that time.\n" + "\n" + "Options:\n" + " -h, --help - Print this usage info.\n" + " -o - Print the results to file .\n" + " -s - Also perform a scheduling analysis over the time the\n" + " child process ran. This requires that scheduler kernel\n" + " tracing had been enabled at compile time.\n" +; + + +static void +print_usage_and_exit(bool error) +{ + fprintf(error ? stderr : stdout, kUsage, __progname); + exit(error ? 1 : 0); +} + + +/* +// get_id +static bool +get_id(const char *str, int32 &id) +{ + int32 len = strlen(str); + for (int32 i = 0; i < len; i++) { + if (!isdigit(str[i])) + return false; + } + + id = atol(str); + return true; +} +*/ + + +int +main(int argc, const char* const* argv) +{ +// const char* outputFile = NULL; +// bool schedulingAnalysis = false; + + while (true) { + static struct option sLongOptions[] = { + { "help", no_argument, 0, 'h' }, +// { "output", required_argument, 0, 'o' }, + { 0, 0, 0, 0 } + }; + + opterr = 0; // don't print errors + int c = getopt_long(argc, (char**)argv, "+h", sLongOptions, NULL); + if (c == -1) + break; + + switch (c) { + case 'h': + print_usage_and_exit(false); + break; +/* case 'o': + outputFile = optarg; + break; + case 's': + schedulingAnalysis = true; + break; +*/ + + default: + print_usage_and_exit(true); + break; + } + } + + if (optind >= argc) + print_usage_and_exit(true); + + const char* const* programArgs = argv + optind; + int programArgCount = argc - optind; + + // get thread/team to be debugged + thread_id thread = -1; + team_id team = -1; +// if (programArgCount > 1 +// || !get_id(*programArgs, (traceTeam ? team : thread))) { + // we've been given an executable and need to load it + thread = load_program(programArgs, programArgCount, false); + if (thread < 0) { + fprintf(stderr, "%s: Failed to start `%s': %s\n", kCommandName, + programArgs[0], strerror(thread)); + exit(1); + } +// } + + // get the team ID, if we have none yet + if (team < 0) { + thread_info threadInfo; + status_t error = get_thread_info(thread, &threadInfo); + if (error != B_OK) { + fprintf(stderr, "%s: Failed to get info for thread %ld: %s\n", + kCommandName, thread, strerror(error)); + exit(1); + } + team = threadInfo.team; + } + + // create a debugger port + port_id debuggerPort = create_port(10, "debugger port"); + if (debuggerPort < 0) { + fprintf(stderr, "%s: Failed to create debugger port: %s\n", + kCommandName, strerror(debuggerPort)); + exit(1); + } + + // install ourselves as the team debugger + port_id nubPort = install_team_debugger(team, debuggerPort); + if (nubPort < 0) { + fprintf(stderr, "%s: Failed to install team debugger: %s\n", + kCommandName, strerror(nubPort)); + exit(1); + } + + // init debug context + debug_context debugContext; + status_t error = init_debug_context(&debugContext, team, nubPort); + if (error != B_OK) { + fprintf(stderr, "%s: Failed to init debug context: %s\n", + kCommandName, strerror(error)); + exit(1); + } + + // create symbol lookup context + debug_symbol_lookup_context* lookupContext; + error = debug_create_symbol_lookup_context(&debugContext, + &lookupContext); + if (error != B_OK) { + fprintf(stderr, "%s: Failed to create symbol lookup context: %s\n", + kCommandName, strerror(error)); + exit(1); + } + + // iterate through the team's images and collect the symbols + BObjectList symbols(1000, true); + image_info imageInfo; + int32 cookie = 0; + while (get_next_image_info(team, &cookie, &imageInfo) == B_OK) { + printf("Loading symbols of image \"%s\" (%ld)...\n", + imageInfo.name, imageInfo.id); + // create symbol iterator + debug_symbol_iterator* iterator; + error = debug_create_image_symbol_iterator(lookupContext, imageInfo.id, + &iterator); + if (error != B_OK) { + printf("Failed to init symbol iterator: %s\n", strerror(error)); + continue; + } + + // iterate through the images + char symbolName[1024]; + int32 symbolType; + void* symbolLocation; + size_t symbolSize; + while (debug_next_image_symbol(iterator, symbolName, sizeof(symbolName), + &symbolType, &symbolLocation, &symbolSize) == B_OK) { +//if (symbolSize == 0) { +// printf(" %s %p (%6lu) %s\n", +// symbolType == B_SYMBOL_TYPE_TEXT ? "text" : "data", +// symbolLocation, symbolSize, symbolName); +//} + if (symbolType == B_SYMBOL_TYPE_TEXT) { + Symbol* symbol = new(std::nothrow) Symbol( + (addr_t)symbolLocation, symbolSize, symbolName); + if (symbol == NULL || !symbols.AddItem(symbol)) { + fprintf(stderr, "%s: Out of memory\n", kCommandName); + exit(1); + } + } + } + + debug_delete_image_symbol_iterator(iterator); + } + + debug_delete_symbol_lookup_context(lookupContext); + + // prepare the start profiler message + int32 symbolCount = symbols.CountItems(); + if (symbolCount == 0) { + fprintf(stderr, "%s: Got no symbols at all, exiting...\n", + kCommandName); + exit(1); + } + + size_t startProfilerSize = sizeof(debug_nub_start_profiler) + + (symbolCount - 1) * sizeof(debug_profile_function); + debug_nub_start_profiler* startProfiler + = (debug_nub_start_profiler*)malloc(startProfilerSize); + if (startProfiler == NULL) { + fprintf(stderr, "%s: Out of memory\n", kCommandName); + exit(1); + } + + startProfiler->reply_port = debugContext.reply_port; + startProfiler->thread = thread; + startProfiler->interval = 10; + startProfiler->function_count = symbolCount; + + for (int32 i = 0; i < symbolCount; i++) { + Symbol* symbol = symbols.ItemAt(i); + debug_profile_function& function = startProfiler->functions[i]; + function.base = symbol->base; + function.size = symbol->size; + } + + // allocate memory for the reply + size_t maxMessageSize = max_c(sizeof(debug_debugger_message_data), + sizeof(debug_profiler_stopped) + 8 * symbolCount); + debug_debugger_message_data* message = (debug_debugger_message_data*) + malloc(maxMessageSize); + if (message == NULL) { + fprintf(stderr, "%s: Out of memory\n", kCommandName); + exit(1); + } + + // set team debugging flags + int32 teamDebugFlags = 0; + set_team_debugging_flags(nubPort, teamDebugFlags); + + // set thread debugging flags and start profiling + if (thread >= 0) { + int32 threadDebugFlags = 0; +// if (!traceTeam) { +// threadDebugFlags = B_THREAD_DEBUG_POST_SYSCALL +// | (traceChildThreads +// ? B_THREAD_DEBUG_SYSCALL_TRACE_CHILD_THREADS : 0); +// } + set_thread_debugging_flags(nubPort, thread, threadDebugFlags); + + // start profiling + debug_nub_start_profiler_reply reply; + error = send_debug_message(&debugContext, B_DEBUG_START_PROFILER, + startProfiler, startProfilerSize, &reply, sizeof(reply)); + if (error != B_OK || (error = reply.error) != B_OK) { + fprintf(stderr, "%s: Failed to start profiler: %s\n", + kCommandName, strerror(error)); + exit(1); + } + + // resume the target thread to be sure, it's running + resume_thread(thread); + } + + // debug loop + while (true) { + bool quitLoop = false; + int32 code; + ssize_t messageSize = read_port(debuggerPort, &code, message, + maxMessageSize); + + if (messageSize < 0) { + if (messageSize == B_INTERRUPTED) + continue; + + fprintf(stderr, "%s: Reading from debugger port failed: %s\n", + kCommandName, strerror(messageSize)); + exit(1); + } + + switch (code) { + case B_DEBUGGER_MESSAGE_PROFILER_STOPPED: + printf("B_DEBUGGER_MESSAGE_PROFILER_STOPPED\n"); + printf(" total ticks: %lld, missed: %lld\n", + message->profiler_stopped.total_ticks, + message->profiler_stopped.missed_ticks); + for (int32 i = 0; i < symbolCount; i++) { + int64 hits = message->profiler_stopped.function_ticks[i]; + if (hits > 0) + printf("%10lld %s\n", hits, symbols.ItemAt(i)->Name()); + } + + break; +/* +typedef struct { + debug_origin origin; + int32 function_count; + int64 total_ticks; // total number of sample ticks + int64 missed_ticks; // ticks that didn't hit a function + int64 function_ticks[1]; // number of hits for each function +} debug_profiler_stopped; +*/ + + + case B_DEBUGGER_MESSAGE_POST_SYSCALL: + case B_DEBUGGER_MESSAGE_SIGNAL_RECEIVED: + case B_DEBUGGER_MESSAGE_THREAD_DEBUGGED: + case B_DEBUGGER_MESSAGE_DEBUGGER_CALL: + case B_DEBUGGER_MESSAGE_BREAKPOINT_HIT: + case B_DEBUGGER_MESSAGE_WATCHPOINT_HIT: + case B_DEBUGGER_MESSAGE_SINGLE_STEP: + case B_DEBUGGER_MESSAGE_PRE_SYSCALL: + case B_DEBUGGER_MESSAGE_EXCEPTION_OCCURRED: + case B_DEBUGGER_MESSAGE_TEAM_CREATED: + case B_DEBUGGER_MESSAGE_THREAD_CREATED: + case B_DEBUGGER_MESSAGE_THREAD_DELETED: + case B_DEBUGGER_MESSAGE_IMAGE_CREATED: + case B_DEBUGGER_MESSAGE_IMAGE_DELETED: + break; + + case B_DEBUGGER_MESSAGE_TEAM_DELETED: + // the debugged team is gone + quitLoop = true; + break; + } + + if (quitLoop) + break; + + // tell the thread to continue (only when there is a thread and the + // message was synchronous) + if (message->origin.thread >= 0 && message->origin.nub_port >= 0) + continue_thread(message->origin.nub_port, message->origin.thread); + } + + + + destroy_debug_context(&debugContext); + +//kill_thread(thread); +//exit(0); + + +/* +typedef struct { + debug_origin origin; + int32 function_count; + int64 total_ticks; // total number of sample ticks + int64 missed_ticks; // ticks that didn't hit a function + int64 function_ticks[1]; // number of hits for each function +} debug_profiler_stopped; + +struct debug_profile_function { + addr_t base; // function base address + size_t size; // function size +}; + +typedef struct { + port_id reply_port; // port to send the reply to + thread_id thread; // thread to profile + bigtime_t interval; // sample interval + int32 function_count; // number of functions we count hits for + struct debug_profile_function functions[1]; + // functions that shall be tracked +} debug_nub_start_profiler; +*/ + + return 0; +} Copied: haiku/trunk/src/bin/debug/strace (from rev 27393, haiku/trunk/src/bin/strace) Modified: haiku/trunk/src/bin/debug/strace/Jamfile =================================================================== --- haiku/trunk/src/bin/strace/Jamfile 2008-09-09 21:32:15 UTC (rev 27393) +++ haiku/trunk/src/bin/debug/strace/Jamfile 2008-09-15 13:45:43 UTC (rev 27533) @@ -1,4 +1,4 @@ -SubDir HAIKU_TOP src bin strace ; +SubDir HAIKU_TOP src bin debug strace ; UsePrivateHeaders device ; UsePrivateHeaders drivers ; @@ -7,6 +7,8 @@ UsePrivateHeaders net ; UsePrivateSystemHeaders ; +SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) ] ; + # find headers generated by gensyscalls SubDirHdrs $(TARGET_COMMON_DEBUG_LOCATE_TARGET) ; @@ -46,7 +48,11 @@ OPTIM = $(oldOptim) ; BinCommand strace : $(straceSources) - : $(straceSyscallsObjects) libroot.so $(TARGET_LIBSTDC++) ; + : + $(straceSyscallsObjects) + debug_utils.a + $(TARGET_LIBSTDC++) +; # We need to specify the dependency on the generated syscalls file explicitly. Includes $(straceSyscallsSource) : strace_syscalls.h ; Modified: haiku/trunk/src/bin/debug/strace/strace.cpp =================================================================== --- haiku/trunk/src/bin/strace/strace.cpp 2008-09-09 21:32:15 UTC (rev 27393) +++ haiku/trunk/src/bin/debug/strace/strace.cpp 2008-09-15 13:45:43 UTC (rev 27533) @@ -16,9 +16,10 @@ #include #include -#include #include +#include "debug_utils.h" + #include "Context.h" #include "MemoryReader.h" #include "Syscall.h" @@ -114,7 +115,7 @@ /* 22 */ "SIGTRAP", /* 23 */ "SIGPOLL", /* 24 */ "SIGPROF", - /* 25 */ "SIGSYS", + /* 25 */ "SIGSYS", /* 26 */ "SIGURG", /* 27 */ "SIGVTALRM", /* 28 */ "SIGXCPU", @@ -161,164 +162,6 @@ return true; } -// find_program -static -status_t -find_program(const char *programName, string &resolvedPath) -{ - // If the program name is absolute, then there's nothing to do. - // If the program name consists of more than one path element, then we - // consider it a relative path and don't search in PATH either. - if (*programName == '/' || strchr(programName, '/')) { - resolvedPath = programName; - return B_OK; - } - - // get the PATH environment variable - const char *paths = getenv("PATH"); - if (!paths) - return B_ENTRY_NOT_FOUND; - - // iterate through the paths - do { - const char *pathEnd = strchr(paths, ':'); - int pathLen = (pathEnd ? pathEnd - paths : strlen(paths)); - - // We skip empty paths. - if (pathLen > 0) { - // get the program path - string path(paths, pathLen); - path += "/"; - path += programName; - - // stat() the path to be sure, there is a file - struct stat st; - if (stat(path.c_str(), &st) == 0 && S_ISREG(st.st_mode)) { - resolvedPath = path; - return B_OK; - } - } - - paths = (pathEnd ? pathEnd + 1 : NULL); - } while (paths); - - // not found in PATH - return B_ENTRY_NOT_FOUND; -} - -// load_program -thread_id -load_program(const char *const *args, int32 argCount, bool traceLoading) -{ - // clone the argument vector so that we can change it - const char **mutableArgs = new const char*[argCount]; - for (int i = 0; i < argCount; i++) - mutableArgs[i] = args[i]; - - // resolve the program path - string programPath; - status_t error = find_program(args[0], programPath); - if (error != B_OK) { - delete[] mutableArgs; - return error; - } - mutableArgs[0] = programPath.c_str(); - - // count environment variables - int envCount = 0; - while (environ[envCount] != NULL) - envCount++; - - // flatten the program args and environment - char** flatArgs = NULL; - size_t flatArgsSize; - error = __flatten_process_args(mutableArgs, argCount, environ, envCount, - &flatArgs, &flatArgsSize); - - // load the program - thread_id thread; - if (error == B_OK) { - thread = _kern_load_image(flatArgs, flatArgsSize, argCount, envCount, - B_NORMAL_PRIORITY, (traceLoading ? 0 : B_WAIT_TILL_LOADED), -1, 0); - - free(flatArgs); - } else - thread = error; - - delete[] mutableArgs; - - return thread; -} - -// set_team_debugging_flags -static -void -set_team_debugging_flags(port_id nubPort, int32 flags) -{ - debug_nub_set_team_flags message; - message.flags = flags; - - while (true) { - status_t error = write_port(nubPort, B_DEBUG_MESSAGE_SET_TEAM_FLAGS, - &message, sizeof(message)); - if (error == B_OK) - return; - - if (error != B_INTERRUPTED) { - fprintf(stderr, "%s: Failed to set team debug flags: %s\n", - kCommandName, strerror(error)); - exit(1); - } - } -} - -// set_thread_debugging_flags -static -void -set_thread_debugging_flags(port_id nubPort, thread_id thread, int32 flags) -{ - debug_nub_set_thread_flags message; - message.thread = thread; - message.flags = flags; - - while (true) { - status_t error = write_port(nubPort, B_DEBUG_MESSAGE_SET_THREAD_FLAGS, - &message, sizeof(message)); - if (error == B_OK) - return; - - if (error != B_INTERRUPTED) { - fprintf(stderr, "%s: Failed to set thread debug flags: %s\n", - kCommandName, strerror(error)); - exit(1); - } - } -} - -// continue_thread -static -void -continue_thread(port_id nubPort, thread_id thread) -{ - debug_nub_continue_thread message; - message.thread = thread; - message.handle_event = B_THREAD_DEBUG_HANDLE_EVENT; - message.single_step = false; - - while (true) { - status_t error = write_port(nubPort, B_DEBUG_MESSAGE_CONTINUE_THREAD, - &message, sizeof(message)); - if (error == B_OK) - return; - - if (error != B_INTERRUPTED) { - fprintf(stderr, "%s: Failed to run thread %ld: %s\n", - kCommandName, thread, strerror(error)); - exit(1); - } - } -} - // get_syscall Syscall * get_syscall(const char *name) Modified: haiku/trunk/src/tools/gensyscalls/Jamfile =================================================================== --- haiku/trunk/src/tools/gensyscalls/Jamfile 2008-09-15 13:37:51 UTC (rev 27532) +++ haiku/trunk/src/tools/gensyscalls/Jamfile 2008-09-15 13:45:43 UTC (rev 27533) @@ -102,7 +102,7 @@ MakeLocate syscall_dispatcher.h : [ FDirName $(dir) system kernel ] ; MakeLocate syscall_numbers.h : [ FDirName $(dir) system kernel ] ; MakeLocate syscall_table.h : [ FDirName $(dir) system kernel ] ; -MakeLocate strace_syscalls.h : [ FDirName $(dir) bin strace ] ; +MakeLocate strace_syscalls.h : [ FDirName $(dir) bin debug strace ] ; rule GenSyscallsFile { Depends $(1) : gensyscalls ; From bonefish at mail.berlios.de Mon Sep 15 15:46:41 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Mon, 15 Sep 2008 15:46:41 +0200 Subject: [Haiku-commits] r27534 - haiku/trunk/build/jam Message-ID: <200809151346.m8FDkfex030771@sheep.berlios.de> Author: bonefish Date: 2008-09-15 15:46:40 +0200 (Mon, 15 Sep 2008) New Revision: 27534 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27534&view=rev Modified: haiku/trunk/build/jam/HaikuImage Log: * Added "profile" command to the image. * Enforced 80 columns limit. Modified: haiku/trunk/build/jam/HaikuImage =================================================================== --- haiku/trunk/build/jam/HaikuImage 2008-09-15 13:45:43 UTC (rev 27533) +++ haiku/trunk/build/jam/HaikuImage 2008-09-15 13:46:40 UTC (rev 27534) @@ -38,19 +38,20 @@ ideinfo idestatus ifconfig install installsound iroster isvolume join keymap kill less lessecho lesskey link listarea listattr listimage listdev listport listres listsem ln locate logger login logname ls lsindex m4 make - makebootable md5sum merge mimeset mkdos mkdir mkfifo mkfs mkindex modifiers mount - mount_nfs mountvolume mv nc netstat nl nohup od open passwd paste patch - pathchk pc ping play playfile playsound playwav pr prio printenv printf ps - ptx pwd query quit rc readlink release renice rescan rlog rm rmattr rmindex - rmdir roster route safemode screen_blanker screenmode sed setdecor settype setversion - setvolume seq sh sha1sum shar shred shuf shutdown sleep sort split stat - strace stty su sum sync sysinfo tac tail tar tcpdump tcptester tee telnet - telnetd test top touch tput tr traceroute - translate true tsort tty uname unchop unexpand unmount uniq unrar unshar - unzip unzipsfx updatedb uptime urlwrapper usb_dev_info useradd uudecode - uuencode vdir - version vim waitfor wc wget whoami xargs xres yes zdiff zforce zgrep zip - zipcloak zipgrep zipnote zipsplit zmore znew + makebootable md5sum merge mimeset mkdos mkdir mkfifo mkfs mkindex modifiers + mount mount_nfs mountvolume mv nc netstat nl nohup od open passwd paste + patch pathchk pc ping play playfile playsound playwav pr prio printenv + printf profile ps ptx pwd query quit rc readlink release renice rescan rlog + rm rmattr rmindex rmdir roster route + safemode screen_blanker screenmode sed setdecor settype setversion setvolume + seq sh sha1sum shar shred shuf shutdown sleep sort split stat strace stty su + sum sync sysinfo + tac tail tar tcpdump tcptester tee telnet telnetd test top touch tput tr + traceroute translate true tsort tty + uname unchop unexpand unmount uniq unrar unshar unzip unzipsfx updatedb + uptime urlwrapper usb_dev_info useradd uudecode uuencode + vdir version vim waitfor wc wget whoami xargs xres yes + zdiff zforce zgrep zip zipcloak zipgrep zipnote zipsplit zmore znew ; BEOS_APPS = AboutSystem ActivityMonitor CodyCam DeskCalc DiskProbe DiskUsage From dlmcpaul at mail.berlios.de Mon Sep 15 15:51:10 2008 From: dlmcpaul at mail.berlios.de (dlmcpaul at BerliOS) Date: Mon, 15 Sep 2008 15:51:10 +0200 Subject: [Haiku-commits] r27535 - haiku/trunk/src/add-ons/media/plugins/avcodec Message-ID: <200809151351.m8FDpAWL031256@sheep.berlios.de> Author: dlmcpaul Date: 2008-09-15 15:51:10 +0200 (Mon, 15 Sep 2008) New Revision: 27535 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27535&view=rev Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/ Log: Update avcodec to 20080825 From dlmcpaul at mail.berlios.de Mon Sep 15 15:51:41 2008 From: dlmcpaul at mail.berlios.de (dlmcpaul at BerliOS) Date: Mon, 15 Sep 2008 15:51:41 +0200 Subject: [Haiku-commits] r27536 - haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil Message-ID: <200809151351.m8FDpf8x031383@sheep.berlios.de> Author: dlmcpaul Date: 2008-09-15 15:51:33 +0200 (Mon, 15 Sep 2008) New Revision: 27536 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27536&view=rev Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/Jamfile haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/adler32.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/adler32.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/aes.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/aes.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/avstring.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/avutil.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/base64.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/base64.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/bswap.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/common.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/crc.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/crc.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/crc_data.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/des.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/des.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/fifo.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/fifo.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/integer.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/integer.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/internal.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/intfloat_readwrite.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/intfloat_readwrite.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/intreadwrite.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/lfg.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/lfg.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/lls.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/lls.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/log.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/log.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/lzo.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/lzo.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/mathematics.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/mathematics.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/md5.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/md5.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/mem.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/mem.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/pca.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/pca.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/random.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/random.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/rational.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/rational.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/rc4.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/rc4.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/sha1.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/sha1.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/softfloat.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/softfloat.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/string.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/tree.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/tree.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/utils.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/x86_cpu.h Log: Update avcodec to 20080825 Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/Jamfile =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/Jamfile 2008-09-15 13:51:10 UTC (rev 27535) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/Jamfile 2008-09-15 13:51:33 UTC (rev 27536) @@ -0,0 +1,35 @@ +SubDir HAIKU_TOP src add-ons media plugins avcodec libavutil ; + +# filter warnings we don't want here +TARGET_WARNING_CCFLAGS = [ FFilter $(TARGET_WARNING_CCFLAGS) + : -Wall -Wmissing-prototypes -Wsign-compare -Wpointer-arith ] ; + +SubDirCcFlags -fomit-frame-pointer -DPIC ; +SubDirCcFlags -DHAVE_AV_CONFIG_H=1 ; + +StaticLibrary libavutil.a : + adler32.c + aes.c + base64.c + crc.c + des.c + fifo.c + integer.c + intfloat_readwrite.c + lfg.c + lls.c + log.c + lzo.c + mathematics.c + md5.c + mem.c + pca.c + random.c + rational.c + rc4.c + sha1.c + softfloat.c + string.c + tree.c + utils.c +; Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/adler32.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/adler32.c 2008-09-15 13:51:10 UTC (rev 27535) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/adler32.c 2008-09-15 13:51:33 UTC (rev 27536) @@ -0,0 +1,71 @@ +/* adler32.c -- compute the Adler-32 checksum of a data stream + * This is a modified version based on adler32.c from the zlib library. + * + * Copyright (C) 1995 Mark Adler + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + */ + +#include "common.h" +#include "adler32.h" + +#define BASE 65521L /* largest prime smaller than 65536 */ + +#define DO1(buf) {s1 += *buf++; s2 += s1;} +#define DO4(buf) DO1(buf); DO1(buf); DO1(buf); DO1(buf); +#define DO16(buf) DO4(buf); DO4(buf); DO4(buf); DO4(buf); + +unsigned long av_adler32_update(unsigned long adler, const uint8_t *buf, unsigned int len) +{ + unsigned long s1 = adler & 0xffff; + unsigned long s2 = adler >> 16; + + while (len>0) { +#ifdef CONFIG_SMALL + while(len>4 && s2 < (1U<<31)){ + DO4(buf); len-=4; +#else + while(len>16 && s2 < (1U<<31)){ + DO16(buf); len-=16; +#endif + } + DO1(buf); len--; + s1 %= BASE; + s2 %= BASE; + } + return (s2 << 16) | s1; +} + +#ifdef TEST +#include "log.h" +#define LEN 7001 +volatile int checksum; +int main(void){ + int i; + char data[LEN]; + av_log_level = AV_LOG_DEBUG; + for(i=0; i>3) + 123*i; + for(i=0; i<1000; i++){ + START_TIMER + checksum= av_adler32_update(1, data, LEN); + STOP_TIMER("adler") + } + av_log(NULL, AV_LOG_DEBUG, "%X == 50E6E508\n", checksum); + return 0; +} +#endif Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/adler32.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/adler32.h 2008-09-15 13:51:10 UTC (rev 27535) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/adler32.h 2008-09-15 13:51:33 UTC (rev 27536) @@ -0,0 +1,30 @@ +/* + * copyright (c) 2006 Mans Rullgard + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_ADLER32_H +#define FFMPEG_ADLER32_H + +#include +#include "common.h" + +unsigned long av_adler32_update(unsigned long adler, const uint8_t *buf, + unsigned int len) av_pure; + +#endif /* FFMPEG_ADLER32_H */ Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/aes.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/aes.c 2008-09-15 13:51:10 UTC (rev 27535) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/aes.c 2008-09-15 13:51:33 UTC (rev 27536) @@ -0,0 +1,243 @@ +/* + * copyright (c) 2007 Michael Niedermayer + * + * some optimization ideas from aes128.c by Reimar Doeffinger + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "common.h" +#include "aes.h" + +typedef struct AVAES{ + // Note: round_key[16] is accessed in the init code, but this only + // overwrites state, which does not matter (see also r7471). + uint8_t round_key[15][4][4]; + uint8_t state[2][4][4]; + int rounds; +}AVAES; + +const int av_aes_size= sizeof(AVAES); + +static const uint8_t rcon[10] = { + 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36 +}; + +static uint8_t sbox[256]; +static uint8_t inv_sbox[256]; +#ifdef CONFIG_SMALL +static uint32_t enc_multbl[1][256]; +static uint32_t dec_multbl[1][256]; +#else +static uint32_t enc_multbl[4][256]; +static uint32_t dec_multbl[4][256]; +#endif + +static inline void addkey(uint64_t dst[2], uint64_t src[2], uint64_t round_key[2]){ + dst[0] = src[0] ^ round_key[0]; + dst[1] = src[1] ^ round_key[1]; +} + +static void subshift(uint8_t s0[2][16], int s, uint8_t *box){ + uint8_t (*s1)[16]= s0[0] - s; + uint8_t (*s3)[16]= s0[0] + s; + s0[0][0]=box[s0[1][ 0]]; s0[0][ 4]=box[s0[1][ 4]]; s0[0][ 8]=box[s0[1][ 8]]; s0[0][12]=box[s0[1][12]]; + s1[0][3]=box[s1[1][ 7]]; s1[0][ 7]=box[s1[1][11]]; s1[0][11]=box[s1[1][15]]; s1[0][15]=box[s1[1][ 3]]; + s0[0][2]=box[s0[1][10]]; s0[0][10]=box[s0[1][ 2]]; s0[0][ 6]=box[s0[1][14]]; s0[0][14]=box[s0[1][ 6]]; + s3[0][1]=box[s3[1][13]]; s3[0][13]=box[s3[1][ 9]]; s3[0][ 9]=box[s3[1][ 5]]; s3[0][ 5]=box[s3[1][ 1]]; +} + +static inline int mix_core(uint32_t multbl[4][256], int a, int b, int c, int d){ +#ifdef CONFIG_SMALL +#define ROT(x,s) ((x<>(32-s))) + return multbl[0][a] ^ ROT(multbl[0][b], 8) ^ ROT(multbl[0][c], 16) ^ ROT(multbl[0][d], 24); +#else + return multbl[0][a] ^ multbl[1][b] ^ multbl[2][c] ^ multbl[3][d]; +#endif +} + +static inline void mix(uint8_t state[2][4][4], uint32_t multbl[4][256], int s1, int s3){ + ((uint32_t *)(state))[0] = mix_core(multbl, state[1][0][0], state[1][s1 ][1], state[1][2][2], state[1][s3 ][3]); + ((uint32_t *)(state))[1] = mix_core(multbl, state[1][1][0], state[1][s3-1][1], state[1][3][2], state[1][s1-1][3]); + ((uint32_t *)(state))[2] = mix_core(multbl, state[1][2][0], state[1][s3 ][1], state[1][0][2], state[1][s1 ][3]); + ((uint32_t *)(state))[3] = mix_core(multbl, state[1][3][0], state[1][s1-1][1], state[1][1][2], state[1][s3-1][3]); +} + +static inline void crypt(AVAES *a, int s, uint8_t *sbox, uint32_t *multbl){ + int r; + + for(r=a->rounds-1; r>0; r--){ + mix(a->state, multbl, 3-s, 1+s); + addkey(a->state[1], a->state[0], a->round_key[r]); + } + subshift(a->state[0][0], s, sbox); +} + +void av_aes_crypt(AVAES *a, uint8_t *dst, uint8_t *src, int count, uint8_t *iv, int decrypt){ + while(count--){ + addkey(a->state[1], src, a->round_key[a->rounds]); + if(decrypt) { + crypt(a, 0, inv_sbox, dec_multbl); + if(iv){ + addkey(a->state[0], a->state[0], iv); + memcpy(iv, src, 16); + } + addkey(dst, a->state[0], a->round_key[0]); + }else{ + if(iv) addkey(a->state[1], a->state[1], iv); + crypt(a, 2, sbox, enc_multbl); + addkey(dst, a->state[0], a->round_key[0]); + if(iv) memcpy(iv, dst, 16); + } + src+=16; + dst+=16; + } +} + +static void init_multbl2(uint8_t tbl[1024], int c[4], uint8_t *log8, uint8_t *alog8, uint8_t *sbox){ + int i, j; + for(i=0; i<1024; i++){ + int x= sbox[i>>2]; + if(x) tbl[i]= alog8[ log8[x] + log8[c[i&3]] ]; + } +#ifndef CONFIG_SMALL + for(j=256; j<1024; j++) + for(i=0; i<4; i++) + tbl[4*j+i]= tbl[4*j + ((i-1)&3) - 1024]; +#endif +} + +// this is based on the reference AES code by Paulo Barreto and Vincent Rijmen +int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt) { + int i, j, t, rconpointer = 0; + uint8_t tk[8][4]; + int KC= key_bits>>5; + int rounds= KC + 6; + uint8_t log8[256]; + uint8_t alog8[512]; + + if(!enc_multbl[0][sizeof(enc_multbl)/sizeof(enc_multbl[0][0])-1]){ + j=1; + for(i=0; i<255; i++){ + alog8[i]= + alog8[i+255]= j; + log8[j]= i; + j^= j+j; + if(j>255) j^= 0x11B; + } + for(i=0; i<256; i++){ + j= i ? alog8[255-log8[i]] : 0; + j ^= (j<<1) ^ (j<<2) ^ (j<<3) ^ (j<<4); + j = (j ^ (j>>8) ^ 99) & 255; + inv_sbox[j]= i; + sbox [i]= j; + } + init_multbl2(dec_multbl[0], (int[4]){0xe, 0x9, 0xd, 0xb}, log8, alog8, inv_sbox); + init_multbl2(enc_multbl[0], (int[4]){0x2, 0x1, 0x1, 0x3}, log8, alog8, sbox); + } + + if(key_bits!=128 && key_bits!=192 && key_bits!=256) + return -1; + + a->rounds= rounds; + + memcpy(tk, key, KC*4); + + for(t= 0; t < (rounds+1)*16;) { + memcpy(a->round_key[0][0]+t, tk, KC*4); + t+= KC*4; + + for(i = 0; i < 4; i++) + tk[0][i] ^= sbox[tk[KC-1][(i+1)&3]]; + tk[0][0] ^= rcon[rconpointer++]; + + for(j = 1; j < KC; j++){ + if(KC != 8 || j != KC>>1) + for(i = 0; i < 4; i++) tk[j][i] ^= tk[j-1][i]; + else + for(i = 0; i < 4; i++) tk[j][i] ^= sbox[tk[j-1][i]]; + } + } + + if(decrypt){ + for(i=1; iround_key[i][0], 16); + subshift(tmp[1], 0, sbox); + mix(tmp, dec_multbl, 1, 3); + memcpy(a->round_key[i][0], tmp[0], 16); + } + }else{ + for(i=0; i<(rounds+1)>>1; i++){ + for(j=0; j<16; j++) + FFSWAP(int, a->round_key[i][0][j], a->round_key[rounds-i][0][j]); + } + } + + return 0; +} + +#ifdef TEST +#include "log.h" + +#undef random + +int main(void){ + int i,j; + AVAES ae, ad, b; + uint8_t rkey[2][16]= { + {0}, + {0x10, 0xa5, 0x88, 0x69, 0xd7, 0x4b, 0xe5, 0xa3, 0x74, 0xcf, 0x86, 0x7c, 0xfb, 0x47, 0x38, 0x59}}; + uint8_t pt[16], rpt[2][16]= { + {0x6a, 0x84, 0x86, 0x7c, 0xd7, 0x7e, 0x12, 0xad, 0x07, 0xea, 0x1b, 0xe8, 0x95, 0xc5, 0x3f, 0xa3}, + {0}}; + uint8_t rct[2][16]= { + {0x73, 0x22, 0x81, 0xc0, 0xa0, 0xaa, 0xb8, 0xf7, 0xa5, 0x4a, 0x0c, 0x67, 0xa0, 0xc4, 0x5e, 0xcf}, + {0x6d, 0x25, 0x1e, 0x69, 0x44, 0xb0, 0x51, 0xe0, 0x4e, 0xaa, 0x6f, 0xb4, 0xdb, 0xf7, 0x84, 0x65}}; + uint8_t temp[16]; + + av_aes_init(&ae, "PI=3.141592654..", 128, 0); + av_aes_init(&ad, "PI=3.141592654..", 128, 1); + av_log_level= AV_LOG_DEBUG; + + for(i=0; i<2; i++){ + av_aes_init(&b, rkey[i], 128, 1); + av_aes_crypt(&b, temp, rct[i], 1, NULL, 1); + for(j=0; j<16; j++) + if(rpt[i][j] != temp[j]) + av_log(NULL, AV_LOG_ERROR, "%d %02X %02X\n", j, rpt[i][j], temp[j]); + } + + for(i=0; i<10000; i++){ + for(j=0; j<16; j++){ + pt[j]= random(); + } +{START_TIMER + av_aes_crypt(&ae, temp, pt, 1, NULL, 0); + if(!(i&(i-1))) + av_log(NULL, AV_LOG_ERROR, "%02X %02X %02X %02X\n", temp[0], temp[5], temp[10], temp[15]); + av_aes_crypt(&ad, temp, temp, 1, NULL, 1); +STOP_TIMER("aes")} + for(j=0; j<16; j++){ + if(pt[j] != temp[j]){ + av_log(NULL, AV_LOG_ERROR, "%d %d %02X %02X\n", i,j, pt[j], temp[j]); + } + } + } + return 0; +} +#endif Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/aes.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/aes.h 2008-09-15 13:51:10 UTC (rev 27535) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/aes.h 2008-09-15 13:51:33 UTC (rev 27536) @@ -0,0 +1,47 @@ +/* + * copyright (c) 2007 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_AES_H +#define FFMPEG_AES_H + +#include + +extern const int av_aes_size; + +struct AVAES; + +/** + * Initializes an AVAES context. + * @param key_bits 128, 192 or 256 + * @param decrypt 0 for encryption, 1 for decryption + */ +int av_aes_init(struct AVAES *a, const uint8_t *key, int key_bits, int decrypt); + +/** + * Encrypts / decrypts. + * @param count number of 16 byte blocks + * @param dst destination array, can be equal to src + * @param src source array, can be equal to dst + * @param iv initialization vector for CBC mode, if NULL then ECB will be used + * @param decrypt 0 for encryption, 1 for decryption + */ +void av_aes_crypt(struct AVAES *a, uint8_t *dst, uint8_t *src, int count, uint8_t *iv, int decrypt); + +#endif /* FFMPEG_AES_H */ Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/avstring.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/avstring.h 2008-09-15 13:51:10 UTC (rev 27535) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/avstring.h 2008-09-15 13:51:33 UTC (rev 27536) @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2007 Mans Rullgard + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_AVSTRING_H +#define FFMPEG_AVSTRING_H + +#include + +/** + * Return non-zero if pfx is a prefix of str. If it is, *ptr is set to + * the address of the first character in str after the prefix. + * + * @param str input string + * @param pfx prefix to test + * @param ptr updated after the prefix in str in there is a match + * @return non-zero if the prefix matches, zero otherwise + */ +int av_strstart(const char *str, const char *pfx, const char **ptr); + +/** + * Return non-zero if pfx is a prefix of str independent of case. If + * it is, *ptr is set to the address of the first character in str + * after the prefix. + * + * @param str input string + * @param pfx prefix to test + * @param ptr updated after the prefix in str in there is a match + * @return non-zero if the prefix matches, zero otherwise + */ +int av_stristart(const char *str, const char *pfx, const char **ptr); + +/** + * Copy the string src to dst, but no more than size - 1 bytes, and + * null terminate dst. + * + * This function is the same as BSD strlcpy(). + * + * @param dst destination buffer + * @param src source string + * @param size size of destination buffer + * @return the length of src + */ +size_t av_strlcpy(char *dst, const char *src, size_t size); + +/** + * Append the string src to the string dst, but to a total length of + * no more than size - 1 bytes, and null terminate dst. + * + * This function is similar to BSD strlcat(), but differs when + * size <= strlen(dst). + * + * @param dst destination buffer + * @param src source string + * @param size size of destination buffer + * @return the total length of src and dst + */ +size_t av_strlcat(char *dst, const char *src, size_t size); + +/** + * Append output to a string, according to a format. Never write out of + * the destination buffer, and and always put a terminating 0 within + * the buffer. + * @param dst destination buffer (string to which the output is + * appended) + * @param size total size of the destination buffer + * @param fmt printf-compatible format string, specifying how the + * following parameters are used + * @return the length of the string that would have been generated + * if enough space had been available + */ +size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...); + +#endif /* FFMPEG_AVSTRING_H */ Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/avutil.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/avutil.h 2008-09-15 13:51:10 UTC (rev 27535) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/avutil.h 2008-09-15 13:51:33 UTC (rev 27536) @@ -0,0 +1,147 @@ +/* + * copyright (c) 2006 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_AVUTIL_H +#define FFMPEG_AVUTIL_H + +/** + * @file avutil.h + * external API header + */ + + +#define AV_STRINGIFY(s) AV_TOSTRING(s) +#define AV_TOSTRING(s) #s + +#define AV_VERSION_INT(a, b, c) (a<<16 | b<<8 | c) +#define AV_VERSION_DOT(a, b, c) a ##.## b ##.## c +#define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c) + +#define LIBAVUTIL_VERSION_MAJOR 49 +#define LIBAVUTIL_VERSION_MINOR 10 +#define LIBAVUTIL_VERSION_MICRO 0 + +#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ + LIBAVUTIL_VERSION_MINOR, \ + LIBAVUTIL_VERSION_MICRO) +#define LIBAVUTIL_VERSION AV_VERSION(LIBAVUTIL_VERSION_MAJOR, \ + LIBAVUTIL_VERSION_MINOR, \ + LIBAVUTIL_VERSION_MICRO) +#define LIBAVUTIL_BUILD LIBAVUTIL_VERSION_INT + +#define LIBAVUTIL_IDENT "Lavu" AV_STRINGIFY(LIBAVUTIL_VERSION) + +/** + * Returns the LIBAVUTIL_VERSION_INT constant. + */ +unsigned avutil_version(void); + +#include "common.h" +#include "mathematics.h" +#include "rational.h" +#include "intfloat_readwrite.h" +#include "log.h" + +/** + * Pixel format. Notes: + * + * PIX_FMT_RGB32 is handled in an endian-specific manner. A RGBA + * color is put together as: + * (A << 24) | (R << 16) | (G << 8) | B + * This is stored as BGRA on little endian CPU architectures and ARGB on + * big endian CPUs. + * + * When the pixel format is palettized RGB (PIX_FMT_PAL8), the palettized + * image data is stored in AVFrame.data[0]. The palette is transported in + * AVFrame.data[1] and, is 1024 bytes long (256 4-byte entries) and is + * formatted the same as in PIX_FMT_RGB32 described above (i.e., it is + * also endian-specific). Note also that the individual RGB palette + * components stored in AVFrame.data[1] should be in the range 0..255. + * This is important as many custom PAL8 video codecs that were designed + * to run on the IBM VGA graphics adapter use 6-bit palette components. + */ +enum PixelFormat { + PIX_FMT_NONE= -1, + PIX_FMT_YUV420P, ///< Planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples) + PIX_FMT_YUYV422, ///< Packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr + PIX_FMT_RGB24, ///< Packed RGB 8:8:8, 24bpp, RGBRGB... + PIX_FMT_BGR24, ///< Packed RGB 8:8:8, 24bpp, BGRBGR... + PIX_FMT_YUV422P, ///< Planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples) + PIX_FMT_YUV444P, ///< Planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples) + PIX_FMT_RGB32, ///< Packed RGB 8:8:8, 32bpp, (msb)8A 8R 8G 8B(lsb), in cpu endianness + PIX_FMT_YUV410P, ///< Planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples) + PIX_FMT_YUV411P, ///< Planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) + PIX_FMT_RGB565, ///< Packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), in cpu endianness + PIX_FMT_RGB555, ///< Packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), in cpu endianness most significant bit to 0 + PIX_FMT_GRAY8, ///< Y , 8bpp + PIX_FMT_MONOWHITE, ///< Y , 1bpp, 0 is white, 1 is black + PIX_FMT_MONOBLACK, ///< Y , 1bpp, 0 is black, 1 is white + PIX_FMT_PAL8, ///< 8 bit with PIX_FMT_RGB32 palette + PIX_FMT_YUVJ420P, ///< Planar YUV 4:2:0, 12bpp, full scale (jpeg) + PIX_FMT_YUVJ422P, ///< Planar YUV 4:2:2, 16bpp, full scale (jpeg) + PIX_FMT_YUVJ444P, ///< Planar YUV 4:4:4, 24bpp, full scale (jpeg) + PIX_FMT_XVMC_MPEG2_MC,///< XVideo Motion Acceleration via common packet passing(xvmc_render.h) + PIX_FMT_XVMC_MPEG2_IDCT, + PIX_FMT_UYVY422, ///< Packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1 + PIX_FMT_UYYVYY411, ///< Packed YUV 4:1:1, 12bpp, Cb Y0 Y1 Cr Y2 Y3 + PIX_FMT_BGR32, ///< Packed RGB 8:8:8, 32bpp, (msb)8A 8B 8G 8R(lsb), in cpu endianness + PIX_FMT_BGR565, ///< Packed RGB 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), in cpu endianness + PIX_FMT_BGR555, ///< Packed RGB 5:5:5, 16bpp, (msb)1A 5B 5G 5R(lsb), in cpu endianness most significant bit to 1 + PIX_FMT_BGR8, ///< Packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb) + PIX_FMT_BGR4, ///< Packed RGB 1:2:1, 4bpp, (msb)1B 2G 1R(lsb) + PIX_FMT_BGR4_BYTE, ///< Packed RGB 1:2:1, 8bpp, (msb)1B 2G 1R(lsb) + PIX_FMT_RGB8, ///< Packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb) + PIX_FMT_RGB4, ///< Packed RGB 1:2:1, 4bpp, (msb)2R 3G 3B(lsb) + PIX_FMT_RGB4_BYTE, ///< Packed RGB 1:2:1, 8bpp, (msb)2R 3G 3B(lsb) + PIX_FMT_NV12, ///< Planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 for UV + PIX_FMT_NV21, ///< as above, but U and V bytes are swapped + + PIX_FMT_RGB32_1, ///< Packed RGB 8:8:8, 32bpp, (msb)8R 8G 8B 8A(lsb), in cpu endianness + PIX_FMT_BGR32_1, ///< Packed RGB 8:8:8, 32bpp, (msb)8B 8G 8R 8A(lsb), in cpu endianness + + PIX_FMT_GRAY16BE, ///< Y , 16bpp, big-endian + PIX_FMT_GRAY16LE, ///< Y , 16bpp, little-endian + PIX_FMT_YUV440P, ///< Planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples) + PIX_FMT_YUVJ440P, ///< Planar YUV 4:4:0 full scale (jpeg) + PIX_FMT_YUVA420P, ///< Planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples) + PIX_FMT_NB, ///< number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of formats might differ between versions +}; + +#ifdef WORDS_BIGENDIAN +#define PIX_FMT_RGBA PIX_FMT_RGB32_1 +#define PIX_FMT_BGRA PIX_FMT_BGR32_1 +#define PIX_FMT_ARGB PIX_FMT_RGB32 +#define PIX_FMT_ABGR PIX_FMT_BGR32 +#define PIX_FMT_GRAY16 PIX_FMT_GRAY16BE +#else +#define PIX_FMT_RGBA PIX_FMT_BGR32 +#define PIX_FMT_BGRA PIX_FMT_RGB32 +#define PIX_FMT_ARGB PIX_FMT_BGR32_1 +#define PIX_FMT_ABGR PIX_FMT_RGB32_1 +#define PIX_FMT_GRAY16 PIX_FMT_GRAY16LE +#endif + +#if LIBAVUTIL_VERSION_INT < (50<<16) +#define PIX_FMT_UYVY411 PIX_FMT_UYYVYY411 +#define PIX_FMT_RGBA32 PIX_FMT_RGB32 +#define PIX_FMT_YUV422 PIX_FMT_YUYV422 +#endif + +#endif /* FFMPEG_AVUTIL_H */ Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/base64.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/base64.c 2008-09-15 13:51:10 UTC (rev 27535) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/base64.c 2008-09-15 13:51:33 UTC (rev 27536) @@ -0,0 +1,228 @@ +/* + * Base64.c + * Copyright (c) 2006 Ryan Martell. (rdm4 at martellventures.com) + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** +* @file base64.c + * @brief Base64 Encode/Decode + * @author Ryan Martell (with lots of Michael) + */ + +#include "common.h" +#include "base64.h" + +/* ---------------- private code */ +static const uint8_t map2[] = +{ + 0x3e, 0xff, 0xff, 0xff, 0x3f, 0x34, 0x35, 0x36, + 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x01, + 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, + 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, + 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1a, 0x1b, + 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, + 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, + 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33 +}; + +int av_base64_decode(uint8_t * out, const char *in, int out_length) +{ + int i, v; + uint8_t *dst = out; + + v = 0; + for (i = 0; in[i] && in[i] != '='; i++) { + unsigned int index= in[i]-43; + if (index>=(sizeof(map2)/sizeof(map2[0])) || map2[index] == 0xff) + return -1; + v = (v << 6) + map2[index]; + if (i & 3) { + if (dst - out < out_length) { + *dst++ = v >> (6 - 2 * (i & 3)); + } + } + } + + return dst - out; +} + +/***************************************************************************** +* b64_encode: stolen from VLC's http.c +* simplified by michael +* fixed edge cases and made it work from data (vs. strings) by ryan. +*****************************************************************************/ + +char *av_base64_encode(char * buf, int buf_len, const uint8_t * src, int len) +{ + static const char b64[] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + char *ret, *dst; + unsigned i_bits = 0; + int i_shift = 0; + int bytes_remaining = len; + + if (len >= UINT_MAX / 4 || + buf_len < len * 4 / 3 + 12) + return NULL; + ret = dst = buf; + while (bytes_remaining) { + i_bits = (i_bits << 8) + *src++; + bytes_remaining--; + i_shift += 8; + + do { + *dst++ = b64[(i_bits << 6 >> i_shift) & 0x3f]; + i_shift -= 6; + } while (i_shift > 6 || (bytes_remaining == 0 && i_shift > 0)); + } + while ((dst - ret) & 3) + *dst++ = '='; + *dst = '\0'; + + return ret; +} + +// #define TEST_BASE64 + +#ifdef TEST_BASE64 +#include "avutil.h" + +int b64test() +{ + int numerr = 0; + int len; + int numtest = 1; + uint8_t decode[1000]; + struct test { + void *data; + int len; + const char *result; + } *t, tests[] = { + { + "", 0, ""}, { + "1", 1, "MQ=="}, { + "22", 2, "MjI="}, { + "333", 3, "MzMz"}, { + "4444", 4, "NDQ0NA=="}, { + "55555", 5, "NTU1NTU="}, { + "abc:def", 7, "YWJjOmRlZg=="}, { + NULL} + }; + for (t = tests; t->data; t++) { + char *str; + + av_log(NULL, AV_LOG_ERROR, "Encoding %s...\n", (char *) t->data); + str = av_base64_encode(t->data, t->len); + if (str) { + av_log(NULL, AV_LOG_ERROR, "Encoded to %s...\n", str); + if (strcmp(str, t->result) != 0) { + av_log(NULL, AV_LOG_ERROR, "failed test %d: %s != %s\n", + numtest, str, t->result); + numerr++; + } + av_free(str); + } + + av_log(NULL, AV_LOG_ERROR, "Done encoding, about to decode...\n"); + len = av_base64_decode(decode, t->result, sizeof(decode)); + if (len != t->len) { + av_log(NULL, AV_LOG_ERROR, "failed test %d: len %d != %d\n", + numtest, len, t->len); + numerr++; + } else if (memcmp(decode, t->data, t->len) != 0) { + av_log(NULL, AV_LOG_ERROR, "failed test %d: data\n", numtest); + numerr++; + } else { + av_log(NULL, AV_LOG_ERROR, "Decoded to %s\n", + (char *) t->data); + } + numtest++; + } + +#undef srand +#undef rand + + { + int test_count; + srand(123141); // time(NULL)); + for (test_count = 0; test_count < 100; test_count++) { + int size = rand() % 1024; + int ii; + uint8_t *data; + char *encoded_result; + + av_log(NULL, AV_LOG_ERROR, "Test %d: Size %d bytes...", + test_count, size); + data = (uint8_t *) av_malloc(size); + for (ii = 0; ii < size; ii++) { + data[ii] = rand() % 255; + } + + encoded_result = av_base64_encode(data, size); + if (encoded_result) { + int decode_buffer_size = size + 10; // try without 10 as well + uint8_t *decode_buffer = av_malloc(decode_buffer_size); + if (decode_buffer) { + int decoded_size = + av_base64_decode(decode_buffer, encoded_result, + decode_buffer_size); + + if (decoded_size != size) { + av_log(NULL, AV_LOG_ERROR, + "Decoded/Encoded size mismatch (%d != %d)\n", + decoded_size, size); + } else { + if (memcmp(decode_buffer, data, decoded_size) == 0) { + av_log(NULL, AV_LOG_ERROR, "Passed!\n"); + } else { + av_log(NULL, AV_LOG_ERROR, + "Failed (Data differs)!\n"); + } + } + av_free(decode_buffer); + } + + av_free(encoded_result); + } + } + } + + // these are invalid strings, that it currently decodes (which it probably shouldn't?) + { + uint8_t str[32]; + if (av_base64_decode(str, "M=M=", sizeof(str)) != -1) { + av_log(NULL, AV_LOG_ERROR, + "failed test %d: successful decode of `M=M='\n", + numtest++); + numerr++; + } + if (av_base64_decode(str, "MQ===", sizeof(str)) != -1) { + av_log(NULL, AV_LOG_ERROR, + "failed test %d: successful decode of `MQ==='\n", + numtest++); + numerr++; + } + } + + return numerr; +} +#endif + Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/base64.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/base64.h 2008-09-15 13:51:10 UTC (rev 27535) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/base64.h 2008-09-15 13:51:33 UTC (rev 27536) @@ -0,0 +1,40 @@ +/* + * Base64.c + * Copyright (c) 2006 Ryan Martell. (rdm4 at martellventures.com) + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_BASE64_H +#define FFMPEG_BASE64_H + +#include + +/** + * decodes base64 + * param order as strncpy() + */ +int av_base64_decode(uint8_t * out, const char *in, int out_length); + +/** + * encodes base64 + * @param src data, not a string + * @param buf output string + */ +char *av_base64_encode(char * buf, int buf_len, const uint8_t * src, int len); + +#endif /* FFMPEG_BASE64_H */ Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/bswap.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/bswap.h 2008-09-15 13:51:10 UTC (rev 27535) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavutil/bswap.h 2008-09-15 13:51:33 UTC (rev 27536) @@ -0,0 +1,132 @@ +/* + * copyright (c) 2006 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * [... truncated: 5926 lines follow ...] From dlmcpaul at mail.berlios.de Mon Sep 15 15:52:29 2008 From: dlmcpaul at mail.berlios.de (dlmcpaul at BerliOS) Date: Mon, 15 Sep 2008 15:52:29 +0200 Subject: [Haiku-commits] r27537 - haiku/trunk/src/add-ons/media/plugins/avcodec Message-ID: <200809151352.m8FDqTOE031458@sheep.berlios.de> Author: dlmcpaul Date: 2008-09-15 15:52:29 +0200 (Mon, 15 Sep 2008) New Revision: 27537 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27537&view=rev Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/ Log: Update avcodec to 20080825 From dlmcpaul at mail.berlios.de Mon Sep 15 15:52:51 2008 From: dlmcpaul at mail.berlios.de (dlmcpaul at BerliOS) Date: Mon, 15 Sep 2008 15:52:51 +0200 Subject: [Haiku-commits] r27538 - haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale Message-ID: <200809151352.m8FDqpLe031497@sheep.berlios.de> Author: dlmcpaul Date: 2008-09-15 15:52:45 +0200 (Mon, 15 Sep 2008) New Revision: 27538 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27538&view=rev Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/Jamfile haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/config.h haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/cs_test.c haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/internal_bfin.S haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/rgb2rgb.c haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/rgb2rgb.h haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/rgb2rgb_template.c haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/swscale-example.c haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/swscale.c haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/swscale.h haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/swscale_altivec_template.c haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/swscale_avoption.c haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/swscale_bfin.c haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/swscale_internal.h haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/swscale_template.c haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/yuv2rgb.c haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/yuv2rgb_altivec.c haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/yuv2rgb_bfin.c haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/yuv2rgb_mlib.c haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/yuv2rgb_template.c haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/yuv2rgb_vis.c Log: Update avcodec to 20080825 Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/Jamfile =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/Jamfile 2008-09-15 13:52:29 UTC (rev 27537) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/Jamfile 2008-09-15 13:52:45 UTC (rev 27538) @@ -0,0 +1,18 @@ +SubDir HAIKU_TOP src add-ons media plugins avcodec libswscale ; + +SubDirHdrs [ FDirName $(SUBDIR) ../libavutil ] ; +SubDirHdrs [ FDirName $(SUBDIR) ../libavcodec ] ; + +# filter warnings we don't want here +TARGET_WARNING_CCFLAGS = [ FFilter $(TARGET_WARNING_CCFLAGS) + : -Wall -Wmissing-prototypes -Wsign-compare -Wpointer-arith ] ; + +SubDirCcFlags -fomit-frame-pointer -DPIC ; +SubDirCcFlags -DHAVE_AV_CONFIG_H=1 ; + +StaticLibrary libswscale.a : + rgb2rgb.c + swscale.c + swscale_avoption.c + yuv2rgb.c +; Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/config.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/config.h 2008-09-15 13:52:29 UTC (rev 27537) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/config.h 2008-09-15 13:52:45 UTC (rev 27538) @@ -0,0 +1 @@ +link /boot/home/programming/haiku/src/add-ons/media/plugins/avcodec/libavcodec/config.h \ No newline at end of file Property changes on: haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/config.h ___________________________________________________________________ Name: svn:special + * Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/cs_test.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/cs_test.c 2008-09-15 13:52:29 UTC (rev 27537) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/cs_test.c 2008-09-15 13:52:45 UTC (rev 27538) @@ -0,0 +1,175 @@ +/* + * Copyright (C) 2002 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include /* for memset() */ +#include +#include +#include + +#include "swscale.h" +#include "rgb2rgb.h" + +#define SIZE 1000 +#define srcByte 0x55 +#define dstByte 0xBB + +#define FUNC(s,d,n) {s,d,#n,n} + +static int cpu_caps; + +static char *args_parse(int argc, char *argv[]) +{ + int o; + + while ((o = getopt(argc, argv, "m23")) != -1) { + switch (o) { + case 'm': + cpu_caps |= SWS_CPU_CAPS_MMX; + break; + case '2': + cpu_caps |= SWS_CPU_CAPS_MMX2; + break; + case '3': + cpu_caps |= SWS_CPU_CAPS_3DNOW; + break; + default: + av_log(NULL, AV_LOG_ERROR, "Unknown option %c\n", o); + } + } + + return argv[optind]; +} + +int main(int argc, char **argv) +{ + int i, funcNum; + uint8_t *srcBuffer= (uint8_t*)av_malloc(SIZE); + uint8_t *dstBuffer= (uint8_t*)av_malloc(SIZE); + int failedNum=0; + int passedNum=0; + + av_log(NULL, AV_LOG_INFO, "memory corruption test ...\n"); + args_parse(argc, argv); + av_log(NULL, AV_LOG_INFO, "CPU capabilities forced to %x\n", cpu_caps); + sws_rgb2rgb_init(cpu_caps); + + for(funcNum=0; ; funcNum++){ + struct func_info_s { + int src_bpp; + int dst_bpp; + char *name; + void (*func)(const uint8_t *src, uint8_t *dst, long src_size); + } func_info[] = { + FUNC(2, 2, rgb15to16), + FUNC(2, 3, rgb15to24), + FUNC(2, 4, rgb15to32), + FUNC(2, 3, rgb16to24), + FUNC(2, 4, rgb16to32), + FUNC(3, 2, rgb24to15), + FUNC(3, 2, rgb24to16), + FUNC(3, 4, rgb24to32), + FUNC(4, 2, rgb32to15), + FUNC(4, 2, rgb32to16), + FUNC(4, 3, rgb32to24), + FUNC(2, 2, rgb16to15), + FUNC(2, 2, rgb15tobgr15), + FUNC(2, 2, rgb15tobgr16), + FUNC(2, 3, rgb15tobgr24), + FUNC(2, 4, rgb15tobgr32), + FUNC(2, 2, rgb16tobgr15), + FUNC(2, 2, rgb16tobgr16), + FUNC(2, 3, rgb16tobgr24), + FUNC(2, 4, rgb16tobgr32), + FUNC(3, 2, rgb24tobgr15), + FUNC(3, 2, rgb24tobgr16), + FUNC(3, 3, rgb24tobgr24), + FUNC(3, 4, rgb24tobgr32), + FUNC(4, 2, rgb32tobgr15), + FUNC(4, 2, rgb32tobgr16), + FUNC(4, 3, rgb32tobgr24), + FUNC(4, 4, rgb32tobgr32), + FUNC(0, 0, NULL) + }; + int width; + int failed=0; + int srcBpp=0; + int dstBpp=0; + + if (!func_info[funcNum].func) break; + + av_log(NULL, AV_LOG_INFO,"."); + memset(srcBuffer, srcByte, SIZE); + + for(width=63; width>0; width--){ + int dstOffset; + for(dstOffset=128; dstOffset<196; dstOffset+=4){ + int srcOffset; + memset(dstBuffer, dstByte, SIZE); + + for(srcOffset=128; srcOffset<196; srcOffset+=4){ + uint8_t *src= srcBuffer+srcOffset; + uint8_t *dst= dstBuffer+dstOffset; + char *name=NULL; + + if(failed) break; //don't fill the screen with shit ... + + srcBpp = func_info[funcNum].src_bpp; + dstBpp = func_info[funcNum].dst_bpp; + name = func_info[funcNum].name; + + func_info[funcNum].func(src, dst, width*srcBpp); + + if(!srcBpp) break; + + for(i=0; i + * April 20, 2007 + * + * Blackfin video color space converter operations + * convert I420 YV12 to RGB in various formats + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +/* +YUV420 to RGB565 conversion. This routine takes a YUV 420 planar macroblock +and converts it to RGB565. R:5 bits, G:6 bits, B:5 bits.. packed into shorts. + + +The following calculation is used for the conversion: + + r = clipz((y-oy)*cy + crv*(v-128)) + g = clipz((y-oy)*cy + cgv*(v-128) + cgu*(u-128)) + b = clipz((y-oy)*cy + cbu*(u-128)) + +y,u,v are prescaled by a factor of 4 i.e. left-shifted to gain precision. + + +New factorization to eliminate the truncation error which was +occurring due to the byteop3p. + + +1) Use the bytop16m to subtract quad bytes we use this in U8 this + then so the offsets need to be renormalized to 8bits. + +2) Scale operands up by a factor of 4 not 8 because Blackfin + multiplies include a shift. + +3) Compute into the accumulators cy*yx0, cy*yx1. + +4) Compute each of the linear equations: + r = clipz((y - oy) * cy + crv * (v - 128)) + + g = clipz((y - oy) * cy + cgv * (v - 128) + cgu * (u - 128)) + + b = clipz((y - oy) * cy + cbu * (u - 128)) + + Reuse of the accumulators requires that we actually multiply + twice once with addition and the second time with a subtraction. + + Because of this we need to compute the equations in the order R B + then G saving the writes for B in the case of 24/32 bit color + formats. + + API: yuv2rgb_kind (uint8_t *Y, uint8_t *U, uint8_t *V, int *out, + int dW, uint32_t *coeffs); + + A B + --- --- + i2 = cb i3 = cr + i1 = coeff i0 = y + +Where coeffs have the following layout in memory. + +uint32_t oy,oc,zero,cy,crv,rmask,cbu,bmask,cgu,cgv; + +coeffs is a pointer to oy. + +The {rgb} masks are only utilized by the 565 packing algorithm. Note the data +replication is used to simplify the internal algorithms for the dual Mac +architecture of BlackFin. + +All routines are exported with _ff_bfin_ as a symbol prefix. + +Rough performance gain compared against -O3: + +2779809/1484290 187.28% + +which translates to ~33c/pel to ~57c/pel for the reference vs 17.5 +c/pel for the optimized implementations. Not sure why there is such a +huge variation on the reference codes on Blackfin I guess it must have +to do with the memory system. +*/ + +#define mL3 .text +#ifdef __FDPIC__ +#define mL1 .l1.text +#else +#define mL1 mL3 +#endif +#define MEM mL1 + +#define DEFUN(fname,where,interface) \ + .section where; \ + .global _ff_bfin_ ## fname; \ + .type _ff_bfin_ ## fname, STT_FUNC; \ + .align 8; \ + _ff_bfin_ ## fname + +#define DEFUN_END(fname) \ + .size _ff_bfin_ ## fname, . - _ff_bfin_ ## fname + + +.text + +#define COEFF_LEN 11*4 +#define COEFF_REL_CY_OFF 4*4 + +#define ARG_OUT 20 +#define ARG_W 24 +#define ARG_COEFF 28 + +DEFUN(yuv2rgb565_line,MEM, + (uint8_t *Y, uint8_t *U, uint8_t *V, int *out, int dW, uint32_t *coeffs)): + link 0; + [--sp] = (r7:4); + p1 = [fp+ARG_OUT]; + r3 = [fp+ARG_W]; + + i0 = r0; + i2 = r1; + i3 = r2; + + r0 = [fp+ARG_COEFF]; + i1 = r0; + b1 = i1; + l1 = COEFF_LEN; + m0 = COEFF_REL_CY_OFF; + p0 = r3; + + r0 = [i0++]; // 2Y + r1.l = w[i2++]; // 2u + r1.h = w[i3++]; // 2v + p0 = p0>>2; + + lsetup (.L0565, .L1565) lc0 = p0; + + /* + uint32_t oy,oc,zero,cy,crv,rmask,cbu,bmask,cgu,cgv + r0 -- used to load 4ys + r1 -- used to load 2us,2vs + r4 -- y3,y2 + r5 -- y1,y0 + r6 -- u1,u0 + r7 -- v1,v0 + */ + r2=[i1++]; // oy +.L0565: + /* + rrrrrrrr gggggggg bbbbbbbb + 5432109876543210 + bbbbb >>3 + gggggggg <<3 + rrrrrrrr <<8 + rrrrrggggggbbbbb + */ + (r4,r5) = byteop16m (r1:0, r3:2) || r3=[i1++]; // oc + (r7,r6) = byteop16m (r1:0, r3:2) (r); + r5 = r5 << 2 (v); // y1,y0 + r4 = r4 << 2 (v); // y3,y2 + r6 = r6 << 2 (v) || r0=[i1++]; // u1,u0, r0=zero + r7 = r7 << 2 (v) || r1=[i1++]; // v1,v0 r1=cy + /* Y' = y*cy */ + a1 = r1.h*r5.h, a0 = r1.l*r5.l || r1=[i1++]; // crv + + /* R = Y+ crv*(Cr-128) */ + r2.h = (a1 += r1.h*r7.l), r2.l = (a0 += r1.l*r7.l); + a1 -= r1.h*r7.l, a0 -= r1.l*r7.l || r5=[i1++]; // rmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cbu + r2 = r2 >> 3 (v); + r3 = r2 & r5; + + /* B = Y+ cbu*(Cb-128) */ + r2.h = (a1 += r1.h*r6.l), r2.l = (a0 += r1.l*r6.l); + a1 -= r1.h*r6.l, a0 -= r1.l*r6.l || r5=[i1++]; // bmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cgu + r2 = r2 << 8 (v); + r2 = r2 & r5; + r3 = r3 | r2; + + /* G = Y+ cgu*(Cb-128)+cgv*(Cr-128) */ + a1 += r1.h*r6.l, a0 += r1.l*r6.l || r1=[i1++]; // cgv + r2.h = (a1 += r1.h*r7.l), r2.l = (a0 += r1.l*r7.l); + r2 = byteop3p(r3:2, r1:0)(LO) || r5=[i1++m0]; // gmask + r2 = r2 << 3 (v); + r2 = r2 & r5; + r3 = r3 | r2; + [p1++]=r3 || r1=[i1++]; // cy + + /* Y' = y*cy */ + + a1 = r1.h*r4.h, a0 = r1.l*r4.l || r1=[i1++]; // crv + + /* R = Y+ crv*(Cr-128) */ + r2.h = (a1 += r1.h*r7.h), r2.l = (a0 += r1.l*r7.h); + a1 -= r1.h*r7.h, a0 -= r1.l*r7.h || r5=[i1++]; // rmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cbu + r2 = r2 >> 3 (v); + r3 = r2 & r5; + + /* B = Y+ cbu*(Cb-128) */ + r2.h = (a1 += r1.h*r6.h), r2.l = (a0 += r1.l*r6.h); + a1 -= r1.h*r6.h, a0 -= r1.l*r6.h || r5=[i1++]; // bmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cgu + r2 = r2 << 8 (v); + r2 = r2 & r5; + r3 = r3 | r2; + + /* G = Y+ cgu*(Cb-128)+cgv*(Cr-128) */ + a1 += r1.h*r6.h, a0 += r1.l*r6.h || r1=[i1++]; // cgv + r2.h = (a1 += r1.h*r7.h), r2.l = (a0 += r1.l*r7.h) || r5=[i1++]; // gmask + r2 = byteop3p(r3:2, r1:0)(LO) || r0 = [i0++]; // 2Y + r2 = r2 << 3 (v) || r1.l = w[i2++]; // 2u + r2 = r2 & r5; + r3 = r3 | r2; + [p1++]=r3 || r1.h = w[i3++]; // 2v +.L1565: r2=[i1++]; // oy + + l1 = 0; + + (r7:4) = [sp++]; + unlink; + rts; +DEFUN_END(yuv2rgb565_line) + +DEFUN(yuv2rgb555_line,MEM, + (uint8_t *Y, uint8_t *U, uint8_t *V, int *out, int dW, uint32_t *coeffs)): + link 0; + [--sp] = (r7:4); + p1 = [fp+ARG_OUT]; + r3 = [fp+ARG_W]; + + i0 = r0; + i2 = r1; + i3 = r2; + + r0 = [fp+ARG_COEFF]; + i1 = r0; + b1 = i1; + l1 = COEFF_LEN; + m0 = COEFF_REL_CY_OFF; + p0 = r3; + + r0 = [i0++]; // 2Y + r1.l = w[i2++]; // 2u + r1.h = w[i3++]; // 2v + p0 = p0>>2; + + lsetup (.L0555, .L1555) lc0 = p0; + + /* + uint32_t oy,oc,zero,cy,crv,rmask,cbu,bmask,cgu,cgv + r0 -- used to load 4ys + r1 -- used to load 2us,2vs + r4 -- y3,y2 + r5 -- y1,y0 + r6 -- u1,u0 + r7 -- v1,v0 + */ + r2=[i1++]; // oy +.L0555: + /* + rrrrrrrr gggggggg bbbbbbbb + 5432109876543210 + bbbbb >>3 + gggggggg <<2 + rrrrrrrr <<7 + xrrrrrgggggbbbbb + */ + + (r4,r5) = byteop16m (r1:0, r3:2) || r3=[i1++]; // oc + (r7,r6) = byteop16m (r1:0, r3:2) (r); + r5 = r5 << 2 (v); // y1,y0 + r4 = r4 << 2 (v); // y3,y2 + r6 = r6 << 2 (v) || r0=[i1++]; // u1,u0, r0=zero + r7 = r7 << 2 (v) || r1=[i1++]; // v1,v0 r1=cy + /* Y' = y*cy */ + a1 = r1.h*r5.h, a0 = r1.l*r5.l || r1=[i1++]; // crv + + /* R = Y+ crv*(Cr-128) */ + r2.h = (a1 += r1.h*r7.l), r2.l = (a0 += r1.l*r7.l); + a1 -= r1.h*r7.l, a0 -= r1.l*r7.l || r5=[i1++]; // rmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cbu + r2 = r2 >> 3 (v); + r3 = r2 & r5; + + /* B = Y+ cbu*(Cb-128) */ + r2.h = (a1 += r1.h*r6.l), r2.l = (a0 += r1.l*r6.l); + a1 -= r1.h*r6.l, a0 -= r1.l*r6.l || r5=[i1++]; // bmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cgu + r2 = r2 << 7 (v); + r2 = r2 & r5; + r3 = r3 | r2; + + /* G = Y+ cgu*(Cb-128)+cgv*(Cr-128) */ + a1 += r1.h*r6.l, a0 += r1.l*r6.l || r1=[i1++]; // cgv + r2.h = (a1 += r1.h*r7.l), r2.l = (a0 += r1.l*r7.l); + r2 = byteop3p(r3:2, r1:0)(LO) || r5=[i1++m0]; // gmask + r2 = r2 << 2 (v); + r2 = r2 & r5; + r3 = r3 | r2; + [p1++]=r3 || r1=[i1++]; // cy + + /* Y' = y*cy */ + + a1 = r1.h*r4.h, a0 = r1.l*r4.l || r1=[i1++]; // crv + + /* R = Y+ crv*(Cr-128) */ + r2.h = (a1 += r1.h*r7.h), r2.l = (a0 += r1.l*r7.h); + a1 -= r1.h*r7.h, a0 -= r1.l*r7.h || r5=[i1++]; // rmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cbu + r2 = r2 >> 3 (v); + r3 = r2 & r5; + + /* B = Y+ cbu*(Cb-128) */ + r2.h = (a1 += r1.h*r6.h), r2.l = (a0 += r1.l*r6.h); + a1 -= r1.h*r6.h, a0 -= r1.l*r6.h || r5=[i1++]; // bmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cgu + r2 = r2 << 7 (v); + r2 = r2 & r5; + r3 = r3 | r2; + + /* G = Y+ cgu*(Cb-128)+cgv*(Cr-128) */ + a1 += r1.h*r6.h, a0 += r1.l*r6.h || r1=[i1++]; // cgv + r2.h = (a1 += r1.h*r7.h), r2.l = (a0 += r1.l*r7.h) || r5=[i1++]; // gmask + r2 = byteop3p(r3:2, r1:0)(LO) || r0=[i0++]; // 4Y + r2 = r2 << 2 (v) || r1.l=w[i2++]; // 2u + r2 = r2 & r5; + r3 = r3 | r2; + [p1++]=r3 || r1.h=w[i3++]; // 2v + +.L1555: r2=[i1++]; // oy + + l1 = 0; + + (r7:4) = [sp++]; + unlink; + rts; +DEFUN_END(yuv2rgb555_line) + +DEFUN(yuv2rgb24_line,MEM, + (uint8_t *Y, uint8_t *U, uint8_t *V, int *out, int dW, uint32_t *coeffs)): + link 0; + [--sp] = (r7:4); + p1 = [fp+ARG_OUT]; + r3 = [fp+ARG_W]; + p2 = p1; + p2 += 3; + + i0 = r0; + i2 = r1; + i3 = r2; + + r0 = [fp+ARG_COEFF]; // coeff buffer + i1 = r0; + b1 = i1; + l1 = COEFF_LEN; + m0 = COEFF_REL_CY_OFF; + p0 = r3; + + r0 = [i0++]; // 2Y + r1.l = w[i2++]; // 2u + r1.h = w[i3++]; // 2v + p0 = p0>>2; + + lsetup (.L0888, .L1888) lc0 = p0; + + /* + uint32_t oy,oc,zero,cy,crv,rmask,cbu,bmask,cgu,cgv + r0 -- used to load 4ys + r1 -- used to load 2us,2vs + r4 -- y3,y2 + r5 -- y1,y0 + r6 -- u1,u0 + r7 -- v1,v0 + */ + r2=[i1++]; // oy +.L0888: + (r4,r5) = byteop16m (r1:0, r3:2) || r3=[i1++]; // oc + (r7,r6) = byteop16m (r1:0, r3:2) (r); + r5 = r5 << 2 (v); // y1,y0 + r4 = r4 << 2 (v); // y3,y2 + r6 = r6 << 2 (v) || r0=[i1++]; // u1,u0, r0=zero + r7 = r7 << 2 (v) || r1=[i1++]; // v1,v0 r1=cy + + /* Y' = y*cy */ + a1 = r1.h*r5.h, a0 = r1.l*r5.l || r1=[i1++]; // crv + + /* R = Y+ crv*(Cr-128) */ + r2.h = (a1 += r1.h*r7.l), r2.l = (a0 += r1.l*r7.l); + a1 -= r1.h*r7.l, a0 -= r1.l*r7.l || r5=[i1++]; // rmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cbu + r2=r2>>16 || B[p1++]=r2; + B[p2++]=r2; + + /* B = Y+ cbu*(Cb-128) */ + r2.h = (a1 += r1.h*r6.l), r2.l = (a0 += r1.l*r6.l); + a1 -= r1.h*r6.l, a0 -= r1.l*r6.l || r5=[i1++]; // bmask + r3 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cgu + + /* G = Y+ cgu*(Cb-128)+cgv*(Cr-128) */ + a1 += r1.h*r6.l, a0 += r1.l*r6.l || r1=[i1++]; // cgv + r2.h = (a1 += r1.h*r7.l), r2.l = (a0 += r1.l*r7.l); + r2 = byteop3p(r3:2, r1:0)(LO) || r5=[i1++m0]; // gmask, oy,cy,zero + + r2=r2>>16 || B[p1++]=r2; + B[p2++]=r2; + + r3=r3>>16 || B[p1++]=r3; + B[p2++]=r3 || r1=[i1++]; // cy + + p1+=3; + p2+=3; + /* Y' = y*cy */ + a1 = r1.h*r4.h, a0 = r1.l*r4.l || r1=[i1++]; // crv + + /* R = Y+ crv*(Cr-128) */ + r2.h = (a1 += r1.h*r7.h), r2.l = (a0 += r1.l*r7.h); + a1 -= r1.h*r7.h, a0 -= r1.l*r7.h || r5=[i1++]; // rmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cbu + r2=r2>>16 || B[p1++]=r2; + B[p2++]=r2; + + /* B = Y+ cbu*(Cb-128) */ + r2.h = (a1 += r1.h*r6.h), r2.l = (a0 += r1.l*r6.h); + a1 -= r1.h*r6.h, a0 -= r1.l*r6.h || r5=[i1++]; // bmask + r3 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cgu + + /* G = Y+ cgu*(Cb-128)+cgv*(Cr-128) */ + a1 += r1.h*r6.h, a0 += r1.l*r6.h || r1=[i1++]; // cgv + r2.h = (a1 += r1.h*r7.h), r2.l = (a0 += r1.l*r7.h); + r2 = byteop3p(r3:2, r1:0)(LO) || r5=[i1++]; // gmask + r2=r2>>16 || B[p1++]=r2 || r0 = [i0++]; // 4y + B[p2++]=r2 || r1.l = w[i2++]; // 2u + r3=r3>>16 || B[p1++]=r3 || r1.h = w[i3++]; // 2v + B[p2++]=r3 || r2=[i1++]; // oy + + p1+=3; +.L1888: p2+=3; + + l1 = 0; + + (r7:4) = [sp++]; + unlink; + rts; +DEFUN_END(yuv2rgb24_line) + + + +#define ARG_vdst 20 +#define ARG_width 24 +#define ARG_height 28 +#define ARG_lumStride 32 +#define ARG_chromStride 36 +#define ARG_srcStride 40 + +DEFUN(uyvytoyv12, mL3, (const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, + long width, long height, + long lumStride, long chromStride, long srcStride)): + link 0; + [--sp] = (r7:4,p5:4); + + p0 = r1; // Y top even + + i2 = r2; // *u + r2 = [fp + ARG_vdst]; + i3 = r2; // *v + + r1 = [fp + ARG_srcStride]; + r2 = r0 + r1; + r1 += -8; // i0,i1 is pre read need to correct + m0 = r1; + + i0 = r0; // uyvy_T even + i1 = r2; // uyvy_B odd + + p2 = [fp + ARG_lumStride]; + p1 = p0 + p2; // Y bot odd + + p5 = [fp + ARG_width]; + p4 = [fp + ARG_height]; + r0 = p5; + p4 = p4 >> 1; + p5 = p5 >> 2; + + r2 = [fp + ARG_chromStride]; + r0 = r0 >> 1; + r2 = r2 - r0; + m1 = r2; + + /* I0,I1 - src input line pointers + * p0,p1 - luma output line pointers + * I2 - dstU + * I3 - dstV + */ + + lsetup (0f, 1f) lc1 = p4; // H/2 +0: r0 = [i0++] || r2 = [i1++]; + r1 = [i0++] || r3 = [i1++]; + r4 = byteop1p(r1:0, r3:2); + r5 = byteop1p(r1:0, r3:2) (r); + lsetup (2f, 3f) lc0 = p5; // W/4 +2: r0 = r0 >> 8(v); + r1 = r1 >> 8(v); + r2 = r2 >> 8(v); + r3 = r3 >> 8(v); + r0 = bytepack(r0, r1); + r2 = bytepack(r2, r3) || [p0++] = r0; // yyyy + r6 = pack(r5.l, r4.l) || [p1++] = r2; // yyyy + r7 = pack(r5.h, r4.h) || r0 = [i0++] || r2 = [i1++]; + r6 = bytepack(r6, r7) || r1 = [i0++] || r3 = [i1++]; + r4 = byteop1p(r1:0, r3:2) || w[i2++] = r6.l; // uu +3: r5 = byteop1p(r1:0, r3:2) (r) || w[i3++] = r6.h; // vv + + i0 += m0; + i1 += m0; + i2 += m1; + i3 += m1; + p0 = p0 + p2; +1: p1 = p1 + p2; + + (r7:4,p5:4) = [sp++]; + unlink; + rts; +DEFUN_END(uyvytoyv12) + +DEFUN(yuyvtoyv12, mL3, (const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, + long width, long height, + long lumStride, long chromStride, long srcStride)): + link 0; + [--sp] = (r7:4,p5:4); + + p0 = r1; // Y top even + + i2 = r2; // *u + r2 = [fp + ARG_vdst]; + i3 = r2; // *v + + r1 = [fp + ARG_srcStride]; + r2 = r0 + r1; + r1 += -8; // i0,i1 is pre read need to correct + m0 = r1; + + i0 = r0; // uyvy_T even + i1 = r2; // uyvy_B odd + + p2 = [fp + ARG_lumStride]; + p1 = p0 + p2; // Y bot odd + + p5 = [fp + ARG_width]; + p4 = [fp + ARG_height]; + r0 = p5; + p4 = p4 >> 1; + p5 = p5 >> 2; + + r2 = [fp + ARG_chromStride]; + r0 = r0 >> 1; + r2 = r2 - r0; + m1 = r2; + + /* I0,I1 - src input line pointers + * p0,p1 - luma output line pointers + * I2 - dstU + * I3 - dstV + */ + + lsetup (0f, 1f) lc1 = p4; // H/2 +0: r0 = [i0++] || r2 = [i1++]; + r1 = [i0++] || r3 = [i1++]; + r4 = bytepack(r0, r1); + r5 = bytepack(r2, r3); + lsetup (2f, 3f) lc0 = p5; // W/4 +2: r0 = r0 >> 8(v) || [p0++] = r4; // yyyy-even + r1 = r1 >> 8(v) || [p1++] = r5; // yyyy-odd + r2 = r2 >> 8(v); + r3 = r3 >> 8(v); + r4 = byteop1p(r1:0, r3:2); + r5 = byteop1p(r1:0, r3:2) (r); + r6 = pack(r5.l, r4.l); + r7 = pack(r5.h, r4.h) || r0 = [i0++] || r2 = [i1++]; + r6 = bytepack(r6, r7) || r1 = [i0++] || r3 = [i1++]; + r4 = bytepack(r0, r1) || w[i2++] = r6.l; // uu +3: r5 = bytepack(r2, r3) || w[i3++] = r6.h; // vv + + i0 += m0; + i1 += m0; + i2 += m1; + i3 += m1; + p0 = p0 + p2; +1: p1 = p1 + p2; + + (r7:4,p5:4) = [sp++]; + unlink; + rts; +DEFUN_END(yuyvtoyv12) Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/rgb2rgb.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/rgb2rgb.c 2008-09-15 13:52:29 UTC (rev 27537) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libswscale/rgb2rgb.c 2008-09-15 13:52:45 UTC (rev 27538) @@ -0,0 +1,534 @@ +/* + * software RGB to RGB converter + * pluralize by software PAL8 to RGB converter + * software YUV to YUV converter + * software YUV to RGB converter + * Written by Nick Kurshev. + * palette & YUV & runtime CPU stuff by Michael (michaelni at gmx.at) + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * The C code (not assembly, MMX, ...) of this file can be used + * under the LGPL license. + */ +#include +#include "config.h" +#include "x86_cpu.h" +#include "bswap.h" +#include "rgb2rgb.h" +#include "swscale.h" +#include "swscale_internal.h" + +#define FAST_BGR2YV12 // use 7-bit instead of 15-bit coefficients + +void (*rgb24to32)(const uint8_t *src, uint8_t *dst, long src_size); +void (*rgb24to16)(const uint8_t *src, uint8_t *dst, long src_size); +void (*rgb24to15)(const uint8_t *src, uint8_t *dst, long src_size); +void (*rgb32to24)(const uint8_t *src, uint8_t *dst, long src_size); +void (*rgb32to16)(const uint8_t *src, uint8_t *dst, long src_size); +void (*rgb32to15)(const uint8_t *src, uint8_t *dst, long src_size); +void (*rgb15to16)(const uint8_t *src, uint8_t *dst, long src_size); +void (*rgb15to24)(const uint8_t *src, uint8_t *dst, long src_size); +void (*rgb15to32)(const uint8_t *src, uint8_t *dst, long src_size); +void (*rgb16to15)(const uint8_t *src, uint8_t *dst, long src_size); +void (*rgb16to24)(const uint8_t *src, uint8_t *dst, long src_size); +void (*rgb16to32)(const uint8_t *src, uint8_t *dst, long src_size); +//void (*rgb24tobgr32)(const uint8_t *src, uint8_t *dst, long src_size); +void (*rgb24tobgr24)(const uint8_t *src, uint8_t *dst, long src_size); +void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, long src_size); +void (*rgb24tobgr15)(const uint8_t *src, uint8_t *dst, long src_size); +void (*rgb32tobgr32)(const uint8_t *src, uint8_t *dst, long src_size); +//void (*rgb32tobgr24)(const uint8_t *src, uint8_t *dst, long src_size); +void (*rgb32tobgr16)(const uint8_t *src, uint8_t *dst, long src_size); +void (*rgb32tobgr15)(const uint8_t *src, uint8_t *dst, long src_size); + +void (*yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, + long width, long height, + long lumStride, long chromStride, long dstStride); +void (*yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, + long width, long height, + long lumStride, long chromStride, long dstStride); +void (*yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, + long width, long height, + long lumStride, long chromStride, long dstStride); +void (*yuy2toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, + long width, long height, + long lumStride, long chromStride, long srcStride); +void (*rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, + long width, long height, + long lumStride, long chromStride, long srcStride); +void (*planar2x)(const uint8_t *src, uint8_t *dst, long width, long height, + long srcStride, long dstStride); +void (*interleaveBytes)(uint8_t *src1, uint8_t *src2, uint8_t *dst, + long width, long height, long src1Stride, + long src2Stride, long dstStride); +void (*vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2, + uint8_t *dst1, uint8_t *dst2, + long width, long height, + long srcStride1, long srcStride2, + long dstStride1, long dstStride2); +void (*yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, + uint8_t *dst, + long width, long height, + long srcStride1, long srcStride2, + long srcStride3, long dstStride); + +#if defined(ARCH_X86) && defined(CONFIG_GPL) +DECLARE_ASM_CONST(8, uint64_t, mmx_null) = 0x0000000000000000ULL; +DECLARE_ASM_CONST(8, uint64_t, mmx_one) = 0xFFFFFFFFFFFFFFFFULL; +DECLARE_ASM_CONST(8, uint64_t, mask32b) = 0x000000FF000000FFULL; +DECLARE_ASM_CONST(8, uint64_t, mask32g) = 0x0000FF000000FF00ULL; +DECLARE_ASM_CONST(8, uint64_t, mask32r) = 0x00FF000000FF0000ULL; +DECLARE_ASM_CONST(8, uint64_t, mask32) = 0x00FFFFFF00FFFFFFULL; +DECLARE_ASM_CONST(8, uint64_t, mask3216br) = 0x00F800F800F800F8ULL; +DECLARE_ASM_CONST(8, uint64_t, mask3216g) = 0x0000FC000000FC00ULL; +DECLARE_ASM_CONST(8, uint64_t, mask3215g) = 0x0000F8000000F800ULL; +DECLARE_ASM_CONST(8, uint64_t, mul3216) = 0x2000000420000004ULL; +DECLARE_ASM_CONST(8, uint64_t, mul3215) = 0x2000000820000008ULL; +DECLARE_ASM_CONST(8, uint64_t, mask24b) = 0x00FF0000FF0000FFULL; +DECLARE_ASM_CONST(8, uint64_t, mask24g) = 0xFF0000FF0000FF00ULL; +DECLARE_ASM_CONST(8, uint64_t, mask24r) = 0x0000FF0000FF0000ULL; +DECLARE_ASM_CONST(8, uint64_t, mask24l) = 0x0000000000FFFFFFULL; +DECLARE_ASM_CONST(8, uint64_t, mask24h) = 0x0000FFFFFF000000ULL; +DECLARE_ASM_CONST(8, uint64_t, mask24hh) = 0xffff000000000000ULL; +DECLARE_ASM_CONST(8, uint64_t, mask24hhh) = 0xffffffff00000000ULL; +DECLARE_ASM_CONST(8, uint64_t, mask24hhhh) = 0xffffffffffff0000ULL; +DECLARE_ASM_CONST(8, uint64_t, mask15b) = 0x001F001F001F001FULL; /* 00000000 00011111 xxB */ +DECLARE_ASM_CONST(8, uint64_t, mask15rg) = 0x7FE07FE07FE07FE0ULL; /* 01111111 11100000 RGx */ +DECLARE_ASM_CONST(8, uint64_t, mask15s) = 0xFFE0FFE0FFE0FFE0ULL; +DECLARE_ASM_CONST(8, uint64_t, mask15g) = 0x03E003E003E003E0ULL; +DECLARE_ASM_CONST(8, uint64_t, mask15r) = 0x7C007C007C007C00ULL; +#define mask16b mask15b +DECLARE_ASM_CONST(8, uint64_t, mask16g) = 0x07E007E007E007E0ULL; +DECLARE_ASM_CONST(8, uint64_t, mask16r) = 0xF800F800F800F800ULL; +DECLARE_ASM_CONST(8, uint64_t, red_16mask) = 0x0000f8000000f800ULL; +DECLARE_ASM_CONST(8, uint64_t, green_16mask) = 0x000007e0000007e0ULL; +DECLARE_ASM_CONST(8, uint64_t, blue_16mask) = 0x0000001f0000001fULL; +DECLARE_ASM_CONST(8, uint64_t, red_15mask) = 0x00007c0000007c00ULL; +DECLARE_ASM_CONST(8, uint64_t, green_15mask) = 0x000003e0000003e0ULL; +DECLARE_ASM_CONST(8, uint64_t, blue_15mask) = 0x0000001f0000001fULL; + +#if 0 +static volatile uint64_t __attribute__((aligned(8))) b5Dither; +static volatile uint64_t __attribute__((aligned(8))) g5Dither; +static volatile uint64_t __attribute__((aligned(8))) g6Dither; +static volatile uint64_t __attribute__((aligned(8))) r5Dither; + +static uint64_t __attribute__((aligned(8))) dither4[2]={ + 0x0103010301030103LL, + 0x0200020002000200LL,}; + +static uint64_t __attribute__((aligned(8))) dither8[2]={ + 0x0602060206020602LL, + 0x0004000400040004LL,}; +#endif +#endif /* defined(ARCH_X86) */ + +#define RGB2YUV_SHIFT 8 +#define BY ((int)( 0.098*(1< Author: dlmcpaul Date: 2008-09-15 15:57:54 +0200 (Mon, 15 Sep 2008) New Revision: 27539 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27539&view=rev Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aac.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aac_ac3_parser.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aacdectab.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aacpsy.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aactab.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/ac3_parser.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/ac3dec.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/ac3dec_data.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/acelp_filters.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/acelp_math.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/acelp_pitch_delay.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/acelp_vectors.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/adx.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/atrac3data.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/audioconvert.h Modified: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/ac3.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/ac3tab.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/avcodec.h Log: Update avcodec to 20080825 Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aac.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aac.h 2008-09-15 13:52:45 UTC (rev 27538) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aac.h 2008-09-15 13:57:54 UTC (rev 27539) @@ -0,0 +1,275 @@ +/* + * AAC definitions and structures + * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org ) + * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com ) + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file aac.h + * AAC definitions and structures + * @author Oded Shimon ( ods15 ods15 dyndns org ) + * @author Maxim Gavrilov ( maxim.gavrilov gmail com ) + */ + +#ifndef FFMPEG_AAC_H +#define FFMPEG_AAC_H + +#include "avcodec.h" +#include "dsputil.h" +#include "mpeg4audio.h" + +#include + +#define AAC_INIT_VLC_STATIC(num, size) \ + INIT_VLC_STATIC(&vlc_spectral[num], 6, ff_aac_spectral_sizes[num], \ + ff_aac_spectral_bits[num], sizeof( ff_aac_spectral_bits[num][0]), sizeof( ff_aac_spectral_bits[num][0]), \ + ff_aac_spectral_codes[num], sizeof(ff_aac_spectral_codes[num][0]), sizeof(ff_aac_spectral_codes[num][0]), \ + size); + +#define MAX_CHANNELS 64 +#define MAX_ELEM_ID 16 + +#define TNS_MAX_ORDER 20 +#define PNS_MEAN_ENERGY 3719550720.0f // sqrt(3.0) * 1<<31 + +enum AudioObjectType { + AOT_NULL, + // Support? Name + AOT_AAC_MAIN, ///< Y Main + AOT_AAC_LC, ///< Y Low Complexity + AOT_AAC_SSR, ///< N (code in SoC repo) Scalable Sample Rate + AOT_AAC_LTP, ///< N (code in SoC repo) Long Term Prediction + AOT_SBR, ///< N (in progress) Spectral Band Replication + AOT_AAC_SCALABLE, ///< N Scalable + AOT_TWINVQ, ///< N Twin Vector Quantizer + AOT_CELP, ///< N Code Excited Linear Prediction + AOT_HVXC, ///< N Harmonic Vector eXcitation Coding + AOT_TTSI = 12, ///< N Text-To-Speech Interface + AOT_MAINSYNTH, ///< N Main Synthesis + AOT_WAVESYNTH, ///< N Wavetable Synthesis + AOT_MIDI, ///< N General MIDI + AOT_SAFX, ///< N Algorithmic Synthesis and Audio Effects + AOT_ER_AAC_LC, ///< N Error Resilient Low Complexity + AOT_ER_AAC_LTP = 19, ///< N Error Resilient Long Term Prediction + AOT_ER_AAC_SCALABLE, ///< N Error Resilient Scalable + AOT_ER_TWINVQ, ///< N Error Resilient Twin Vector Quantizer + AOT_ER_BSAC, ///< N Error Resilient Bit-Sliced Arithmetic Coding + AOT_ER_AAC_LD, ///< N Error Resilient Low Delay + AOT_ER_CELP, ///< N Error Resilient Code Excited Linear Prediction + AOT_ER_HVXC, ///< N Error Resilient Harmonic Vector eXcitation Coding + AOT_ER_HILN, ///< N Error Resilient Harmonic and Individual Lines plus Noise + AOT_ER_PARAM, ///< N Error Resilient Parametric + AOT_SSC, ///< N SinuSoidal Coding +}; + +enum RawDataBlockType { + TYPE_SCE, + TYPE_CPE, + TYPE_CCE, + TYPE_LFE, + TYPE_DSE, + TYPE_PCE, + TYPE_FIL, + TYPE_END, +}; + +enum ExtensionPayloadID { + EXT_FILL, + EXT_FILL_DATA, + EXT_DATA_ELEMENT, + EXT_DYNAMIC_RANGE = 0xb, + EXT_SBR_DATA = 0xd, + EXT_SBR_DATA_CRC = 0xe, +}; + +enum WindowSequence { + ONLY_LONG_SEQUENCE, + LONG_START_SEQUENCE, + EIGHT_SHORT_SEQUENCE, + LONG_STOP_SEQUENCE, +}; + +enum BandType { + ZERO_BT = 0, ///< Scalefactors and spectral data are all zero. + FIRST_PAIR_BT = 5, ///< This and later band types encode two values (rather than four) with one code word. + ESC_BT = 11, ///< Spectral data are coded with an escape sequence. + NOISE_BT = 13, ///< Spectral data are scaled white noise not coded in the bitstream. + INTENSITY_BT2 = 14, ///< Scalefactor data are intensity stereo positions. + INTENSITY_BT = 15, ///< Scalefactor data are intensity stereo positions. +}; + +#define IS_CODEBOOK_UNSIGNED(x) ((x - 1) & 10) + +enum ChannelPosition { + AAC_CHANNEL_FRONT = 1, + AAC_CHANNEL_SIDE = 2, + AAC_CHANNEL_BACK = 3, + AAC_CHANNEL_LFE = 4, + AAC_CHANNEL_CC = 5, +}; + +/** + * The point during decoding at which channel coupling is applied. + */ +enum CouplingPoint { + BEFORE_TNS, + BETWEEN_TNS_AND_IMDCT, + AFTER_IMDCT = 3, +}; + +/** + * Individual Channel Stream + */ +typedef struct { + uint8_t max_sfb; ///< number of scalefactor bands per group + enum WindowSequence window_sequence[2]; + uint8_t use_kb_window[2]; ///< If set, use Kaiser-Bessel window, otherwise use a sinus window. + int num_window_groups; + uint8_t group_len[8]; + const uint16_t *swb_offset; ///< table of offsets to the lowest spectral coefficient of a scalefactor band, sfb, for a particular window + int num_swb; ///< number of scalefactor window bands + int num_windows; + int tns_max_bands; +} IndividualChannelStream; + +/** + * Temporal Noise Shaping + */ +typedef struct { + int present; + int n_filt[8]; + int length[8][4]; + int direction[8][4]; + int order[8][4]; + float coef[8][4][TNS_MAX_ORDER]; +} TemporalNoiseShaping; + +/** + * Dynamic Range Control - decoded from the bitstream but not processed further. + */ +typedef struct { + int pce_instance_tag; ///< Indicates with which program the DRC info is associated. + int dyn_rng_sgn[17]; ///< DRC sign information; 0 - positive, 1 - negative + int dyn_rng_ctl[17]; ///< DRC magnitude information + int exclude_mask[MAX_CHANNELS]; ///< Channels to be excluded from DRC processing. + int band_incr; ///< Number of DRC bands greater than 1 having DRC info. + int interpolation_scheme; ///< Indicates the interpolation scheme used in the SBR QMF domain. + int band_top[17]; ///< Indicates the top of the i-th DRC band in units of 4 spectral lines. + int prog_ref_level; /**< A reference level for the long-term program audio level for all + * channels combined. + */ +} DynamicRangeControl; + +typedef struct { + int num_pulse; + int pos[4]; + int amp[4]; +} Pulse; + +/** + * coupling parameters + */ +typedef struct { + enum CouplingPoint coupling_point; ///< The point during decoding at which coupling is applied. + int num_coupled; ///< number of target elements + enum RawDataBlockType type[8]; ///< Type of channel element to be coupled - SCE or CPE. + int id_select[8]; ///< element id + int ch_select[8]; /**< [0] shared list of gains; [1] list of gains for left channel; + * [2] list of gains for right channel; [3] lists of gains for both channels + */ + float gain[16][120]; +} ChannelCoupling; + +/** + * Single Channel Element - used for both SCE and LFE elements. + */ +typedef struct { + IndividualChannelStream ics; + TemporalNoiseShaping tns; + enum BandType band_type[120]; ///< band types + int band_type_run_end[120]; ///< band type run end points + float sf[120]; ///< scalefactors + DECLARE_ALIGNED_16(float, coeffs[1024]); ///< coefficients for IMDCT + DECLARE_ALIGNED_16(float, saved[512]); ///< overlap + DECLARE_ALIGNED_16(float, ret[1024]); ///< PCM output +} SingleChannelElement; + +/** + * channel element - generic struct for SCE/CPE/CCE/LFE + */ +typedef struct { + // CPE specific + uint8_t ms_mask[120]; ///< Set if mid/side stereo is used for each scalefactor window band + // shared + SingleChannelElement ch[2]; + // CCE specific + ChannelCoupling coup; +} ChannelElement; + +/** + * main AAC context + */ +typedef struct { + AVCodecContext * avccontext; + + MPEG4AudioConfig m4ac; + + int is_saved; ///< Set if elements have stored overlap from previous frame. + DynamicRangeControl che_drc; + + /** + * @defgroup elements + * @{ + */ + enum ChannelPosition che_pos[4][MAX_ELEM_ID]; /**< channel element channel mapping with the + * first index as the first 4 raw data block types + */ + ChannelElement * che[4][MAX_ELEM_ID]; + /** @} */ + + /** + * @defgroup temporary aligned temporary buffers (We do not want to have these on the stack.) + * @{ + */ + DECLARE_ALIGNED_16(float, buf_mdct[1024]); + /** @} */ + + /** + * @defgroup tables Computed / set up during initialization. + * @{ + */ + MDCTContext mdct; + MDCTContext mdct_small; + DSPContext dsp; + int random_state; + /** @} */ + + /** + * @defgroup output Members used for output interleaving. + * @{ + */ + float *output_data[MAX_CHANNELS]; ///< Points to each element's 'ret' buffer (PCM output). + float add_bias; ///< offset for dsp.float_to_int16 + float sf_scale; ///< Pre-scale for correct IMDCT and dsp.float_to_int16. + int sf_offset; ///< offset into pow2sf_tab as appropriate for dsp.float_to_int16 + /** @} */ + +} AACContext; + +#endif /* FFMPEG_AAC_H */ Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aac_ac3_parser.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aac_ac3_parser.h 2008-09-15 13:52:45 UTC (rev 27538) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aac_ac3_parser.h 2008-09-15 13:57:54 UTC (rev 27539) @@ -0,0 +1,53 @@ +/* + * Common AAC and AC-3 parser prototypes + * Copyright (c) 2003 Fabrice Bellard. + * Copyright (c) 2003 Michael Niedermayer. + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_AAC_AC3_PARSER_H +#define FFMPEG_AAC_AC3_PARSER_H + +#include +#include "avcodec.h" +#include "parser.h" + +typedef struct AACAC3ParseContext { + ParseContext pc; + int frame_size; + int header_size; + int (*sync)(uint64_t state, struct AACAC3ParseContext *hdr_info, + int *need_next_header, int *new_frame_start); + + int channels; + int sample_rate; + int bit_rate; + int samples; + + int remaining_size; + uint64_t state; + + int need_next_header; +} AACAC3ParseContext; + +int ff_aac_ac3_parse(AVCodecParserContext *s1, + AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size); + +#endif /* FFMPEG_AAC_AC3_PARSER_H */ Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aacdectab.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aacdectab.h 2008-09-15 13:52:45 UTC (rev 27538) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aacdectab.h 2008-09-15 13:57:54 UTC (rev 27539) @@ -0,0 +1,209 @@ +/* + * AAC decoder data + * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org ) + * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com ) + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file aacdectab.h + * AAC decoder data + * @author Oded Shimon ( ods15 ods15 dyndns org ) + * @author Maxim Gavrilov ( maxim.gavrilov gmail com ) + */ + +#ifndef FFMPEG_AACDECTAB_H +#define FFMPEG_AACDECTAB_H + +#include "aac.h" + +#include + +/* @name swb_offsets + * Sample offset into the window indicating the beginning of a scalefactor + * window band + * + * scalefactor window band - term for scalefactor bands within a window, + * given in Table 4.110 to Table 4.128. + * + * scalefactor band - a set of spectral coefficients which are scaled by one + * scalefactor. In case of EIGHT_SHORT_SEQUENCE and grouping a scalefactor band + * may contain several scalefactor window bands of corresponding frequency. For + * all other window_sequences scalefactor bands and scalefactor window bands are + * identical. + * @{ + */ + +static const uint16_t swb_offset_1024_96[] = { + 0, 4, 8, 12, 16, 20, 24, 28, + 32, 36, 40, 44, 48, 52, 56, 64, + 72, 80, 88, 96, 108, 120, 132, 144, + 156, 172, 188, 212, 240, 276, 320, 384, + 448, 512, 576, 640, 704, 768, 832, 896, + 960, 1024 +}; + +static const uint16_t swb_offset_128_96[] = { + 0, 4, 8, 12, 16, 20, 24, 32, 40, 48, 64, 92, 128 +}; + +static const uint16_t swb_offset_1024_64[] = { + 0, 4, 8, 12, 16, 20, 24, 28, + 32, 36, 40, 44, 48, 52, 56, 64, + 72, 80, 88, 100, 112, 124, 140, 156, + 172, 192, 216, 240, 268, 304, 344, 384, + 424, 464, 504, 544, 584, 624, 664, 704, + 744, 784, 824, 864, 904, 944, 984, 1024 +}; + +static const uint16_t swb_offset_1024_48[] = { + 0, 4, 8, 12, 16, 20, 24, 28, + 32, 36, 40, 48, 56, 64, 72, 80, + 88, 96, 108, 120, 132, 144, 160, 176, + 196, 216, 240, 264, 292, 320, 352, 384, + 416, 448, 480, 512, 544, 576, 608, 640, + 672, 704, 736, 768, 800, 832, 864, 896, + 928, 1024 +}; + +static const uint16_t swb_offset_128_48[] = { + 0, 4, 8, 12, 16, 20, 28, 36, + 44, 56, 68, 80, 96, 112, 128 +}; + +static const uint16_t swb_offset_1024_32[] = { + 0, 4, 8, 12, 16, 20, 24, 28, + 32, 36, 40, 48, 56, 64, 72, 80, + 88, 96, 108, 120, 132, 144, 160, 176, + 196, 216, 240, 264, 292, 320, 352, 384, + 416, 448, 480, 512, 544, 576, 608, 640, + 672, 704, 736, 768, 800, 832, 864, 896, + 928, 960, 992, 1024 +}; + +static const uint16_t swb_offset_1024_24[] = { + 0, 4, 8, 12, 16, 20, 24, 28, + 32, 36, 40, 44, 52, 60, 68, 76, + 84, 92, 100, 108, 116, 124, 136, 148, + 160, 172, 188, 204, 220, 240, 260, 284, + 308, 336, 364, 396, 432, 468, 508, 552, + 600, 652, 704, 768, 832, 896, 960, 1024 +}; + +static const uint16_t swb_offset_128_24[] = { + 0, 4, 8, 12, 16, 20, 24, 28, + 36, 44, 52, 64, 76, 92, 108, 128 +}; + +static const uint16_t swb_offset_1024_16[] = { + 0, 8, 16, 24, 32, 40, 48, 56, + 64, 72, 80, 88, 100, 112, 124, 136, + 148, 160, 172, 184, 196, 212, 228, 244, + 260, 280, 300, 320, 344, 368, 396, 424, + 456, 492, 532, 572, 616, 664, 716, 772, + 832, 896, 960, 1024 +}; + +static const uint16_t swb_offset_128_16[] = { + 0, 4, 8, 12, 16, 20, 24, 28, + 32, 40, 48, 60, 72, 88, 108, 128 +}; + +static const uint16_t swb_offset_1024_8[] = { + 0, 12, 24, 36, 48, 60, 72, 84, + 96, 108, 120, 132, 144, 156, 172, 188, + 204, 220, 236, 252, 268, 288, 308, 328, + 348, 372, 396, 420, 448, 476, 508, 544, + 580, 620, 664, 712, 764, 820, 880, 944, + 1024 +}; + +static const uint16_t swb_offset_128_8[] = { + 0, 4, 8, 12, 16, 20, 24, 28, + 36, 44, 52, 60, 72, 88, 108, 128 +}; + +static const uint16_t *swb_offset_1024[] = { + swb_offset_1024_96, swb_offset_1024_96, swb_offset_1024_64, + swb_offset_1024_48, swb_offset_1024_48, swb_offset_1024_32, + swb_offset_1024_24, swb_offset_1024_24, swb_offset_1024_16, + swb_offset_1024_16, swb_offset_1024_16, swb_offset_1024_8 +}; + +static const uint16_t *swb_offset_128[] = { + /* The last entry on the following row is swb_offset_128_64 but is a + duplicate of swb_offset_128_96. */ + swb_offset_128_96, swb_offset_128_96, swb_offset_128_96, + swb_offset_128_48, swb_offset_128_48, swb_offset_128_48, + swb_offset_128_24, swb_offset_128_24, swb_offset_128_16, + swb_offset_128_16, swb_offset_128_16, swb_offset_128_8 +}; + +// @} + +/* @name tns_max_bands + * The maximum number of scalefactor bands on which TNS can operate for the long + * and short transforms respectively. The index to these tables is related to + * the sample rate of the audio. + * @{ + */ +static const uint8_t tns_max_bands_1024[] = { + 31, 31, 34, 40, 42, 51, 46, 46, 42, 42, 42, 39 +}; + +static const uint8_t tns_max_bands_128[] = { + 9, 9, 10, 14, 14, 14, 14, 14, 14, 14, 14, 14 +}; +// @} + +/* @name tns_tmp2_map + * Tables of the tmp2[] arrays of LPC coefficients used for TNS. + * The suffix _M_N[] indicate the values of coef_compress and coef_res + * respectively. + * @{ + */ +static const float tns_tmp2_map_1_3[4] = { + 0.00000000, 0.43388373, -0.64278758, -0.34202015, +}; + +static const float tns_tmp2_map_0_3[8] = { + 0.00000000, 0.43388373, 0.78183150, 0.97492790, + -0.98480773, -0.86602539, -0.64278758, -0.34202015, +}; + +static const float tns_tmp2_map_1_4[8] = { + 0.00000000, 0.20791170, 0.40673664, 0.58778524, + -0.67369562, -0.52643216, -0.36124167, -0.18374951, +}; + +static const float tns_tmp2_map_0_4[16] = { + 0.00000000, 0.20791170, 0.40673664, 0.58778524, + 0.74314481, 0.86602539, 0.95105654, 0.99452192, + -0.99573416, -0.96182561, -0.89516330, -0.79801720, + -0.67369562, -0.52643216, -0.36124167, -0.18374951, +}; + +static const float *tns_tmp2_map[4] = { + tns_tmp2_map_0_3, + tns_tmp2_map_0_4, + tns_tmp2_map_1_3, + tns_tmp2_map_1_4 +}; +// @} + +#endif /* FFMPEG_AACDECTAB_H */ Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aacpsy.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aacpsy.h 2008-09-15 13:52:45 UTC (rev 27538) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aacpsy.h 2008-09-15 13:57:54 UTC (rev 27539) @@ -0,0 +1,50 @@ +/* + * AAC encoder psychoacoustic model + * Copyright (C) 2008 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_AACPSY_H +#define FFMPEG_AACPSY_H + +#include "avcodec.h" +#include "aac.h" +#include "lowpass.h" + +enum AACPsyModelType{ + AAC_PSY_TEST, ///< a sample model to exercise encoder + AAC_PSY_3GPP, ///< model following recommendations from 3GPP TS 26.403 + + AAC_NB_PSY_MODELS ///< total number of psychoacoustic models, since it's not a part of the ABI new models can be added freely +}; + +/** + * context used by psychoacoustic model + */ +typedef struct AACPsyContext { + AVCodecContext *avctx; ///< encoder context +}AACPsyContext; + +/** + * Cleanup model context at the end. + * + * @param ctx model context + */ +void ff_aac_psy_end(AACPsyContext *ctx); + +#endif /* FFMPEG_AACPSY_H */ Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aactab.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aactab.h 2008-09-15 13:52:45 UTC (rev 27538) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aactab.h 2008-09-15 13:57:54 UTC (rev 27539) @@ -0,0 +1,72 @@ +/* + * AAC data declarations + * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org ) + * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com ) + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file aactab.h + * AAC data declarations + * @author Oded Shimon ( ods15 ods15 dyndns org ) + * @author Maxim Gavrilov ( maxim.gavrilov gmail com ) + */ + +#ifndef FFMPEG_AACTAB_H +#define FFMPEG_AACTAB_H + +#include "mem.h" +#include "aac.h" + +#include + +/* NOTE: + * Tables in this file are used by the AAC decoder and will be used by the AAC + * encoder. + */ + +/* @name window coefficients + * @{ + */ +DECLARE_ALIGNED(16, extern float, ff_aac_kbd_long_1024[1024]); +DECLARE_ALIGNED(16, extern float, ff_aac_kbd_short_128[128]); +// @} + +/* @name number of scalefactor window bands for long and short transform windows respectively + * @{ + */ +extern const uint8_t ff_aac_num_swb_1024[]; +extern const uint8_t ff_aac_num_swb_128 []; +// @} + +extern const uint32_t ff_aac_scalefactor_code[121]; +extern const uint8_t ff_aac_scalefactor_bits[121]; + +extern const uint16_t *ff_aac_spectral_codes[11]; +extern const uint8_t *ff_aac_spectral_bits [11]; +extern const uint16_t ff_aac_spectral_sizes[11]; + +extern const float *ff_aac_codebook_vectors[]; + +#ifdef CONFIG_HARDCODED_TABLES +extern const float ff_aac_pow2sf_tab[316]; +#else +extern float ff_aac_pow2sf_tab[316]; +#endif /* CONFIG_HARDCODED_TABLES */ + +#endif /* FFMPEG_AACTAB_H */ Modified: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/ac3.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/ac3.h 2008-09-15 13:52:45 UTC (rev 27538) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/ac3.h 2008-09-15 13:57:54 UTC (rev 27539) @@ -1,31 +1,38 @@ /* - * Common code between AC3 encoder and decoder + * Common code between the AC-3 encoder and decoder * Copyright (c) 2000, 2001, 2002 Fabrice Bellard. * - * This library is free software; you can redistribute it and/or + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. + * version 2.1 of the License, or (at your option) any later version. * - * This library is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** * @file ac3.h - * Common code between AC3 encoder and decoder. + * Common code between the AC-3 encoder and decoder. */ +#ifndef FFMPEG_AC3_H +#define FFMPEG_AC3_H + +#include "ac3tab.h" + #define AC3_MAX_CODED_FRAME_SIZE 3840 /* in bytes */ #define AC3_MAX_CHANNELS 6 /* including LFE channel */ -#define NB_BLOCKS 6 /* number of PCM blocks inside an AC3 frame */ +#define NB_BLOCKS 6 /* number of PCM blocks inside an AC-3 frame */ #define AC3_FRAME_SIZE (NB_BLOCKS * 256) /* exponent encoding strategy */ @@ -36,26 +43,143 @@ #define EXP_D25 2 #define EXP_D45 3 +/** Delta bit allocation strategy */ +typedef enum { + DBA_REUSE = 0, + DBA_NEW, + DBA_NONE, + DBA_RESERVED +} AC3DeltaStrategy; + +/** Channel mode (audio coding mode) */ +typedef enum { + AC3_CHMODE_DUALMONO = 0, + AC3_CHMODE_MONO, + AC3_CHMODE_STEREO, + AC3_CHMODE_3F, + AC3_CHMODE_2F1R, + AC3_CHMODE_3F1R, + AC3_CHMODE_2F2R, + AC3_CHMODE_3F2R +} AC3ChannelMode; + typedef struct AC3BitAllocParameters { - int fscod; /* frequency */ - int halfratecod; - int sgain, sdecay, fdecay, dbknee, floor; - int cplfleak, cplsleak; + int sr_code; + int sr_shift; + int slow_gain, slow_decay, fast_decay, db_per_bit, floor; + int cpl_fast_leak, cpl_slow_leak; } AC3BitAllocParameters; -extern const uint16_t ac3_freqs[3]; -extern const uint16_t ac3_bitratetab[19]; -extern const int16_t ac3_window[256]; -extern const uint8_t sdecaytab[4]; -extern const uint8_t fdecaytab[4]; -extern const uint16_t sgaintab[4]; -extern const uint16_t dbkneetab[4]; -extern const uint16_t floortab[8]; -extern const uint16_t fgaintab[8]; +/** + * @struct AC3HeaderInfo + * Coded AC-3 header values up to the lfeon element, plus derived values. + */ +typedef struct { + /** @defgroup coded Coded elements + * @{ + */ + uint16_t sync_word; + uint16_t crc1; + uint8_t sr_code; + uint8_t bitstream_id; + uint8_t channel_mode; + uint8_t lfe_on; + uint8_t frame_type; + int substreamid; ///< substream identification + int center_mix_level; ///< Center mix level index + int surround_mix_level; ///< Surround mix level index + uint16_t channel_map; + int num_blocks; ///< number of audio blocks + /** @} */ + /** @defgroup derived Derived values + * @{ + */ + uint8_t sr_shift; + uint16_t sample_rate; + uint32_t bit_rate; + uint8_t channels; + uint16_t frame_size; + /** @} */ +} AC3HeaderInfo; + +typedef enum { + EAC3_FRAME_TYPE_INDEPENDENT = 0, + EAC3_FRAME_TYPE_DEPENDENT, + EAC3_FRAME_TYPE_AC3_CONVERT, + EAC3_FRAME_TYPE_RESERVED +} EAC3FrameType; + void ac3_common_init(void); + +/** + * Calculates the log power-spectral density of the input signal. + * This gives a rough estimate of signal power in the frequency domain by using + * the spectral envelope (exponents). The psd is also separately grouped + * into critical bands for use in the calculating the masking curve. + * 128 units in psd = -6 dB. The dbknee parameter in AC3BitAllocParameters + * determines the reference level. + * + * @param[in] exp frequency coefficient exponents + * @param[in] start starting bin location + * @param[in] end ending bin location + * @param[out] psd signal power for each frequency bin + * @param[out] band_psd signal power for each critical band + */ +void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd, + int16_t *band_psd); + +/** + * Calculates the masking curve. + * First, the excitation is calculated using parameters in \p s and the signal + * power in each critical band. The excitation is compared with a predefined + * hearing threshold table to produce the masking curve. If delta bit + * allocation information is provided, it is used for adjusting the masking + * curve, usually to give a closer match to a better psychoacoustic model. + * + * @param[in] s adjustable bit allocation parameters + * @param[in] band_psd signal power for each critical band + * @param[in] start starting bin location + * @param[in] end ending bin location + * @param[in] fast_gain fast gain (estimated signal-to-mask ratio) + * @param[in] is_lfe whether or not the channel being processed is the LFE + * @param[in] dba_mode delta bit allocation mode (none, reuse, or new) + * @param[in] dba_nsegs number of delta segments + * @param[in] dba_offsets location offsets for each segment + * @param[in] dba_lengths length of each segment + * @param[in] dba_values delta bit allocation for each segment + * @param[out] mask calculated masking curve + */ +void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd, + int start, int end, int fast_gain, int is_lfe, + int dba_mode, int dba_nsegs, uint8_t *dba_offsets, + uint8_t *dba_lengths, uint8_t *dba_values, + int16_t *mask); + +/** + * Calculates bit allocation pointers. + * The SNR is the difference between the masking curve and the signal. AC-3 + * uses this value for each frequency bin to allocate bits. The \p snroffset + * parameter is a global adjustment to the SNR for all bins. + * + * @param[in] mask masking curve + * @param[in] psd signal power for each frequency bin + * @param[in] start starting bin location + * @param[in] end ending bin location + * @param[in] snr_offset SNR adjustment + * @param[in] floor noise floor + * @param[in] bap_tab look-up table for bit allocation pointers + * @param[out] bap bit allocation pointers + */ +void ff_ac3_bit_alloc_calc_bap(int16_t *mask, int16_t *psd, int start, int end, + int snr_offset, int floor, + const uint8_t *bap_tab, uint8_t *bap); + void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap, int8_t *exp, int start, int end, - int snroffset, int fgain, int is_lfe, - int deltbae,int deltnseg, - uint8_t *deltoffst, uint8_t *deltlen, uint8_t *deltba); + int snr_offset, int fast_gain, int is_lfe, + int dba_mode, int dba_nsegs, + uint8_t *dba_offsets, uint8_t *dba_lengths, + uint8_t *dba_values); + +#endif /* FFMPEG_AC3_H */ Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/ac3_parser.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/ac3_parser.h 2008-09-15 13:52:45 UTC (rev 27538) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/ac3_parser.h 2008-09-15 13:57:54 UTC (rev 27539) @@ -0,0 +1,61 @@ +/* + * AC-3 parser prototypes + * Copyright (c) 2003 Fabrice Bellard. + * Copyright (c) 2003 Michael Niedermayer. + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_AC3_PARSER_H +#define FFMPEG_AC3_PARSER_H + +#include "ac3.h" +#include "bitstream.h" + +typedef enum { + AC3_PARSE_ERROR_SYNC = -1, + AC3_PARSE_ERROR_BSID = -2, + AC3_PARSE_ERROR_SAMPLE_RATE = -3, + AC3_PARSE_ERROR_FRAME_SIZE = -4, + AC3_PARSE_ERROR_FRAME_TYPE = -5, + AC3_PARSE_ERROR_CRC = -6, +} AC3ParseError; + +/** + * Parses AC-3 frame header. + * Parses the header up to the lfeon element, which is the first 52 or 54 bits + * depending on the audio coding mode. + * @param gbc[in] BitContext containing the first 54 bits of the frame. + * @param hdr[out] Pointer to struct where header info is written. + * @return Returns 0 on success, -1 if there is a sync word mismatch, + * -2 if the bsid (version) element is invalid, -3 if the fscod (sample rate) + * element is invalid, or -4 if the frmsizecod (bit rate) element is invalid. + */ +int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr); + +/** + * Parses AC-3 frame header and sets channel_map + * Parses the header up to the lfeon (channel_map in E-AC-3) + * element, which is the first 52, 54 or 104 bits depending + * on the audio coding mode. + * @param gbc[in] BitContext containing the first 54 bits of the frame. + * @param hdr[out] Pointer to struct where header info is written. + * @return value returned by ff_ac3_parse_header + */ +int ff_ac3_parse_header_full(GetBitContext *gbc, AC3HeaderInfo *hdr); + +#endif /* FFMPEG_AC3_PARSER_H */ Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/ac3dec.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/ac3dec.h 2008-09-15 13:52:45 UTC (rev 27538) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/ac3dec.h 2008-09-15 13:57:54 UTC (rev 27539) @@ -0,0 +1,171 @@ +/* + * Common code between the AC-3 and E-AC-3 decoders + * Copyright (c) 2007 Bartlomiej Wolowiec + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file ac3.h + * Common code between the AC-3 and E-AC-3 decoders. + */ + +#ifndef FFMPEG_AC3DEC_H [... truncated: 5299 lines follow ...] From dlmcpaul at mail.berlios.de Mon Sep 15 16:00:27 2008 From: dlmcpaul at mail.berlios.de (dlmcpaul at BerliOS) Date: Mon, 15 Sep 2008 16:00:27 +0200 Subject: [Haiku-commits] r27540 - haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec Message-ID: <200809151400.m8FE0R44032464@sheep.berlios.de> Author: dlmcpaul Date: 2008-09-15 16:00:22 +0200 (Mon, 15 Sep 2008) New Revision: 27540 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27540&view=rev Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aac.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aac_ac3_parser.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aac_parser.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aacenc.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aacpsy.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aactab.c Log: Update avcodec to 20080825 Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aac.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aac.c 2008-09-15 13:57:54 UTC (rev 27539) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aac.c 2008-09-15 14:00:22 UTC (rev 27540) @@ -0,0 +1,1465 @@ +/* + * AAC decoder + * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org ) + * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com ) + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file aac.c + * AAC decoder + * @author Oded Shimon ( ods15 ods15 dyndns org ) + * @author Maxim Gavrilov ( maxim.gavrilov gmail com ) + */ + +/* + * supported tools + * + * Support? Name + * N (code in SoC repo) gain control + * Y block switching + * Y window shapes - standard + * N window shapes - Low Delay + * Y filterbank - standard + * N (code in SoC repo) filterbank - Scalable Sample Rate + * Y Temporal Noise Shaping + * N (code in SoC repo) Long Term Prediction + * Y intensity stereo + * Y channel coupling + * N frequency domain prediction + * Y Perceptual Noise Substitution + * Y Mid/Side stereo + * N Scalable Inverse AAC Quantization + * N Frequency Selective Switch + * N upsampling filter + * Y quantization & coding - AAC + * N quantization & coding - TwinVQ + * N quantization & coding - BSAC + * N AAC Error Resilience tools + * N Error Resilience payload syntax + * N Error Protection tool + * N CELP + * N Silence Compression + * N HVXC + * N HVXC 4kbits/s VR + * N Structured Audio tools + * N Structured Audio Sample Bank Format + * N MIDI + * N Harmonic and Individual Lines plus Noise + * N Text-To-Speech Interface + * N (in progress) Spectral Band Replication + * Y (not in this code) Layer-1 + * Y (not in this code) Layer-2 + * Y (not in this code) Layer-3 + * N SinuSoidal Coding (Transient, Sinusoid, Noise) + * N (planned) Parametric Stereo + * N Direct Stream Transfer + * + * Note: - HE AAC v1 comprises LC AAC with Spectral Band Replication. + * - HE AAC v2 comprises LC AAC with Spectral Band Replication and + Parametric Stereo. + */ + + +#include "avcodec.h" +#include "bitstream.h" +#include "dsputil.h" + +#include "aac.h" +#include "aactab.h" +#include "aacdectab.h" +#include "mpeg4audio.h" + +#include +#include +#include +#include + +static VLC vlc_scalefactors; +static VLC vlc_spectral[11]; + + +/** + * Configure output channel order based on the current program configuration element. + * + * @param che_pos current channel position configuration + * @param new_che_pos New channel position configuration - we only do something if it differs from the current one. + * + * @return Returns error status. 0 - OK, !0 - error + */ +static int output_configure(AACContext *ac, enum ChannelPosition che_pos[4][MAX_ELEM_ID], + enum ChannelPosition new_che_pos[4][MAX_ELEM_ID]) { + AVCodecContext *avctx = ac->avccontext; + int i, type, channels = 0; + + if(!memcmp(che_pos, new_che_pos, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0]))) + return 0; /* no change */ + + memcpy(che_pos, new_che_pos, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0])); + + /* Allocate or free elements depending on if they are in the + * current program configuration. + * + * Set up default 1:1 output mapping. + * + * For a 5.1 stream the output order will be: + * [ Center ] [ Front Left ] [ Front Right ] [ LFE ] [ Surround Left ] [ Surround Right ] + */ + + for(i = 0; i < MAX_ELEM_ID; i++) { + for(type = 0; type < 4; type++) { + if(che_pos[type][i]) { + if(!ac->che[type][i] && !(ac->che[type][i] = av_mallocz(sizeof(ChannelElement)))) + return AVERROR(ENOMEM); + if(type != TYPE_CCE) { + ac->output_data[channels++] = ac->che[type][i]->ch[0].ret; + if(type == TYPE_CPE) { + ac->output_data[channels++] = ac->che[type][i]->ch[1].ret; + } + } + } else + av_freep(&ac->che[type][i]); + } + } + + avctx->channels = channels; + return 0; +} + +/** + * Decode an array of 4 bit element IDs, optionally interleaved with a stereo/mono switching bit. + * + * @param cpe_map Stereo (Channel Pair Element) map, NULL if stereo bit is not present. + * @param sce_map mono (Single Channel Element) map + * @param type speaker type/position for these channels + */ +static void decode_channel_map(enum ChannelPosition *cpe_map, + enum ChannelPosition *sce_map, enum ChannelPosition type, GetBitContext * gb, int n) { + while(n--) { + enum ChannelPosition *map = cpe_map && get_bits1(gb) ? cpe_map : sce_map; // stereo or mono map + map[get_bits(gb, 4)] = type; + } +} + +/** + * Decode program configuration element; reference: table 4.2. + * + * @param new_che_pos New channel position configuration - we only do something if it differs from the current one. + * + * @return Returns error status. 0 - OK, !0 - error + */ +static int decode_pce(AACContext * ac, enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], + GetBitContext * gb) { + int num_front, num_side, num_back, num_lfe, num_assoc_data, num_cc; + + skip_bits(gb, 2); // object_type + + ac->m4ac.sampling_index = get_bits(gb, 4); + if(ac->m4ac.sampling_index > 11) { + av_log(ac->avccontext, AV_LOG_ERROR, "invalid sampling rate index %d\n", ac->m4ac.sampling_index); + return -1; + } + ac->m4ac.sample_rate = ff_mpeg4audio_sample_rates[ac->m4ac.sampling_index]; + num_front = get_bits(gb, 4); + num_side = get_bits(gb, 4); + num_back = get_bits(gb, 4); + num_lfe = get_bits(gb, 2); + num_assoc_data = get_bits(gb, 3); + num_cc = get_bits(gb, 4); + + if (get_bits1(gb)) + skip_bits(gb, 4); // mono_mixdown_tag + if (get_bits1(gb)) + skip_bits(gb, 4); // stereo_mixdown_tag + + if (get_bits1(gb)) + skip_bits(gb, 3); // mixdown_coeff_index and pseudo_surround + + decode_channel_map(new_che_pos[TYPE_CPE], new_che_pos[TYPE_SCE], AAC_CHANNEL_FRONT, gb, num_front); + decode_channel_map(new_che_pos[TYPE_CPE], new_che_pos[TYPE_SCE], AAC_CHANNEL_SIDE, gb, num_side ); + decode_channel_map(new_che_pos[TYPE_CPE], new_che_pos[TYPE_SCE], AAC_CHANNEL_BACK, gb, num_back ); + decode_channel_map(NULL, new_che_pos[TYPE_LFE], AAC_CHANNEL_LFE, gb, num_lfe ); + + skip_bits_long(gb, 4 * num_assoc_data); + + decode_channel_map(new_che_pos[TYPE_CCE], new_che_pos[TYPE_CCE], AAC_CHANNEL_CC, gb, num_cc ); + + align_get_bits(gb); + + /* comment field, first byte is length */ + skip_bits_long(gb, 8 * get_bits(gb, 8)); + return 0; +} + +/** + * Set up channel positions based on a default channel configuration + * as specified in table 1.17. + * + * @param new_che_pos New channel position configuration - we only do something if it differs from the current one. + * + * @return Returns error status. 0 - OK, !0 - error + */ +static int set_default_channel_config(AACContext *ac, enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], + int channel_config) +{ + if(channel_config < 1 || channel_config > 7) { + av_log(ac->avccontext, AV_LOG_ERROR, "invalid default channel configuration (%d)\n", + channel_config); + return -1; + } + + /* default channel configurations: + * + * 1ch : front center (mono) + * 2ch : L + R (stereo) + * 3ch : front center + L + R + * 4ch : front center + L + R + back center + * 5ch : front center + L + R + back stereo + * 6ch : front center + L + R + back stereo + LFE + * 7ch : front center + L + R + outer front left + outer front right + back stereo + LFE + */ + + if(channel_config != 2) + new_che_pos[TYPE_SCE][0] = AAC_CHANNEL_FRONT; // front center (or mono) + if(channel_config > 1) + new_che_pos[TYPE_CPE][0] = AAC_CHANNEL_FRONT; // L + R (or stereo) + if(channel_config == 4) + new_che_pos[TYPE_SCE][1] = AAC_CHANNEL_BACK; // back center + if(channel_config > 4) + new_che_pos[TYPE_CPE][(channel_config == 7) + 1] + = AAC_CHANNEL_BACK; // back stereo + if(channel_config > 5) + new_che_pos[TYPE_LFE][0] = AAC_CHANNEL_LFE; // LFE + if(channel_config == 7) + new_che_pos[TYPE_CPE][1] = AAC_CHANNEL_FRONT; // outer front left + outer front right + + return 0; +} + +/** + * Decode GA "General Audio" specific configuration; reference: table 4.1. + * + * @return Returns error status. 0 - OK, !0 - error + */ +static int decode_ga_specific_config(AACContext * ac, GetBitContext * gb, int channel_config) { + enum ChannelPosition new_che_pos[4][MAX_ELEM_ID]; + int extension_flag, ret; + + if(get_bits1(gb)) { // frameLengthFlag + av_log_missing_feature(ac->avccontext, "960/120 MDCT window is", 1); + return -1; + } + + if (get_bits1(gb)) // dependsOnCoreCoder + skip_bits(gb, 14); // coreCoderDelay + extension_flag = get_bits1(gb); + + if(ac->m4ac.object_type == AOT_AAC_SCALABLE || + ac->m4ac.object_type == AOT_ER_AAC_SCALABLE) + skip_bits(gb, 3); // layerNr + + memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0])); + if (channel_config == 0) { + skip_bits(gb, 4); // element_instance_tag + if((ret = decode_pce(ac, new_che_pos, gb))) + return ret; + } else { + if((ret = set_default_channel_config(ac, new_che_pos, channel_config))) + return ret; + } + if((ret = output_configure(ac, ac->che_pos, new_che_pos))) + return ret; + + if (extension_flag) { + switch (ac->m4ac.object_type) { + case AOT_ER_BSAC: + skip_bits(gb, 5); // numOfSubFrame + skip_bits(gb, 11); // layer_length + break; + case AOT_ER_AAC_LC: + case AOT_ER_AAC_LTP: + case AOT_ER_AAC_SCALABLE: + case AOT_ER_AAC_LD: + skip_bits(gb, 3); /* aacSectionDataResilienceFlag + * aacScalefactorDataResilienceFlag + * aacSpectralDataResilienceFlag + */ + break; + } + skip_bits1(gb); // extensionFlag3 (TBD in version 3) + } + return 0; +} + +/** + * Decode audio specific configuration; reference: table 1.13. + * + * @param data pointer to AVCodecContext extradata + * @param data_size size of AVCCodecContext extradata + * + * @return Returns error status. 0 - OK, !0 - error + */ +static int decode_audio_specific_config(AACContext * ac, void *data, int data_size) { + GetBitContext gb; + int i; + + init_get_bits(&gb, data, data_size * 8); + + if((i = ff_mpeg4audio_get_config(&ac->m4ac, data, data_size)) < 0) { + av_log(ac->avccontext, AV_LOG_ERROR, "ff_mpeg4audio_get_config failed\n"); + return -1; + } + + av_log(ac->avccontext, AV_LOG_DEBUG, "Details decoded Sample Rate %d ext Sample Rate %d Channels %d\n",ac->m4ac.sample_rate, ac->m4ac.ext_sample_rate, ac->m4ac.chan_config); + + if(ac->m4ac.sampling_index > 11) { + av_log(ac->avccontext, AV_LOG_ERROR, "invalid sampling rate index %d\n", ac->m4ac.sampling_index); + return -1; + } + + skip_bits_long(&gb, i); + + switch (ac->m4ac.object_type) { + case AOT_AAC_LC: + if (decode_ga_specific_config(ac, &gb, ac->m4ac.chan_config)) { + av_log(ac->avccontext, AV_LOG_ERROR, "decode_ga_specific_config failed\n"); + return -1; + } + break; + default: + av_log(ac->avccontext, AV_LOG_ERROR, "Audio object type %s%d is not supported.\n", + ac->m4ac.sbr == 1? "SBR+" : "", ac->m4ac.object_type); + return -1; + } + return 0; +} + +/** + * linear congruential pseudorandom number generator + * + * @param previous_val pointer to the current state of the generator + * + * @return Returns a 32-bit pseudorandom integer + */ +static av_always_inline int lcg_random(int previous_val) { + return previous_val * 1664525 + 1013904223; +} + +static av_cold int aac_decode_init(AVCodecContext * avccontext) { + AACContext * ac = avccontext->priv_data; + int i; + + ac->avccontext = avccontext; + + if (avccontext->extradata_size <= 0 || + decode_audio_specific_config(ac, avccontext->extradata, avccontext->extradata_size)) { + av_log(avccontext, AV_LOG_ERROR, "no audio config data supplied (%ld) or data invalid\n",avccontext->extradata_size); + + return -1; + } + + avccontext->sample_fmt = SAMPLE_FMT_S16; + avccontext->sample_rate = ac->m4ac.sample_rate; + avccontext->frame_size = 1024; + + AAC_INIT_VLC_STATIC( 0, 144); + AAC_INIT_VLC_STATIC( 1, 114); + AAC_INIT_VLC_STATIC( 2, 188); + AAC_INIT_VLC_STATIC( 3, 180); + AAC_INIT_VLC_STATIC( 4, 172); + AAC_INIT_VLC_STATIC( 5, 140); + AAC_INIT_VLC_STATIC( 6, 168); + AAC_INIT_VLC_STATIC( 7, 114); + AAC_INIT_VLC_STATIC( 8, 262); + AAC_INIT_VLC_STATIC( 9, 248); + AAC_INIT_VLC_STATIC(10, 384); + + dsputil_init(&ac->dsp, avccontext); + + ac->random_state = 0x1f2e3d4c; + + // -1024 - Compensate wrong IMDCT method. + // 32768 - Required to scale values to the correct range for the bias method + // for float to int16 conversion. + + if(ac->dsp.float_to_int16 == ff_float_to_int16_c) { + ac->add_bias = 385.0f; + ac->sf_scale = 1. / (-1024. * 32768.); + ac->sf_offset = 0; + } else { + ac->add_bias = 0.0f; + ac->sf_scale = 1. / -1024.; + ac->sf_offset = 60; + } + +#ifndef CONFIG_HARDCODED_TABLES + for (i = 0; i < 316; i++) + ff_aac_pow2sf_tab[i] = pow(2, (i - 200)/4.); +#endif /* CONFIG_HARDCODED_TABLES */ + + INIT_VLC_STATIC(&vlc_scalefactors, 7, sizeof(ff_aac_scalefactor_code)/sizeof(ff_aac_scalefactor_code[0]), + ff_aac_scalefactor_bits, sizeof(ff_aac_scalefactor_bits[0]), sizeof(ff_aac_scalefactor_bits[0]), + ff_aac_scalefactor_code, sizeof(ff_aac_scalefactor_code[0]), sizeof(ff_aac_scalefactor_code[0]), + 352); + + ff_mdct_init(&ac->mdct, 11, 1); + ff_mdct_init(&ac->mdct_small, 8, 1); + // window initialization + ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024); + ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128); + ff_sine_window_init(ff_sine_1024, 1024); + ff_sine_window_init(ff_sine_128, 128); + + return 0; +} + +/** + * Skip data_stream_element; reference: table 4.10. + */ +static void skip_data_stream_element(GetBitContext * gb) { + int byte_align = get_bits1(gb); + int count = get_bits(gb, 8); + if (count == 255) + count += get_bits(gb, 8); + if (byte_align) + align_get_bits(gb); + skip_bits_long(gb, 8 * count); +} + +/** + * Decode Individual Channel Stream info; reference: table 4.6. + * + * @param common_window Channels have independent [0], or shared [1], Individual Channel Stream information. + */ +static int decode_ics_info(AACContext * ac, IndividualChannelStream * ics, GetBitContext * gb, int common_window) { + if (get_bits1(gb)) { + av_log(ac->avccontext, AV_LOG_ERROR, "Reserved bit set.\n"); + memset(ics, 0, sizeof(IndividualChannelStream)); + return -1; + } + ics->window_sequence[1] = ics->window_sequence[0]; + ics->window_sequence[0] = get_bits(gb, 2); + ics->use_kb_window[1] = ics->use_kb_window[0]; + ics->use_kb_window[0] = get_bits1(gb); + ics->num_window_groups = 1; + ics->group_len[0] = 1; + if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { + int i; + ics->max_sfb = get_bits(gb, 4); + for (i = 0; i < 7; i++) { + if (get_bits1(gb)) { + ics->group_len[ics->num_window_groups-1]++; + } else { + ics->num_window_groups++; + ics->group_len[ics->num_window_groups-1] = 1; + } + } + ics->num_windows = 8; + ics->swb_offset = swb_offset_128[ac->m4ac.sampling_index]; + ics->num_swb = ff_aac_num_swb_128[ac->m4ac.sampling_index]; + ics->tns_max_bands = tns_max_bands_128[ac->m4ac.sampling_index]; + } else { + ics->max_sfb = get_bits(gb, 6); + ics->num_windows = 1; + ics->swb_offset = swb_offset_1024[ac->m4ac.sampling_index]; + ics->num_swb = ff_aac_num_swb_1024[ac->m4ac.sampling_index]; + ics->tns_max_bands = tns_max_bands_1024[ac->m4ac.sampling_index]; + if (get_bits1(gb)) { + av_log_missing_feature(ac->avccontext, "Predictor bit set but LTP is", 1); + memset(ics, 0, sizeof(IndividualChannelStream)); + return -1; + } + } + + if(ics->max_sfb > ics->num_swb) { + av_log(ac->avccontext, AV_LOG_ERROR, + "Number of scalefactor bands in group (%d) exceeds limit (%d).\n", + ics->max_sfb, ics->num_swb); + memset(ics, 0, sizeof(IndividualChannelStream)); + return -1; + } + + return 0; +} + +/** + * Decode band types (section_data payload); reference: table 4.46. + * + * @param band_type array of the used band type + * @param band_type_run_end array of the last scalefactor band of a band type run + * + * @return Returns error status. 0 - OK, !0 - error + */ +static int decode_band_types(AACContext * ac, enum BandType band_type[120], + int band_type_run_end[120], GetBitContext * gb, IndividualChannelStream * ics) { + int g, idx = 0; + const int bits = (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) ? 3 : 5; + for (g = 0; g < ics->num_window_groups; g++) { + int k = 0; + while (k < ics->max_sfb) { + uint8_t sect_len = k; + int sect_len_incr; + int sect_band_type = get_bits(gb, 4); + if (sect_band_type == 12) { + av_log(ac->avccontext, AV_LOG_ERROR, "invalid band type\n"); + return -1; + } + while ((sect_len_incr = get_bits(gb, bits)) == (1 << bits)-1) + sect_len += sect_len_incr; + sect_len += sect_len_incr; + if (sect_len > ics->max_sfb) { + av_log(ac->avccontext, AV_LOG_ERROR, + "Number of bands (%d) exceeds limit (%d).\n", + sect_len, ics->max_sfb); + return -1; + } + for (; k < sect_len; k++) { + band_type [idx] = sect_band_type; + band_type_run_end[idx++] = sect_len; + } + } + } + return 0; +} + +/** + * Decode scalefactors; reference: table 4.47. + * + * @param global_gain first scalefactor value as scalefactors are differentially coded + * @param band_type array of the used band type + * @param band_type_run_end array of the last scalefactor band of a band type run + * @param sf array of scalefactors or intensity stereo positions + * + * @return Returns error status. 0 - OK, !0 - error + */ +static int decode_scalefactors(AACContext * ac, float sf[120], GetBitContext * gb, + unsigned int global_gain, IndividualChannelStream * ics, + enum BandType band_type[120], int band_type_run_end[120]) { + const int sf_offset = ac->sf_offset + (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE ? 12 : 0); + int g, i, idx = 0; + int offset[3] = { global_gain, global_gain - 90, 100 }; + int noise_flag = 1; + static const char *sf_str[3] = { "Global gain", "Noise gain", "Intensity stereo position" }; + for (g = 0; g < ics->num_window_groups; g++) { + for (i = 0; i < ics->max_sfb;) { + int run_end = band_type_run_end[idx]; + if (band_type[idx] == ZERO_BT) { + for(; i < run_end; i++, idx++) + sf[idx] = 0.; + }else if((band_type[idx] == INTENSITY_BT) || (band_type[idx] == INTENSITY_BT2)) { + for(; i < run_end; i++, idx++) { + offset[2] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60; + if(offset[2] > 255U) { + av_log(ac->avccontext, AV_LOG_ERROR, + "%s (%d) out of range.\n", sf_str[2], offset[2]); + return -1; + } + sf[idx] = ff_aac_pow2sf_tab[-offset[2] + 300]; + } + }else if(band_type[idx] == NOISE_BT) { + for(; i < run_end; i++, idx++) { + if(noise_flag-- > 0) + offset[1] += get_bits(gb, 9) - 256; + else + offset[1] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60; + if(offset[1] > 255U) { + av_log(ac->avccontext, AV_LOG_ERROR, + "%s (%d) out of range.\n", sf_str[1], offset[1]); + return -1; + } + sf[idx] = -ff_aac_pow2sf_tab[ offset[1] + sf_offset]; + } + }else { + for(; i < run_end; i++, idx++) { + offset[0] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60; + if(offset[0] > 255U) { + av_log(ac->avccontext, AV_LOG_ERROR, + "%s (%d) out of range.\n", sf_str[0], offset[0]); + return -1; + } + sf[idx] = -ff_aac_pow2sf_tab[ offset[0] + sf_offset]; + } + } + } + } + return 0; +} + +/** + * Decode pulse data; reference: table 4.7. + */ +static void decode_pulses(Pulse * pulse, GetBitContext * gb, const uint16_t * swb_offset) { + int i; + pulse->num_pulse = get_bits(gb, 2) + 1; + pulse->pos[0] = get_bits(gb, 5) + swb_offset[get_bits(gb, 6)]; + pulse->amp[0] = get_bits(gb, 4); + for (i = 1; i < pulse->num_pulse; i++) { + pulse->pos[i] = get_bits(gb, 5) + pulse->pos[i-1]; + pulse->amp[i] = get_bits(gb, 4); + } +} + +/** + * Decode Temporal Noise Shaping data; reference: table 4.48. + * + * @return Returns error status. 0 - OK, !0 - error + */ +static int decode_tns(AACContext * ac, TemporalNoiseShaping * tns, + GetBitContext * gb, const IndividualChannelStream * ics) { + int w, filt, i, coef_len, coef_res, coef_compress; + const int is8 = ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE; + const int tns_max_order = is8 ? 7 : ac->m4ac.object_type == AOT_AAC_MAIN ? 20 : 12; + for (w = 0; w < ics->num_windows; w++) { + if ((tns->n_filt[w] = get_bits(gb, 2 - is8))) { + coef_res = get_bits1(gb); + + for (filt = 0; filt < tns->n_filt[w]; filt++) { + int tmp2_idx; + tns->length[w][filt] = get_bits(gb, 6 - 2*is8); + + if ((tns->order[w][filt] = get_bits(gb, 5 - 2*is8)) > tns_max_order) { + av_log(ac->avccontext, AV_LOG_ERROR, "TNS filter order %d is greater than maximum %d.", + tns->order[w][filt], tns_max_order); + tns->order[w][filt] = 0; + return -1; + } + tns->direction[w][filt] = get_bits1(gb); + coef_compress = get_bits1(gb); + coef_len = coef_res + 3 - coef_compress; + tmp2_idx = 2*coef_compress + coef_res; + + for (i = 0; i < tns->order[w][filt]; i++) + tns->coef[w][filt][i] = tns_tmp2_map[tmp2_idx][get_bits(gb, coef_len)]; + } + } + } + return 0; +} + +/** + * Decode Mid/Side data; reference: table 4.54. + * + * @param ms_present Indicates mid/side stereo presence. [0] mask is all 0s; + * [1] mask is decoded from bitstream; [2] mask is all 1s; + * [3] reserved for scalable AAC + */ +static void decode_mid_side_stereo(ChannelElement * cpe, GetBitContext * gb, + int ms_present) { + int idx; + if (ms_present == 1) { + for (idx = 0; idx < cpe->ch[0].ics.num_window_groups * cpe->ch[0].ics.max_sfb; idx++) + cpe->ms_mask[idx] = get_bits1(gb); + } else if (ms_present == 2) { + memset(cpe->ms_mask, 1, cpe->ch[0].ics.num_window_groups * cpe->ch[0].ics.max_sfb * sizeof(cpe->ms_mask[0])); + } +} + +/** + * Decode spectral data; reference: table 4.50. + * Dequantize and scale spectral data; reference: 4.6.3.3. + * + * @param coef array of dequantized, scaled spectral data + * @param sf array of scalefactors or intensity stereo positions + * @param pulse_present set if pulses are present + * @param pulse pointer to pulse data struct + * @param band_type array of the used band type + * + * @return Returns error status. 0 - OK, !0 - error + */ +static int decode_spectrum_and_dequant(AACContext * ac, float coef[1024], GetBitContext * gb, float sf[120], + int pulse_present, const Pulse * pulse, const IndividualChannelStream * ics, enum BandType band_type[120]) { + int i, k, g, idx = 0; + const int c = 1024/ics->num_windows; + const uint16_t * offsets = ics->swb_offset; + float *coef_base = coef; + + for (g = 0; g < ics->num_windows; g++) + memset(coef + g * 128 + offsets[ics->max_sfb], 0, sizeof(float)*(c - offsets[ics->max_sfb])); + + for (g = 0; g < ics->num_window_groups; g++) { + for (i = 0; i < ics->max_sfb; i++, idx++) { + const int cur_band_type = band_type[idx]; + const int dim = cur_band_type >= FIRST_PAIR_BT ? 2 : 4; + const int is_cb_unsigned = IS_CODEBOOK_UNSIGNED(cur_band_type); + int group; + if (cur_band_type == ZERO_BT) { + for (group = 0; group < ics->group_len[g]; group++) { + memset(coef + group * 128 + offsets[i], 0, (offsets[i+1] - offsets[i])*sizeof(float)); + } + }else if (cur_band_type == NOISE_BT) { + const float scale = sf[idx] / ((offsets[i+1] - offsets[i]) * PNS_MEAN_ENERGY); + for (group = 0; group < ics->group_len[g]; group++) { + for (k = offsets[i]; k < offsets[i+1]; k++) { + ac->random_state = lcg_random(ac->random_state); + coef[group*128+k] = ac->random_state * scale; + } + } + }else if (cur_band_type != INTENSITY_BT2 && cur_band_type != INTENSITY_BT) { + for (group = 0; group < ics->group_len[g]; group++) { + for (k = offsets[i]; k < offsets[i+1]; k += dim) { + const int index = get_vlc2(gb, vlc_spectral[cur_band_type - 1].table, 6, 3); + const int coef_tmp_idx = (group << 7) + k; + const float *vq_ptr; + int j; + if(index >= ff_aac_spectral_sizes[cur_band_type - 1]) { + av_log(ac->avccontext, AV_LOG_ERROR, + "Read beyond end of ff_aac_codebook_vectors[%d][]. index %d >= %d\n", + cur_band_type - 1, index, ff_aac_spectral_sizes[cur_band_type - 1]); + return -1; + } + vq_ptr = &ff_aac_codebook_vectors[cur_band_type - 1][index * dim]; + if (is_cb_unsigned) { + for (j = 0; j < dim; j++) + if (vq_ptr[j]) + coef[coef_tmp_idx + j] = 1 - 2*(int)get_bits1(gb); + }else { + for (j = 0; j < dim; j++) + coef[coef_tmp_idx + j] = 1.0f; + } + if (cur_band_type == ESC_BT) { + for (j = 0; j < 2; j++) { + if (vq_ptr[j] == 64.0f) { + int n = 4; + /* The total length of escape_sequence must be < 22 bits according + to the specification (i.e. max is 11111111110xxxxxxxxxx). */ + while (get_bits1(gb) && n < 15) n++; + if(n == 15) { + av_log(ac->avccontext, AV_LOG_ERROR, "error in spectral data, ESC overflow\n"); + return -1; + } + n = (1<group_len[g]<<7; + } + + if (pulse_present) { + for(i = 0; i < pulse->num_pulse; i++){ + float co = coef_base[ pulse->pos[i] ]; + float ico = co / sqrtf(sqrtf(fabsf(co))) + pulse->amp[i]; + coef_base[ pulse->pos[i] ] = cbrtf(fabsf(ico)) * ico; + } + } + return 0; +} + +/** + * Decode an individual_channel_stream payload; reference: table 4.44. + * + * @param common_window Channels have independent [0], or shared [1], Individual Channel Stream information. + * @param scale_flag scalable [1] or non-scalable [0] AAC (Unused until scalable AAC is implemented.) + * + * @return Returns error status. 0 - OK, !0 - error + */ +static int decode_ics(AACContext * ac, SingleChannelElement * sce, GetBitContext * gb, int common_window, int scale_flag) { + Pulse pulse; + TemporalNoiseShaping * tns = &sce->tns; + IndividualChannelStream * ics = &sce->ics; + float * out = sce->coeffs; + int global_gain, pulse_present = 0; + + /* This assignment is to silence a GCC warning about the variable being used + * uninitialized when in fact it always is. + */ + pulse.num_pulse = 0; + + global_gain = get_bits(gb, 8); + + if (!common_window && !scale_flag) { + if (decode_ics_info(ac, ics, gb, 0) < 0) + return -1; + } + + if (decode_band_types(ac, sce->band_type, sce->band_type_run_end, gb, ics) < 0) + return -1; + if (decode_scalefactors(ac, sce->sf, gb, global_gain, ics, sce->band_type, sce->band_type_run_end) < 0) + return -1; + + pulse_present = 0; + if (!scale_flag) { + if ((pulse_present = get_bits1(gb))) { + if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { + av_log(ac->avccontext, AV_LOG_ERROR, "Pulse tool not allowed in eight short sequence.\n"); + return -1; + } + decode_pulses(&pulse, gb, ics->swb_offset); + } + if ((tns->present = get_bits1(gb)) && decode_tns(ac, tns, gb, ics)) + return -1; + if (get_bits1(gb)) { + av_log_missing_feature(ac->avccontext, "SSR", 1); + return -1; + } + } + + if (decode_spectrum_and_dequant(ac, out, gb, sce->sf, pulse_present, &pulse, ics, sce->band_type) < 0) + return -1; + return 0; +} + +/** + * Mid/Side stereo decoding; reference: 4.6.8.1.3. + */ +static void apply_mid_side_stereo(ChannelElement * cpe) { + const IndividualChannelStream * ics = &cpe->ch[0].ics; + float *ch0 = cpe->ch[0].coeffs; + float *ch1 = cpe->ch[1].coeffs; + int g, i, k, group, idx = 0; + const uint16_t * offsets = ics->swb_offset; + for (g = 0; g < ics->num_window_groups; g++) { + for (i = 0; i < ics->max_sfb; i++, idx++) { + if (cpe->ms_mask[idx] && + cpe->ch[0].band_type[idx] < NOISE_BT && cpe->ch[1].band_type[idx] < NOISE_BT) { + for (group = 0; group < ics->group_len[g]; group++) { + for (k = offsets[i]; k < offsets[i+1]; k++) { + float tmp = ch0[group*128 + k] - ch1[group*128 + k]; + ch0[group*128 + k] += ch1[group*128 + k]; + ch1[group*128 + k] = tmp; + } + } + } + } + ch0 += ics->group_len[g]*128; + ch1 += ics->group_len[g]*128; + } +} + +/** + * intensity stereo decoding; reference: 4.6.8.2.3 + * + * @param ms_present Indicates mid/side stereo presence. [0] mask is all 0s; + * [1] mask is decoded from bitstream; [2] mask is all 1s; + * [3] reserved for scalable AAC + */ +static void apply_intensity_stereo(ChannelElement * cpe, int ms_present) { + const IndividualChannelStream * ics = &cpe->ch[1].ics; + SingleChannelElement * sce1 = &cpe->ch[1]; + float *coef0 = cpe->ch[0].coeffs, *coef1 = cpe->ch[1].coeffs; + const uint16_t * offsets = ics->swb_offset; + int g, group, i, k, idx = 0; + int c; + float scale; + for (g = 0; g < ics->num_window_groups; g++) { + for (i = 0; i < ics->max_sfb;) { + if (sce1->band_type[idx] == INTENSITY_BT || sce1->band_type[idx] == INTENSITY_BT2) { + const int bt_run_end = sce1->band_type_run_end[idx]; + for (; i < bt_run_end; i++, idx++) { + c = -1 + 2 * (sce1->band_type[idx] - 14); + if (ms_present) + c *= 1 - 2 * cpe->ms_mask[idx]; + scale = c * sce1->sf[idx]; + for (group = 0; group < ics->group_len[g]; group++) + for (k = offsets[i]; k < offsets[i+1]; k++) + coef1[group*128 + k] = scale * coef0[group*128 + k]; + } + } else { + int bt_run_end = sce1->band_type_run_end[idx]; + idx += bt_run_end - i; + i = bt_run_end; + } + } + coef0 += ics->group_len[g]*128; + coef1 += ics->group_len[g]*128; + } +} + +/** + * Decode a channel_pair_element; reference: table 4.4. + * + * @param elem_id Identifies the instance of a syntax element. + * + * @return Returns error status. 0 - OK, !0 - error + */ +static int decode_cpe(AACContext * ac, GetBitContext * gb, int elem_id) { + int i, ret, common_window, ms_present = 0; + ChannelElement * cpe; + + cpe = ac->che[TYPE_CPE][elem_id]; + common_window = get_bits1(gb); + if (common_window) { + if (decode_ics_info(ac, &cpe->ch[0].ics, gb, 1)) + return -1; + i = cpe->ch[1].ics.use_kb_window[0]; + cpe->ch[1].ics = cpe->ch[0].ics; + cpe->ch[1].ics.use_kb_window[1] = i; + ms_present = get_bits(gb, 2); + if(ms_present == 3) { + av_log(ac->avccontext, AV_LOG_ERROR, "ms_present = 3 is reserved.\n"); + return -1; + } else if(ms_present) + decode_mid_side_stereo(cpe, gb, ms_present); + } + if ((ret = decode_ics(ac, &cpe->ch[0], gb, common_window, 0))) + return ret; + if ((ret = decode_ics(ac, &cpe->ch[1], gb, common_window, 0))) + return ret; + + if (common_window && ms_present) + apply_mid_side_stereo(cpe); + + apply_intensity_stereo(cpe, ms_present); + return 0; +} + +/** + * Decode coupling_channel_element; reference: table 4.8. + * + * @param elem_id Identifies the instance of a syntax element. + * + * @return Returns error status. 0 - OK, !0 - error + */ +static int decode_cce(AACContext * ac, GetBitContext * gb, ChannelElement * che) { + int num_gain = 0; + int c, g, sfb, ret, idx = 0; + int sign; + float scale; + SingleChannelElement * sce = &che->ch[0]; + ChannelCoupling * coup = &che->coup; + + coup->coupling_point = 2*get_bits1(gb); + coup->num_coupled = get_bits(gb, 3); + for (c = 0; c <= coup->num_coupled; c++) { + num_gain++; + coup->type[c] = get_bits1(gb) ? TYPE_CPE : TYPE_SCE; + coup->id_select[c] = get_bits(gb, 4); + if (coup->type[c] == TYPE_CPE) { + coup->ch_select[c] = get_bits(gb, 2); + if (coup->ch_select[c] == 3) + num_gain++; + } else + coup->ch_select[c] = 1; + } + coup->coupling_point += get_bits1(gb); + + if (coup->coupling_point == 2) { + av_log(ac->avccontext, AV_LOG_ERROR, + "Independently switched CCE with 'invalid' domain signalled.\n"); + memset(coup, 0, sizeof(ChannelCoupling)); + return -1; + } + + sign = get_bits(gb, 1); + scale = pow(2., pow(2., get_bits(gb, 2) - 3)); + + if ((ret = decode_ics(ac, sce, gb, 0, 0))) + return ret; + + for (c = 0; c < num_gain; c++) { + int cge = 1; + int gain = 0; + float gain_cache = 1.; + if (c) { + cge = coup->coupling_point == AFTER_IMDCT ? 1 : get_bits1(gb); + gain = cge ? get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60: 0; + gain_cache = pow(scale, gain); + } + for (g = 0; g < sce->ics.num_window_groups; g++) + for (sfb = 0; sfb < sce->ics.max_sfb; sfb++, idx++) + if (sce->band_type[idx] != ZERO_BT) { + if (!cge) { + int t = get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60; + if (t) { + int s = 1; + if (sign) { + s -= 2 * (t & 0x1); + t >>= 1; + } + gain += t; + gain_cache = pow(scale, gain) * s; + } [... truncated: 2142 lines follow ...] From dlmcpaul at mail.berlios.de Mon Sep 15 16:00:41 2008 From: dlmcpaul at mail.berlios.de (dlmcpaul at BerliOS) Date: Mon, 15 Sep 2008 16:00:41 +0200 Subject: [Haiku-commits] r27541 - haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec Message-ID: <200809151400.m8FE0fpE032541@sheep.berlios.de> Author: dlmcpaul Date: 2008-09-15 16:00:39 +0200 (Mon, 15 Sep 2008) New Revision: 27541 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27541&view=rev Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/ac3.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/ac3_parser.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/ac3dec.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/ac3dec_data.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/ac3tab.c Modified: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/ac3enc.c Log: Update avcodec to 20080825 Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/ac3.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/ac3.c 2008-09-15 14:00:22 UTC (rev 27540) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/ac3.c 2008-09-15 14:00:39 UTC (rev 27541) @@ -0,0 +1,241 @@ +/* + * Common code between the AC-3 encoder and decoder + * Copyright (c) 2000 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file ac3.c + * Common code between the AC-3 encoder and decoder. + */ + +#include "avcodec.h" +#include "ac3.h" +#include "bitstream.h" + +static uint8_t band_start_tab[51]; +static uint8_t bin_to_band_tab[253]; + +static inline int calc_lowcomp1(int a, int b0, int b1, int c) +{ + if ((b0 + 256) == b1) { + a = c; + } else if (b0 > b1) { + a = FFMAX(a - 64, 0); + } + return a; +} + +static inline int calc_lowcomp(int a, int b0, int b1, int bin) +{ + if (bin < 7) { + return calc_lowcomp1(a, b0, b1, 384); + } else if (bin < 20) { + return calc_lowcomp1(a, b0, b1, 320); + } else { + return FFMAX(a - 128, 0); + } +} + +void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd, + int16_t *band_psd) +{ + int bin, i, j, k, end1, v; + + /* exponent mapping to PSD */ + for(bin=start;bin> 1, 255); + v = FFMAX(v, psd[j]) + ff_ac3_log_add_tab[adr]; + j++; + } + band_psd[k]=v; + k++; + } while (end > band_start_tab[k]); +} + +void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd, + int start, int end, int fast_gain, int is_lfe, + int dba_mode, int dba_nsegs, uint8_t *dba_offsets, + uint8_t *dba_lengths, uint8_t *dba_values, + int16_t *mask) +{ + int16_t excite[50]; /* excitation */ + int bin, k; + int bndstrt, bndend, begin, end1, tmp; + int lowcomp, fastleak, slowleak; + + /* excitation function */ + bndstrt = bin_to_band_tab[start]; + bndend = bin_to_band_tab[end-1] + 1; + + if (bndstrt == 0) { + lowcomp = 0; + lowcomp = calc_lowcomp1(lowcomp, band_psd[0], band_psd[1], 384); + excite[0] = band_psd[0] - fast_gain - lowcomp; + lowcomp = calc_lowcomp1(lowcomp, band_psd[1], band_psd[2], 384); + excite[1] = band_psd[1] - fast_gain - lowcomp; + begin = 7; + for (bin = 2; bin < 7; bin++) { + if (!(is_lfe && bin == 6)) + lowcomp = calc_lowcomp1(lowcomp, band_psd[bin], band_psd[bin+1], 384); + fastleak = band_psd[bin] - fast_gain; + slowleak = band_psd[bin] - s->slow_gain; + excite[bin] = fastleak - lowcomp; + if (!(is_lfe && bin == 6)) { + if (band_psd[bin] <= band_psd[bin+1]) { + begin = bin + 1; + break; + } + } + } + + end1=bndend; + if (end1 > 22) end1=22; + + for (bin = begin; bin < end1; bin++) { + if (!(is_lfe && bin == 6)) + lowcomp = calc_lowcomp(lowcomp, band_psd[bin], band_psd[bin+1], bin); + + fastleak = FFMAX(fastleak - s->fast_decay, band_psd[bin] - fast_gain); + slowleak = FFMAX(slowleak - s->slow_decay, band_psd[bin] - s->slow_gain); + excite[bin] = FFMAX(fastleak - lowcomp, slowleak); + } + begin = 22; + } else { + /* coupling channel */ + begin = bndstrt; + + fastleak = (s->cpl_fast_leak << 8) + 768; + slowleak = (s->cpl_slow_leak << 8) + 768; + } + + for (bin = begin; bin < bndend; bin++) { + fastleak = FFMAX(fastleak - s->fast_decay, band_psd[bin] - fast_gain); + slowleak = FFMAX(slowleak - s->slow_decay, band_psd[bin] - s->slow_gain); + excite[bin] = FFMAX(fastleak, slowleak); + } + + /* compute masking curve */ + + for (bin = bndstrt; bin < bndend; bin++) { + tmp = s->db_per_bit - band_psd[bin]; + if (tmp > 0) { + excite[bin] += tmp >> 2; + } + mask[bin] = FFMAX(ff_ac3_hearing_threshold_tab[bin >> s->sr_shift][s->sr_code], excite[bin]); + } + + /* delta bit allocation */ + + if (dba_mode == DBA_REUSE || dba_mode == DBA_NEW) { + int band, seg, delta; + band = 0; + for (seg = 0; seg < FFMIN(8, dba_nsegs); seg++) { + band = FFMIN(49, band + dba_offsets[seg]); + if (dba_values[seg] >= 4) { + delta = (dba_values[seg] - 3) << 7; + } else { + delta = (dba_values[seg] - 4) << 7; + } + for (k = 0; k < dba_lengths[seg]; k++) { + mask[band] += delta; + band++; + } + } + } +} + +void ff_ac3_bit_alloc_calc_bap(int16_t *mask, int16_t *psd, int start, int end, + int snr_offset, int floor, + const uint8_t *bap_tab, uint8_t *bap) +{ + int i, j, k, end1, v, address; + + /* special case, if snr offset is -960, set all bap's to zero */ + if(snr_offset == -960) { + memset(bap, 0, 256); + return; + } + + i = start; + j = bin_to_band_tab[start]; + do { + v = (FFMAX(mask[j] - snr_offset - floor, 0) & 0x1FE0) + floor; + end1 = FFMIN(band_start_tab[j] + ff_ac3_critical_band_size_tab[j], end); + for (k = i; k < end1; k++) { + address = av_clip((psd[i] - v) >> 5, 0, 63); + bap[i] = bap_tab[address]; + i++; + } + } while (end > band_start_tab[j++]); +} + +/* AC-3 bit allocation. The algorithm is the one described in the AC-3 + spec. */ +void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap, + int8_t *exp, int start, int end, + int snr_offset, int fast_gain, int is_lfe, + int dba_mode, int dba_nsegs, + uint8_t *dba_offsets, uint8_t *dba_lengths, + uint8_t *dba_values) +{ + int16_t psd[256]; /* scaled exponents */ + int16_t band_psd[50]; /* interpolated exponents */ + int16_t mask[50]; /* masking value */ + + ff_ac3_bit_alloc_calc_psd(exp, start, end, psd, band_psd); + + ff_ac3_bit_alloc_calc_mask(s, band_psd, start, end, fast_gain, is_lfe, + dba_mode, dba_nsegs, dba_offsets, dba_lengths, dba_values, + mask); + + ff_ac3_bit_alloc_calc_bap(mask, psd, start, end, snr_offset, s->floor, + ff_ac3_bap_tab, bap); +} + +/** + * Initializes some tables. + * note: This function must remain thread safe because it is called by the + * AVParser init code. + */ +av_cold void ac3_common_init(void) +{ + int i, j, k, l, v; + /* compute bndtab and masktab from bandsz */ + k = 0; + l = 0; + for(i=0;i<50;i++) { + band_start_tab[i] = l; + v = ff_ac3_critical_band_size_tab[i]; + for(j=0;jsync_word = get_bits(gbc, 16); + if(hdr->sync_word != 0x0B77) + return AC3_PARSE_ERROR_SYNC; + + /* read ahead to bsid to distinguish between AC-3 and E-AC-3 */ + hdr->bitstream_id = show_bits_long(gbc, 29) & 0x1F; + if(hdr->bitstream_id > 16) + return AC3_PARSE_ERROR_BSID; + + hdr->num_blocks = 6; + + /* set default mix levels */ + hdr->center_mix_level = 1; // -4.5dB + hdr->surround_mix_level = 1; // -6.0dB + + if(hdr->bitstream_id <= 10) { + /* Normal AC-3 */ + hdr->crc1 = get_bits(gbc, 16); + hdr->sr_code = get_bits(gbc, 2); + if(hdr->sr_code == 3) + return AC3_PARSE_ERROR_SAMPLE_RATE; + + frame_size_code = get_bits(gbc, 6); + if(frame_size_code > 37) + return AC3_PARSE_ERROR_FRAME_SIZE; + + skip_bits(gbc, 5); // skip bsid, already got it + + skip_bits(gbc, 3); // skip bitstream mode + hdr->channel_mode = get_bits(gbc, 3); + + if(hdr->channel_mode == AC3_CHMODE_STEREO) { + skip_bits(gbc, 2); // skip dsurmod + } else { + if((hdr->channel_mode & 1) && hdr->channel_mode != AC3_CHMODE_MONO) + hdr->center_mix_level = get_bits(gbc, 2); + if(hdr->channel_mode & 4) + hdr->surround_mix_level = get_bits(gbc, 2); + } + hdr->lfe_on = get_bits1(gbc); + + hdr->sr_shift = FFMAX(hdr->bitstream_id, 8) - 8; + hdr->sample_rate = ff_ac3_sample_rate_tab[hdr->sr_code] >> hdr->sr_shift; + hdr->bit_rate = (ff_ac3_bitrate_tab[frame_size_code>>1] * 1000) >> hdr->sr_shift; + hdr->channels = ff_ac3_channels_tab[hdr->channel_mode] + hdr->lfe_on; + hdr->frame_size = ff_ac3_frame_size_tab[frame_size_code][hdr->sr_code] * 2; + hdr->frame_type = EAC3_FRAME_TYPE_AC3_CONVERT; //EAC3_FRAME_TYPE_INDEPENDENT; + hdr->substreamid = 0; + } else { + /* Enhanced AC-3 */ + hdr->crc1 = 0; + hdr->frame_type = get_bits(gbc, 2); + if(hdr->frame_type == EAC3_FRAME_TYPE_RESERVED) + return AC3_PARSE_ERROR_FRAME_TYPE; + + hdr->substreamid = get_bits(gbc, 3); + + hdr->frame_size = (get_bits(gbc, 11) + 1) << 1; + if(hdr->frame_size < AC3_HEADER_SIZE) + return AC3_PARSE_ERROR_FRAME_SIZE; + + hdr->sr_code = get_bits(gbc, 2); + if (hdr->sr_code == 3) { + int sr_code2 = get_bits(gbc, 2); + if(sr_code2 == 3) + return AC3_PARSE_ERROR_SAMPLE_RATE; + hdr->sample_rate = ff_ac3_sample_rate_tab[sr_code2] / 2; + hdr->sr_shift = 1; + } else { + hdr->num_blocks = eac3_blocks[get_bits(gbc, 2)]; + hdr->sample_rate = ff_ac3_sample_rate_tab[hdr->sr_code]; + hdr->sr_shift = 0; + } + + hdr->channel_mode = get_bits(gbc, 3); + hdr->lfe_on = get_bits1(gbc); + + hdr->bit_rate = (uint32_t)(8.0 * hdr->frame_size * hdr->sample_rate / + (hdr->num_blocks * 256.0)); + hdr->channels = ff_ac3_channels_tab[hdr->channel_mode] + hdr->lfe_on; + } + + return 0; +} + +int ff_ac3_parse_header_full(GetBitContext *gbc, AC3HeaderInfo *hdr){ + int ret, i; + ret = ff_ac3_parse_header(gbc, hdr); + if(!ret){ + if(hdr->bitstream_id>10){ + /* Enhanced AC-3 */ + skip_bits(gbc, 5); // skip bitstream id + + /* skip dialog normalization and compression gain */ + for (i = 0; i < (hdr->channel_mode ? 1 : 2); i++) { + skip_bits(gbc, 5); // skip dialog normalization + if (get_bits1(gbc)) { + skip_bits(gbc, 8); //skip Compression gain word + } + } + /* dependent stream channel map */ + if (hdr->frame_type == EAC3_FRAME_TYPE_DEPENDENT && get_bits1(gbc)) { + hdr->channel_map = get_bits(gbc, 16); //custom channel map + return 0; + } + } + //default channel map based on acmod and lfeon + hdr->channel_map = ff_eac3_default_chmap[hdr->channel_mode]; + if(hdr->lfe_on) + hdr->channel_map |= AC3_CHMAP_LFE; + } + return ret; +} + +static int ac3_sync(uint64_t state, AACAC3ParseContext *hdr_info, + int *need_next_header, int *new_frame_start) +{ + int err; + uint64_t tmp = be2me_64(state); + AC3HeaderInfo hdr; + GetBitContext gbc; + + init_get_bits(&gbc, ((uint8_t *)&tmp)+8-AC3_HEADER_SIZE, 54); + err = ff_ac3_parse_header(&gbc, &hdr); + + if(err < 0) + return 0; + + hdr_info->sample_rate = hdr.sample_rate; + hdr_info->bit_rate = hdr.bit_rate; + hdr_info->channels = hdr.channels; + hdr_info->samples = AC3_FRAME_SIZE; + + *need_next_header = (hdr.frame_type != EAC3_FRAME_TYPE_AC3_CONVERT); + *new_frame_start = (hdr.frame_type != EAC3_FRAME_TYPE_DEPENDENT); + return hdr.frame_size; +} + +static av_cold int ac3_parse_init(AVCodecParserContext *s1) +{ + AACAC3ParseContext *s = s1->priv_data; + s->header_size = AC3_HEADER_SIZE; + s->sync = ac3_sync; + return 0; +} + + +AVCodecParser ac3_parser = { + { CODEC_ID_AC3 }, + sizeof(AACAC3ParseContext), + ac3_parse_init, + ff_aac_ac3_parse, + ff_parse_close, +}; Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/ac3dec.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/ac3dec.c 2008-09-15 14:00:22 UTC (rev 27540) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/ac3dec.c 2008-09-15 14:00:39 UTC (rev 27541) @@ -0,0 +1,1268 @@ +/* + * AC-3 Audio Decoder + * This code was developed as part of Google Summer of Code 2006. + * E-AC-3 support was added as part of Google Summer of Code 2007. + * + * Copyright (c) 2006 Kartikey Mahendra BHATT (bhattkm at gmail dot com). + * Copyright (c) 2007-2008 Bartlomiej Wolowiec + * Copyright (c) 2007 Justin Ruggles + * + * Portions of this code are derived from liba52 + * http://liba52.sourceforge.net + * Copyright (C) 2000-2003 Michel Lespinasse + * Copyright (C) 1999-2000 Aaron Holtzman + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include + +#include "libavutil/crc.h" +#include "ac3_parser.h" +#include "ac3dec.h" +#include "ac3dec_data.h" + +/** Large enough for maximum possible frame size when the specification limit is ignored */ +#define AC3_FRAME_BUFFER_SIZE 32768 + +/** + * table for ungrouping 3 values in 7 bits. + * used for exponents and bap=2 mantissas + */ +static uint8_t ungroup_3_in_7_bits_tab[128][3]; + + +/** tables for ungrouping mantissas */ +static int b1_mantissas[32][3]; +static int b2_mantissas[128][3]; +static int b3_mantissas[8]; +static int b4_mantissas[128][2]; +static int b5_mantissas[16]; + +/** + * Quantization table: levels for symmetric. bits for asymmetric. + * reference: Table 7.18 Mapping of bap to Quantizer + */ +static const uint8_t quantization_tab[16] = { + 0, 3, 5, 7, 11, 15, + 5, 6, 7, 8, 9, 10, 11, 12, 14, 16 +}; + +/** dynamic range table. converts codes to scale factors. */ +static float dynamic_range_tab[256]; + +/** Adjustments in dB gain */ +#define LEVEL_PLUS_3DB 1.4142135623730950 +#define LEVEL_PLUS_1POINT5DB 1.1892071150027209 +#define LEVEL_MINUS_1POINT5DB 0.8408964152537145 +#define LEVEL_MINUS_3DB 0.7071067811865476 +#define LEVEL_MINUS_4POINT5DB 0.5946035575013605 +#define LEVEL_MINUS_6DB 0.5000000000000000 +#define LEVEL_MINUS_9DB 0.3535533905932738 +#define LEVEL_ZERO 0.0000000000000000 +#define LEVEL_ONE 1.0000000000000000 + +static const float gain_levels[9] = { + LEVEL_PLUS_3DB, + LEVEL_PLUS_1POINT5DB, + LEVEL_ONE, + LEVEL_MINUS_1POINT5DB, + LEVEL_MINUS_3DB, + LEVEL_MINUS_4POINT5DB, + LEVEL_MINUS_6DB, + LEVEL_ZERO, + LEVEL_MINUS_9DB +}; + +/** + * Table for center mix levels + * reference: Section 5.4.2.4 cmixlev + */ +static const uint8_t center_levels[4] = { 4, 5, 6, 5 }; + +/** + * Table for surround mix levels + * reference: Section 5.4.2.5 surmixlev + */ +static const uint8_t surround_levels[4] = { 4, 6, 7, 6 }; + +/** + * Table for default stereo downmixing coefficients + * reference: Section 7.8.2 Downmixing Into Two Channels + */ +static const uint8_t ac3_default_coeffs[8][5][2] = { + { { 2, 7 }, { 7, 2 }, }, + { { 4, 4 }, }, + { { 2, 7 }, { 7, 2 }, }, + { { 2, 7 }, { 5, 5 }, { 7, 2 }, }, + { { 2, 7 }, { 7, 2 }, { 6, 6 }, }, + { { 2, 7 }, { 5, 5 }, { 7, 2 }, { 8, 8 }, }, + { { 2, 7 }, { 7, 2 }, { 6, 7 }, { 7, 6 }, }, + { { 2, 7 }, { 5, 5 }, { 7, 2 }, { 6, 7 }, { 7, 6 }, }, +}; + +/** + * Symmetrical Dequantization + * reference: Section 7.3.3 Expansion of Mantissas for Symmetrical Quantization + * Tables 7.19 to 7.23 + */ +static inline int +symmetric_dequant(int code, int levels) +{ + return ((code - (levels >> 1)) << 24) / levels; +} + +/* + * Initialize tables at runtime. + */ +static av_cold void ac3_tables_init(void) +{ + int i; + + /* generate table for ungrouping 3 values in 7 bits + reference: Section 7.1.3 Exponent Decoding */ + for(i=0; i<128; i++) { + ungroup_3_in_7_bits_tab[i][0] = i / 25; + ungroup_3_in_7_bits_tab[i][1] = (i % 25) / 5; + ungroup_3_in_7_bits_tab[i][2] = (i % 25) % 5; + } + + /* generate grouped mantissa tables + reference: Section 7.3.5 Ungrouping of Mantissas */ + for(i=0; i<32; i++) { + /* bap=1 mantissas */ + b1_mantissas[i][0] = symmetric_dequant(ff_ac3_ungroup_3_in_5_bits_tab[i][0], 3); + b1_mantissas[i][1] = symmetric_dequant(ff_ac3_ungroup_3_in_5_bits_tab[i][1], 3); + b1_mantissas[i][2] = symmetric_dequant(ff_ac3_ungroup_3_in_5_bits_tab[i][2], 3); + } + for(i=0; i<128; i++) { + /* bap=2 mantissas */ + b2_mantissas[i][0] = symmetric_dequant(ungroup_3_in_7_bits_tab[i][0], 5); + b2_mantissas[i][1] = symmetric_dequant(ungroup_3_in_7_bits_tab[i][1], 5); + b2_mantissas[i][2] = symmetric_dequant(ungroup_3_in_7_bits_tab[i][2], 5); + + /* bap=4 mantissas */ + b4_mantissas[i][0] = symmetric_dequant(i / 11, 11); + b4_mantissas[i][1] = symmetric_dequant(i % 11, 11); + } + /* generate ungrouped mantissa tables + reference: Tables 7.21 and 7.23 */ + for(i=0; i<7; i++) { + /* bap=3 mantissas */ + b3_mantissas[i] = symmetric_dequant(i, 7); + } + for(i=0; i<15; i++) { + /* bap=5 mantissas */ + b5_mantissas[i] = symmetric_dequant(i, 15); + } + + /* generate dynamic range table + reference: Section 7.7.1 Dynamic Range Control */ + for(i=0; i<256; i++) { + int v = (i >> 5) - ((i >> 7) << 3) - 5; + dynamic_range_tab[i] = powf(2.0f, v) * ((i & 0x1F) | 0x20); + } +} + + +/** + * AVCodec initialization + */ +static av_cold int ac3_decode_init(AVCodecContext *avctx) +{ + AC3DecodeContext *s = avctx->priv_data; + s->avctx = avctx; + + ac3_common_init(); + ac3_tables_init(); + ff_mdct_init(&s->imdct_256, 8, 1); + ff_mdct_init(&s->imdct_512, 9, 1); + ff_kbd_window_init(s->window, 5.0, 256); + dsputil_init(&s->dsp, avctx); + av_lfg_init(&s->dith_state, 0); + + /* set bias values for float to int16 conversion */ + if(s->dsp.float_to_int16_interleave == ff_float_to_int16_interleave_c) { + s->add_bias = 385.0f; + s->mul_bias = 1.0f; + } else { + s->add_bias = 0.0f; + s->mul_bias = 32767.0f; + } + + /* allow downmixing to stereo or mono */ + if (avctx->channels > 0 && avctx->request_channels > 0 && + avctx->request_channels < avctx->channels && + avctx->request_channels <= 2) { + avctx->channels = avctx->request_channels; + } + s->downmixed = 1; + + /* allocate context input buffer */ + if (avctx->error_resilience >= FF_ER_CAREFUL) { + s->input_buffer = av_mallocz(AC3_FRAME_BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE); + if (!s->input_buffer) + return AVERROR_NOMEM; + } + + avctx->sample_fmt = SAMPLE_FMT_S16; + return 0; +} + +/** + * Parse the 'sync info' and 'bit stream info' from the AC-3 bitstream. + * GetBitContext within AC3DecodeContext must point to + * the start of the synchronized AC-3 bitstream. + */ +static int ac3_parse_header(AC3DecodeContext *s) +{ + GetBitContext *gbc = &s->gbc; + int i; + + /* read the rest of the bsi. read twice for dual mono mode. */ + i = !(s->channel_mode); + do { + skip_bits(gbc, 5); // skip dialog normalization + if (get_bits1(gbc)) + skip_bits(gbc, 8); //skip compression + if (get_bits1(gbc)) + skip_bits(gbc, 8); //skip language code + if (get_bits1(gbc)) + skip_bits(gbc, 7); //skip audio production information + } while (i--); + + skip_bits(gbc, 2); //skip copyright bit and original bitstream bit + + /* skip the timecodes (or extra bitstream information for Alternate Syntax) + TODO: read & use the xbsi1 downmix levels */ + if (get_bits1(gbc)) + skip_bits(gbc, 14); //skip timecode1 / xbsi1 + if (get_bits1(gbc)) + skip_bits(gbc, 14); //skip timecode2 / xbsi2 + + /* skip additional bitstream info */ + if (get_bits1(gbc)) { + i = get_bits(gbc, 6); + do { + skip_bits(gbc, 8); + } while(i--); + } + + return 0; +} + +/** + * Common function to parse AC-3 or E-AC-3 frame header + */ +static int parse_frame_header(AC3DecodeContext *s) +{ + AC3HeaderInfo hdr; + int err; + + err = ff_ac3_parse_header(&s->gbc, &hdr); + if(err) + return err; + + /* get decoding parameters from header info */ + s->bit_alloc_params.sr_code = hdr.sr_code; + s->channel_mode = hdr.channel_mode; + s->lfe_on = hdr.lfe_on; + s->bit_alloc_params.sr_shift = hdr.sr_shift; + s->sample_rate = hdr.sample_rate; + s->bit_rate = hdr.bit_rate; + s->channels = hdr.channels; + s->fbw_channels = s->channels - s->lfe_on; + s->lfe_ch = s->fbw_channels + 1; + s->frame_size = hdr.frame_size; + s->center_mix_level = hdr.center_mix_level; + s->surround_mix_level = hdr.surround_mix_level; + s->num_blocks = hdr.num_blocks; + s->frame_type = hdr.frame_type; + s->substreamid = hdr.substreamid; + + if(s->lfe_on) { + s->start_freq[s->lfe_ch] = 0; + s->end_freq[s->lfe_ch] = 7; + s->num_exp_groups[s->lfe_ch] = 2; + s->channel_in_cpl[s->lfe_ch] = 0; + } + + if (hdr.bitstream_id <= 10) { + s->eac3 = 0; + s->snr_offset_strategy = 2; + s->block_switch_syntax = 1; + s->dither_flag_syntax = 1; + s->bit_allocation_syntax = 1; + s->fast_gain_syntax = 0; + s->first_cpl_leak = 0; + s->dba_syntax = 1; + s->skip_syntax = 1; + memset(s->channel_uses_aht, 0, sizeof(s->channel_uses_aht)); + return ac3_parse_header(s); + } else { + /*s->eac3 = 1; + return ff_eac3_parse_header(s);*/ + return AC3_PARSE_ERROR_BSID; + } +} + +/** + * Set stereo downmixing coefficients based on frame header info. + * reference: Section 7.8.2 Downmixing Into Two Channels + */ +static void set_downmix_coeffs(AC3DecodeContext *s) +{ + int i; + float cmix = gain_levels[center_levels[s->center_mix_level]]; + float smix = gain_levels[surround_levels[s->surround_mix_level]]; + float norm0, norm1; + + for(i=0; ifbw_channels; i++) { + s->downmix_coeffs[i][0] = gain_levels[ac3_default_coeffs[s->channel_mode][i][0]]; + s->downmix_coeffs[i][1] = gain_levels[ac3_default_coeffs[s->channel_mode][i][1]]; + } + if(s->channel_mode > 1 && s->channel_mode & 1) { + s->downmix_coeffs[1][0] = s->downmix_coeffs[1][1] = cmix; + } + if(s->channel_mode == AC3_CHMODE_2F1R || s->channel_mode == AC3_CHMODE_3F1R) { + int nf = s->channel_mode - 2; + s->downmix_coeffs[nf][0] = s->downmix_coeffs[nf][1] = smix * LEVEL_MINUS_3DB; + } + if(s->channel_mode == AC3_CHMODE_2F2R || s->channel_mode == AC3_CHMODE_3F2R) { + int nf = s->channel_mode - 4; + s->downmix_coeffs[nf][0] = s->downmix_coeffs[nf+1][1] = smix; + } + + /* renormalize */ + norm0 = norm1 = 0.0; + for(i=0; ifbw_channels; i++) { + norm0 += s->downmix_coeffs[i][0]; + norm1 += s->downmix_coeffs[i][1]; + } + norm0 = 1.0f / norm0; + norm1 = 1.0f / norm1; + for(i=0; ifbw_channels; i++) { + s->downmix_coeffs[i][0] *= norm0; + s->downmix_coeffs[i][1] *= norm1; + } + + if(s->output_mode == AC3_CHMODE_MONO) { + for(i=0; ifbw_channels; i++) + s->downmix_coeffs[i][0] = (s->downmix_coeffs[i][0] + s->downmix_coeffs[i][1]) * LEVEL_MINUS_3DB; + } +} + +/** + * Decode the grouped exponents according to exponent strategy. + * reference: Section 7.1.3 Exponent Decoding + */ +static void decode_exponents(GetBitContext *gbc, int exp_strategy, int ngrps, + uint8_t absexp, int8_t *dexps) +{ + int i, j, grp, group_size; + int dexp[256]; + int expacc, prevexp; + + /* unpack groups */ + group_size = exp_strategy + (exp_strategy == EXP_D45); + for(grp=0,i=0; grpstart_freq[CPL_CH]; + for(bnd=0; bndnum_cpl_bands; bnd++) { + do { + subbnd++; + for(j=0; j<12; j++) { + for(ch=1; ch<=s->fbw_channels; ch++) { + if(s->channel_in_cpl[ch]) { + s->fixed_coeffs[ch][i] = ((int64_t)s->fixed_coeffs[CPL_CH][i] * (int64_t)s->cpl_coords[ch][bnd]) >> 23; + if (ch == 2 && s->phase_flags[bnd]) + s->fixed_coeffs[ch][i] = -s->fixed_coeffs[ch][i]; + } + } + i++; + } + } while(s->cpl_band_struct[subbnd]); + } +} + +/** + * Grouped mantissas for 3-level 5-level and 11-level quantization + */ +typedef struct { + int b1_mant[3]; + int b2_mant[3]; + int b4_mant[2]; + int b1ptr; + int b2ptr; + int b4ptr; +} mant_groups; + +/** + * Get the transform coefficients for a particular channel + * reference: Section 7.3 Quantization and Decoding of Mantissas + */ +static void get_transform_coeffs_ch(AC3DecodeContext *s, int ch_index, mant_groups *m) +{ + GetBitContext *gbc = &s->gbc; + int i, gcode, tbap, start, end; + uint8_t *exps; + uint8_t *bap; + int *coeffs; + + exps = s->dexps[ch_index]; + bap = s->bap[ch_index]; + coeffs = s->fixed_coeffs[ch_index]; + start = s->start_freq[ch_index]; + end = s->end_freq[ch_index]; + + for (i = start; i < end; i++) { + tbap = bap[i]; + switch (tbap) { + case 0: + coeffs[i] = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000; + break; + + case 1: + if(m->b1ptr > 2) { + gcode = get_bits(gbc, 5); + m->b1_mant[0] = b1_mantissas[gcode][0]; + m->b1_mant[1] = b1_mantissas[gcode][1]; + m->b1_mant[2] = b1_mantissas[gcode][2]; + m->b1ptr = 0; + } + coeffs[i] = m->b1_mant[m->b1ptr++]; + break; + + case 2: + if(m->b2ptr > 2) { + gcode = get_bits(gbc, 7); + m->b2_mant[0] = b2_mantissas[gcode][0]; + m->b2_mant[1] = b2_mantissas[gcode][1]; + m->b2_mant[2] = b2_mantissas[gcode][2]; + m->b2ptr = 0; + } + coeffs[i] = m->b2_mant[m->b2ptr++]; + break; + + case 3: + coeffs[i] = b3_mantissas[get_bits(gbc, 3)]; + break; + + case 4: + if(m->b4ptr > 1) { + gcode = get_bits(gbc, 7); + m->b4_mant[0] = b4_mantissas[gcode][0]; + m->b4_mant[1] = b4_mantissas[gcode][1]; + m->b4ptr = 0; + } + coeffs[i] = m->b4_mant[m->b4ptr++]; + break; + + case 5: + coeffs[i] = b5_mantissas[get_bits(gbc, 4)]; + break; + + default: { + /* asymmetric dequantization */ + int qlevel = quantization_tab[tbap]; + coeffs[i] = get_sbits(gbc, qlevel) << (24 - qlevel); + break; + } + } + coeffs[i] >>= exps[i]; + } +} + +/** + * Remove random dithering from coefficients with zero-bit mantissas + * reference: Section 7.3.4 Dither for Zero Bit Mantissas (bap=0) + */ +static void remove_dithering(AC3DecodeContext *s) { + int ch, i; + int end=0; + int *coeffs; + uint8_t *bap; + + for(ch=1; ch<=s->fbw_channels; ch++) { + if(!s->dither_flag[ch]) { + coeffs = s->fixed_coeffs[ch]; + bap = s->bap[ch]; + if(s->channel_in_cpl[ch]) + end = s->start_freq[CPL_CH]; + else + end = s->end_freq[ch]; + for(i=0; ichannel_in_cpl[ch]) { + bap = s->bap[CPL_CH]; + for(; iend_freq[CPL_CH]; i++) { + if(!bap[i]) + coeffs[i] = 0; + } + } [... truncated: 3482 lines follow ...] From dlmcpaul at mail.berlios.de Mon Sep 15 16:01:02 2008 From: dlmcpaul at mail.berlios.de (dlmcpaul at BerliOS) Date: Mon, 15 Sep 2008 16:01:02 +0200 Subject: [Haiku-commits] r27542 - haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec Message-ID: <200809151401.m8FE12kb032608@sheep.berlios.de> Author: dlmcpaul Date: 2008-09-15 16:00:59 +0200 (Mon, 15 Sep 2008) New Revision: 27542 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27542&view=rev Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aasc.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/acelp_filters.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/acelp_math.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/acelp_pitch_delay.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/acelp_vectors.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/adxdec.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/adxenc.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/alac.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/alacenc.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/apedec.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/apiexample.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/atrac3.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/audioconvert.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/avs.c Modified: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/adpcm.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/allcodecs.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/asv1.c Log: Update avcodec to 20080825 Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aasc.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aasc.c 2008-09-15 14:00:39 UTC (rev 27541) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/aasc.c 2008-09-15 14:00:59 UTC (rev 27542) @@ -0,0 +1,175 @@ +/* + * Autodesk RLE Decoder + * Copyright (C) 2005 the ffmpeg project + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file aasc.c + * Autodesk RLE Video Decoder by Konstantin Shishkov + */ + +#include +#include +#include + +#include "avcodec.h" +#include "dsputil.h" + +typedef struct AascContext { + AVCodecContext *avctx; + AVFrame frame; +} AascContext; + +#define FETCH_NEXT_STREAM_BYTE() \ + if (stream_ptr >= buf_size) \ + { \ + av_log(s->avctx, AV_LOG_ERROR, " AASC: stream ptr just went out of bounds (fetch)\n"); \ + break; \ + } \ + stream_byte = buf[stream_ptr++]; + +static av_cold int aasc_decode_init(AVCodecContext *avctx) +{ + AascContext *s = avctx->priv_data; + + s->avctx = avctx; + + avctx->pix_fmt = PIX_FMT_BGR24; + s->frame.data[0] = NULL; + + return 0; +} + +static int aasc_decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + const uint8_t *buf, int buf_size) +{ + AascContext *s = avctx->priv_data; + int stream_ptr = 4; + unsigned char rle_code; + unsigned char stream_byte; + int pixel_ptr = 0; + int row_dec, row_ptr; + int frame_size; + int i; + + s->frame.reference = 1; + s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; + if (avctx->reget_buffer(avctx, &s->frame)) { + av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); + return -1; + } + + row_dec = s->frame.linesize[0]; + row_ptr = (s->avctx->height - 1) * row_dec; + frame_size = row_dec * s->avctx->height; + + while (row_ptr >= 0) { + FETCH_NEXT_STREAM_BYTE(); + rle_code = stream_byte; + if (rle_code == 0) { + /* fetch the next byte to see how to handle escape code */ + FETCH_NEXT_STREAM_BYTE(); + if (stream_byte == 0) { + /* line is done, goto the next one */ + row_ptr -= row_dec; + pixel_ptr = 0; + } else if (stream_byte == 1) { + /* decode is done */ + break; + } else if (stream_byte == 2) { + /* reposition frame decode coordinates */ + FETCH_NEXT_STREAM_BYTE(); + pixel_ptr += stream_byte; + FETCH_NEXT_STREAM_BYTE(); + row_ptr -= stream_byte * row_dec; + } else { + /* copy pixels from encoded stream */ + if ((pixel_ptr + stream_byte > avctx->width * 3) || + (row_ptr < 0)) { + av_log(s->avctx, AV_LOG_ERROR, " AASC: frame ptr just went out of bounds (copy1)\n"); + break; + } + + rle_code = stream_byte; + if (stream_ptr + rle_code > buf_size) { + av_log(s->avctx, AV_LOG_ERROR, " AASC: stream ptr just went out of bounds (copy2)\n"); + break; + } + + for (i = 0; i < rle_code; i++) { + FETCH_NEXT_STREAM_BYTE(); + s->frame.data[0][row_ptr + pixel_ptr] = stream_byte; + pixel_ptr++; + } + if (rle_code & 1) + stream_ptr++; + } + } else { + /* decode a run of data */ + if ((pixel_ptr + rle_code > avctx->width * 3) || + (row_ptr < 0)) { + av_log(s->avctx, AV_LOG_ERROR, " AASC: frame ptr just went out of bounds (run1)\n"); + break; + } + + FETCH_NEXT_STREAM_BYTE(); + + while(rle_code--) { + s->frame.data[0][row_ptr + pixel_ptr] = stream_byte; + pixel_ptr++; + } + } + } + + /* one last sanity check on the way out */ + if (stream_ptr < buf_size) + av_log(s->avctx, AV_LOG_ERROR, " AASC: ended frame decode with bytes left over (%d < %d)\n", + stream_ptr, buf_size); + + *data_size = sizeof(AVFrame); + *(AVFrame*)data = s->frame; + + /* report that the buffer was completely consumed */ + return buf_size; +} + +static av_cold int aasc_decode_end(AVCodecContext *avctx) +{ + AascContext *s = avctx->priv_data; + + /* release the last frame */ + if (s->frame.data[0]) + avctx->release_buffer(avctx, &s->frame); + + return 0; +} + +AVCodec aasc_decoder = { + "aasc", + CODEC_TYPE_VIDEO, + CODEC_ID_AASC, + sizeof(AascContext), + aasc_decode_init, + NULL, + aasc_decode_end, + aasc_decode_frame, + CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Autodesk RLE"), +}; Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/acelp_filters.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/acelp_filters.c 2008-09-15 14:00:39 UTC (rev 27541) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/acelp_filters.c 2008-09-15 14:00:59 UTC (rev 27542) @@ -0,0 +1,162 @@ +/* + * various filters for ACELP-based codecs + * + * Copyright (c) 2008 Vladimir Voroshilov + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include "avcodec.h" +#include "acelp_filters.h" + +const int16_t ff_acelp_interp_filter[61] = +{ /* (0.15) */ + 29443, 28346, 25207, 20449, 14701, 8693, + 3143, -1352, -4402, -5865, -5850, -4673, + -2783, -672, 1211, 2536, 3130, 2991, + 2259, 1170, 0, -1001, -1652, -1868, + -1666, -1147, -464, 218, 756, 1060, + 1099, 904, 550, 135, -245, -514, + -634, -602, -451, -231, 0, 191, + 308, 340, 296, 198, 78, -36, + -120, -163, -165, -132, -79, -19, + 34, 73, 91, 89, 70, 38, + 0, +}; + +void ff_acelp_interpolate( + int16_t* out, + const int16_t* in, + const int16_t* filter_coeffs, + int precision, + int frac_pos, + int filter_length, + int length) +{ + int n, i; + + assert(pitch_delay_frac >= 0 && pitch_delay_frac < precision); + + for(n=0; n> 15); + } +} + +void ff_acelp_convolve_circ( + int16_t* fc_out, + const int16_t* fc_in, + const int16_t* filter, + int len) +{ + int i, k; + + memset(fc_out, 0, len * sizeof(int16_t)); + + /* Since there are few pulses over an entire subframe (i.e. almost + all fc_in[i] are zero) it is faster to loop over fc_in first. */ + for(i=0; i> 15; + + for(k=i; k> 15; + } + } +} + +int ff_acelp_lp_synthesis_filter( + int16_t *out, + const int16_t* filter_coeffs, + const int16_t* in, + int buffer_length, + int filter_length, + int stop_on_overflow, + int rounder) +{ + int i,n; + + // These two lines are to avoid a -1 subtraction in the main loop + filter_length++; + filter_coeffs--; + + for(n=0; n> 12) + in[n]; + + if(sum + 0x8000 > 0xFFFFU) + { + if(stop_on_overflow) + return 1; + sum = (sum >> 31) ^ 32767; + } + out[n] = sum; + } + + return 0; +} + +void ff_acelp_high_pass_filter( + int16_t* out, + int hpf_f[2], + const int16_t* in, + int length) +{ + int i; + int tmp; + + for(i=0; i>13; /* (14.13) = (13.13) * (1.13) */ + tmp += (hpf_f[1]* -7667LL)>>13; /* (13.13) = (13.13) * (0.13) */ + tmp += 7699 * (in[i] - 2*in[i-1] + in[i-2]); /* (14.13) = (0.13) * (14.0) */ + + out[i] = av_clip_int16((tmp + 0x800) >> 12); /* (15.0) = 2 * (13.13) = (14.13) */ + + hpf_f[1] = hpf_f[0]; + hpf_f[0] = tmp; + } +} Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/acelp_math.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/acelp_math.c 2008-09-15 14:00:39 UTC (rev 27541) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/acelp_math.c 2008-09-15 14:00:59 UTC (rev 27542) @@ -0,0 +1,197 @@ +/* + * Various fixed-point math operations + * + * Copyright (c) 2008 Vladimir Voroshilov + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include + +#include "avcodec.h" +#include "acelp_math.h" + +#ifdef G729_BITEXACT +/** + * Cosine table: base_cos[i] = (1<<15) * cos(i*PI/64) + */ +static const int16_t base_cos[64] = +{ + 32767, 32729, 32610, 32413, 32138, 31786, 31357, 30853, + 30274, 29622, 28899, 28106, 27246, 26320, 25330, 24279, + 23170, 22006, 20788, 19520, 18205, 16846, 15447, 14010, + 12540, 11039, 9512, 7962, 6393, 4808, 3212, 1608, + 0, -1608, -3212, -4808, -6393, -7962, -9512, -11039, + -12540, -14010, -15447, -16846, -18205, -19520, -20788, -22006, + -23170, -24279, -25330, -26320, -27246, -28106, -28899, -29622, + -30274, -30853, -31357, -31786, -32138, -32413, -32610, -32729 +}; + +/** + * Slope used to compute cos(x) + * + * cos(ind*64+offset) = base_cos[ind]+offset*slope_cos[ind] + * values multiplied by 1<<19 + */ +static const int16_t slope_cos[64] = +{ + -632, -1893, -3150, -4399, -5638, -6863, -8072, -9261, + -10428, -11570, -12684, -13767, -14817, -15832, -16808, -17744, + -18637, -19486, -20287, -21039, -21741, -22390, -22986, -23526, + -24009, -24435, -24801, -25108, -25354, -25540, -25664, -25726, + -25726, -25664, -25540, -25354, -25108, -24801, -24435, -24009, + -23526, -22986, -22390, -21741, -21039, -20287, -19486, -18637, + -17744, -16808, -15832, -14817, -13767, -12684, -11570, -10428, + -9261, -8072, -6863, -5638, -4399, -3150, -1893, -632 +}; + +/** + * Table used to compute exp2(x) + * + * tab_exp2[i] = (1<<14) * exp2(i/32) = 2^(i/32) i=0..32 + */ +static const uint16_t tab_exp2[33] = +{ + 16384, 16743, 17109, 17484, 17867, 18258, 18658, 19066, 19484, 19911, + 20347, 20792, 21247, 21713, 22188, 22674, 23170, 23678, 24196, 24726, + 25268, 25821, 26386, 26964, 27554, 28158, 28774, 29405, 30048, 30706, + 31379, 32066, 32767 +}; + +int16_t ff_cos(uint16_t arg) +{ + uint8_t offset= arg; + uint8_t ind = arg >> 8; + + assert(arg < 0x4000); + + return FFMAX(base_cos[ind] + ((slope_cos[ind] * offset) >> 12), -0x8000); +} + +int ff_exp2(uint16_t power) +{ + uint16_t frac_x0; + uint16_t frac_dx; + int result; + + assert(power <= 0x7fff); + + frac_x0 = power >> 10; + frac_dx = (power & 0x03ff) << 5; + + result = tab_exp2[frac_x0] << 15; + result += frac_dx * (tab_exp2[frac_x0+1] - tab_exp2[frac_x0]); + + return result >> 10; +} + +#else // G729_BITEXACT + +/** + * Cosine table: base_cos[i] = (1<<15) * cos(i*PI/64) + */ +static const int16_t tab_cos[65] = +{ + 32767, 32738, 32617, 32421, 32145, 31793, 31364, 30860, + 30280, 29629, 28905, 28113, 27252, 26326, 25336, 24285, + 23176, 22011, 20793, 19525, 18210, 16851, 15451, 14014, + 12543, 11043, 9515, 7965, 6395, 4810, 3214, 1609, + 1, -1607, -3211, -4808, -6393, -7962, -9513, -11040, + -12541, -14012, -15449, -16848, -18207, -19523, -20791, -22009, + -23174, -24283, -25334, -26324, -27250, -28111, -28904, -29627, + -30279, -30858, -31363, -31792, -32144, -32419, -32616, -32736, -32768, +}; + +static const uint16_t exp2a[]= +{ + 0, 1435, 2901, 4400, 5931, 7496, 9096, 10730, + 12400, 14106, 15850, 17632, 19454, 21315, 23216, 25160, + 27146, 29175, 31249, 33368, 35534, 37747, 40009, 42320, + 44682, 47095, 49562, 52082, 54657, 57289, 59979, 62727, +}; + +static const uint16_t exp2b[]= +{ + 3, 712, 1424, 2134, 2845, 3557, 4270, 4982, + 5696, 6409, 7124, 7839, 8554, 9270, 9986, 10704, + 11421, 12138, 12857, 13576, 14295, 15014, 15734, 16455, + 17176, 17898, 18620, 19343, 20066, 20790, 21514, 22238, +}; + +int16_t ff_cos(uint16_t arg) +{ + uint8_t offset= arg; + uint8_t ind = arg >> 8; + + assert(arg <= 0x3fff); + + return tab_cos[ind] + (offset * (tab_cos[ind+1] - tab_cos[ind]) >> 8); +} + +int ff_exp2(uint16_t power) +{ + unsigned int result= exp2a[power>>10] + 0x10000; + + assert(arg <= 0x7fff); + + result= (result<<3) + ((result*exp2b[(power>>5)&31])>>17); + return result + ((result*(power&31)*89)>>22); +} + +#endif // else G729_BITEXACT + +/** + * Table used to compute log2(x) + * + * tab_log2[i] = (1<<15) * log2(1 + i/32), i=0..32 + */ +static const uint16_t tab_log2[33] = +{ +#ifdef G729_BITEXACT + 0, 1455, 2866, 4236, 5568, 6863, 8124, 9352, + 10549, 11716, 12855, 13967, 15054, 16117, 17156, 18172, + 19167, 20142, 21097, 22033, 22951, 23852, 24735, 25603, + 26455, 27291, 28113, 28922, 29716, 30497, 31266, 32023, 32767, +#else + 4, 1459, 2870, 4240, 5572, 6867, 8127, 9355, + 10552, 11719, 12858, 13971, 15057, 16120, 17158, 18175, + 19170, 20145, 21100, 22036, 22954, 23854, 24738, 25605, + 26457, 27294, 28116, 28924, 29719, 30500, 31269, 32025, 32769, +#endif +}; + +int ff_log2(uint32_t value) +{ + uint8_t power_int; + uint8_t frac_x0; + uint16_t frac_dx; + + // Stripping zeros from beginning + power_int = av_log2(value); + value <<= (31 - power_int); + + // b31 is always non-zero now + frac_x0 = (value & 0x7c000000) >> 26; // b26-b31 and [32..63] -> [0..31] + frac_dx = (value & 0x03fff800) >> 11; + + value = tab_log2[frac_x0]; + value += (frac_dx * (tab_log2[frac_x0+1] - tab_log2[frac_x0])) >> 15; + + return (power_int << 15) + value; +} Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/acelp_pitch_delay.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/acelp_pitch_delay.c 2008-09-15 14:00:39 UTC (rev 27541) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/acelp_pitch_delay.c 2008-09-15 14:00:59 UTC (rev 27542) @@ -0,0 +1,119 @@ +/* + * gain code, gain pitch and pitch delay decoding + * + * Copyright (c) 2008 Vladimir Voroshilov + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avcodec.h" +#include "acelp_pitch_delay.h" +#include "acelp_math.h" + +int ff_acelp_decode_8bit_to_1st_delay3(int ac_index) +{ + ac_index += 58; + if(ac_index > 254) + ac_index = 3 * ac_index - 510; + return ac_index; +} + +int ff_acelp_decode_4bit_to_2nd_delay3( + int ac_index, + int pitch_delay_min) +{ + if(ac_index < 4) + return 3 * (ac_index + pitch_delay_min); + else if(ac_index < 12) + return 3 * pitch_delay_min + ac_index + 6; + else + return 3 * (ac_index + pitch_delay_min) - 18; +} + +int ff_acelp_decode_5_6_bit_to_2nd_delay3( + int ac_index, + int pitch_delay_min) +{ + return 3 * pitch_delay_min + ac_index - 2; +} + +int ff_acelp_decode_9bit_to_1st_delay6(int ac_index) +{ + if(ac_index < 463) + return ac_index + 105; + else + return 6 * (ac_index - 368); +} +int ff_acelp_decode_6bit_to_2nd_delay6( + int ac_index, + int pitch_delay_min) +{ + return 6 * pitch_delay_min + ac_index - 3; +} + +void ff_acelp_update_past_gain( + int16_t* quant_energy, + int gain_corr_factor, + int log2_ma_pred_order, + int erasure) +{ + int i; + int avg_gain=quant_energy[(1 << log2_ma_pred_order) - 1]; // (5.10) + + for(i=(1 << log2_ma_pred_order) - 1; i>0; i--) + { + avg_gain += quant_energy[i-1]; + quant_energy[i] = quant_energy[i-1]; + } + + if(erasure) + quant_energy[0] = FFMAX(avg_gain >> log2_ma_pred_order, -10240) - 4096; // -10 and -4 in (5.10) + else + quant_energy[0] = (6165 * ((ff_log2(gain_corr_factor) >> 2) - (13 << 13))) >> 13; +} + +int16_t ff_acelp_decode_gain_code( + int gain_corr_factor, + const int16_t* fc_v, + int mr_energy, + const int16_t* quant_energy, + const int16_t* ma_prediction_coeff, + int subframe_size, + int ma_pred_order) +{ + int i; + + mr_energy <<= 10; + + for(i=0; i> 3) & ~0x3ff); + + mr_energy = (5439 * (mr_energy >> 15)) >> 8; // (0.15) = (0.15) * (7.23) + + return bidir_sal( + ((ff_exp2(mr_energy & 0x7fff) + 16) >> 5) * (gain_corr_factor >> 1), + (mr_energy >> 15) - 25 + ); +#else + mr_energy = gain_corr_factor * exp(M_LN10 / (20 << 23) * mr_energy) / + sqrt(dot_product(fc_v, fc_v, subframe_size, 0)); + return mr_energy >> 12; +#endif +} Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/acelp_vectors.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/acelp_vectors.c 2008-09-15 14:00:39 UTC (rev 27541) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/acelp_vectors.c 2008-09-15 14:00:59 UTC (rev 27542) @@ -0,0 +1,147 @@ +/* + * adaptive and fixed codebook vector operations for ACELP-based codecs + * + * Copyright (c) 2008 Vladimir Voroshilov + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include "avcodec.h" +#include "acelp_vectors.h" + +const uint8_t ff_fc_2pulses_9bits_track1[16] = +{ + 1, 3, + 6, 8, + 11, 13, + 16, 18, + 21, 23, + 26, 28, + 31, 33, + 36, 38 +}; +const uint8_t ff_fc_2pulses_9bits_track1_gray[16] = +{ + 1, 3, + 8, 6, + 18, 16, + 11, 13, + 38, 36, + 31, 33, + 21, 23, + 28, 26, +}; + +const uint8_t ff_fc_2pulses_9bits_track2_gray[32] = +{ + 0, 2, + 5, 4, + 12, 10, + 7, 9, + 25, 24, + 20, 22, + 14, 15, + 19, 17, + 36, 31, + 21, 26, + 1, 6, + 16, 11, + 27, 29, + 32, 30, + 39, 37, + 34, 35, +}; + +const uint8_t ff_fc_4pulses_8bits_tracks_13[16] = +{ + 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, +}; + +const uint8_t ff_fc_4pulses_8bits_track_4[32] = +{ + 3, 4, + 8, 9, + 13, 14, + 18, 19, + 23, 24, + 28, 29, + 33, 34, + 38, 39, + 43, 44, + 48, 49, + 53, 54, + 58, 59, + 63, 64, + 68, 69, + 73, 74, + 78, 79, +}; + +#if 0 +static uint8_t gray_decode[32] = +{ + 0, 1, 3, 2, 7, 6, 4, 5, + 15, 14, 12, 13, 8, 9, 11, 10, + 31, 30, 28, 29, 24, 25, 27, 26, + 16, 17, 19, 18, 23, 22, 20, 21 +}; +#endif + +void ff_acelp_fc_pulse_per_track( + int16_t* fc_v, + const uint8_t *tab1, + const uint8_t *tab2, + int pulse_indexes, + int pulse_signs, + int pulse_count, + int bits) +{ + int mask = (1 << bits) - 1; + int i; + + for(i=0; i>= bits; + pulse_signs >>= 1; + } + + fc_v[tab2[pulse_indexes]] += (pulse_signs & 1) ? 8191 : -8192; +} + +void ff_acelp_weighted_vector_sum( + int16_t* out, + const int16_t *in_a, + const int16_t *in_b, + int16_t weight_coeff_a, + int16_t weight_coeff_b, + int16_t rounder, + int shift, + int length) +{ + int i; + + // Clipping required here; breaks OVERFLOW test. + for(i=0; i> shift); +} Modified: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/adpcm.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/adpcm.c 2008-09-15 14:00:39 UTC (rev 27541) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/adpcm.c 2008-09-15 14:00:59 UTC (rev 27542) @@ -2,21 +2,25 @@ * ADPCM codecs * Copyright (c) 2001-2003 The ffmpeg Project * - * This library is free software; you can redistribute it and/or + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. + * version 2.1 of the License, or (at your option) any later version. * - * This library is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "avcodec.h" +#include "bitstream.h" +#include "bytestream.h" /** * @file adpcm.c @@ -25,6 +29,13 @@ * Fringe ADPCM codecs (e.g., DK3, DK4, Westwood) * by Mike Melanson (melanson at pcisys.net) * CD-ROM XA ADPCM codec by BERO + * EA ADPCM decoder by Robin Kay (komadori at myrealbox.com) + * EA ADPCM R1/R2/R3 decoder by Peter Ross (pross at xvid.org) + * EA IMA EACS decoder by Peter Ross (pross at xvid.org) + * EA IMA SEAD decoder by Peter Ross (pross at xvid.org) + * EA ADPCM XAS decoder by Peter Ross (pross at xvid.org) + * MAXIS EA ADPCM decoder by Robert Marston (rmarston at gmail.com) + * THP ADPCM decoder by Marco Gerards (mgerards at xs4all.nl) * * Features and limitations: * @@ -44,12 +55,6 @@ #define BLKSIZE 1024 -#define CLAMP_TO_SHORT(value) \ -if (value > 32767) \ - value = 32767; \ -else if (value < -32768) \ - value = -32768; \ - /* step_table[] and index_table[] are from the ADPCM reference source */ /* This is the index table: */ static const int index_table[16] = { @@ -57,7 +62,7 @@ -1, -1, -1, -1, 2, 4, 6, 8, }; -/** +/** * This is the step table. Note that many programs use slight deviations from * this table, but such deviations are negligible: */ @@ -80,12 +85,12 @@ 768, 614, 512, 409, 307, 230, 230, 230 }; -static const int AdaptCoeff1[] = { - 256, 512, 0, 192, 240, 460, 392 +static const uint8_t AdaptCoeff1[] = { + 64, 128, 0, 48, 60, 115, 98 }; -static const int AdaptCoeff2[] = { - 0, -256, 0, 64, 0, -208, -232 +static const int8_t AdaptCoeff2[] = { + 0, -64, 0, 16, 0, -52, -58 }; /* These are for CD-ROM XA ADPCM */ @@ -97,6 +102,34 @@ { 122, -60 } }; +static const int ea_adpcm_table[] = { + 0, 240, 460, 392, 0, 0, -208, -220, 0, 1, + 3, 4, 7, 8, 10, 11, 0, -1, -3, -4 +}; + +static const int ct_adpcm_table[8] = { + 0x00E6, 0x00E6, 0x00E6, 0x00E6, + 0x0133, 0x0199, 0x0200, 0x0266 +}; + +// padded to zero where table size is less then 16 +static const int swf_index_tables[4][16] = { + /*2*/ { -1, 2 }, + /*3*/ { -1, -1, 2, 4 }, + /*4*/ { -1, -1, -1, -1, 2, 4, 6, 8 }, + /*5*/ { -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16 } +}; + +static const int yamaha_indexscale[] = { + 230, 230, 230, 230, 307, 409, 512, 614, + 230, 230, 230, 230, 307, 409, 512, 614 +}; + +static const int yamaha_difflookup[] = { + 1, 3, 5, 7, 9, 11, 13, 15, + -1, -3, -5, -7, -9, -11, -13, -15 +}; + /* end of tables */ typedef struct ADPCMChannelStatus { @@ -115,9 +148,7 @@ } ADPCMChannelStatus; typedef struct ADPCMContext { - int channel; /* for stereo MOVs, decode left, then decode right, then tell it's decoded */ - ADPCMChannelStatus status[2]; - short sample_buffer[32]; /* hold left samples while waiting for right samples */ + ADPCMChannelStatus status[6]; } ADPCMContext; /* XXX: implement encoding */ @@ -127,22 +158,41 @@ { if (avctx->channels > 2) return -1; /* only stereo or mono =) */ + + if(avctx->trellis && (unsigned)avctx->trellis > 16U){ + av_log(avctx, AV_LOG_ERROR, "invalid trellis size\n"); + return -1; + } + switch(avctx->codec->id) { - case CODEC_ID_ADPCM_IMA_QT: - av_log(avctx, AV_LOG_ERROR, "ADPCM: codec adpcm_ima_qt unsupported for encoding !\n"); - avctx->frame_size = 64; /* XXX: can multiple of avctx->channels * 64 (left and right blocks are interleaved) */ - return -1; - break; case CODEC_ID_ADPCM_IMA_WAV: avctx->frame_size = (BLKSIZE - 4 * avctx->channels) * 8 / (4 * avctx->channels) + 1; /* each 16 bits sample gives one nibble */ /* and we have 4 bytes per channel overhead */ avctx->block_align = BLKSIZE; /* seems frame_size isn't taken into account... have to buffer the samples :-( */ break; + case CODEC_ID_ADPCM_IMA_QT: + avctx->frame_size = 64; + avctx->block_align = 34 * avctx->channels; + break; case CODEC_ID_ADPCM_MS: - av_log(avctx, AV_LOG_ERROR, "ADPCM: codec adpcm_ms unsupported for encoding !\n"); - return -1; + avctx->frame_size = (BLKSIZE - 7 * avctx->channels) * 2 / avctx->channels + 2; /* each 16 bits sample gives one nibble */ + /* and we have 7 bytes per channel overhead */ + avctx->block_align = BLKSIZE; break; + case CODEC_ID_ADPCM_YAMAHA: + avctx->frame_size = BLKSIZE * avctx->channels; + avctx->block_align = BLKSIZE; [... truncated: 6949 lines follow ...] From dlmcpaul at mail.berlios.de Mon Sep 15 16:02:06 2008 From: dlmcpaul at mail.berlios.de (dlmcpaul at BerliOS) Date: Mon, 15 Sep 2008 16:02:06 +0200 Subject: [Haiku-commits] r27543 - haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec Message-ID: <200809151402.m8FE26lc032720@sheep.berlios.de> Author: dlmcpaul Date: 2008-09-15 16:02:05 +0200 (Mon, 15 Sep 2008) New Revision: 27543 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27543&view=rev Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/beosthread.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/bethsoftvideo.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/bethsoftvideo.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/bfi.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/bitstream.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/bitstream.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/bitstream_filter.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/bmp.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/bmp.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/bmpenc.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/bytestream.h Log: Update avcodec to 20080825 Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/beosthread.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/beosthread.c 2008-09-15 14:00:59 UTC (rev 27542) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/beosthread.c 2008-09-15 14:02:05 UTC (rev 27543) @@ -0,0 +1,180 @@ +/* + * Copyright (c) 2004 Fran?ois Revol + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +//#define DEBUG + +#include "avcodec.h" + +#include + +typedef struct ThreadContext{ + AVCodecContext *avctx; + thread_id thread; + sem_id work_sem; + sem_id done_sem; + int (*func)(AVCodecContext *c, void *arg); + void *arg; + int ret; +}ThreadContext; + +// it's odd Be never patented that :D +struct benaphore { + vint32 atom; + sem_id sem; +}; +static inline int lock_ben(struct benaphore *ben) +{ + if (atomic_add(&ben->atom, 1) > 0) + return acquire_sem(ben->sem); + return B_OK; +} +static inline int unlock_ben(struct benaphore *ben) +{ + if (atomic_add(&ben->atom, -1) > 1) + return release_sem(ben->sem); + return B_OK; +} + +static struct benaphore av_thread_lib_ben; + +static int32 ff_thread_func(void *v){ + ThreadContext *c= v; + + for(;;){ +//printf("thread_func %X enter wait\n", (int)v); fflush(stdout); + acquire_sem(c->work_sem); +//printf("thread_func %X after wait (func=%X)\n", (int)v, (int)c->func); fflush(stdout); + if(c->func) + c->ret= c->func(c->avctx, c->arg); + else + return 0; +//printf("thread_func %X signal complete\n", (int)v); fflush(stdout); + release_sem(c->done_sem); + } + + return B_OK; +} + +/** + * Free what has been allocated by avcodec_thread_init(). + * Must be called after decoding has finished, especially do not call while avcodec_thread_execute() is running. + */ +void avcodec_thread_free(AVCodecContext *s){ + ThreadContext *c= s->thread_opaque; + int i; + int32 ret; + + for(i=0; ithread_count; i++){ + + c[i].func= NULL; + release_sem(c[i].work_sem); + wait_for_thread(c[i].thread, &ret); + if(c[i].work_sem > B_OK) delete_sem(c[i].work_sem); + if(c[i].done_sem > B_OK) delete_sem(c[i].done_sem); + } + + av_freep(&s->thread_opaque); +} + +int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count){ + ThreadContext *c= s->thread_opaque; + int i; + + assert(s == c->avctx); + assert(count <= s->thread_count); + + /* note, we can be certain that this is not called with the same AVCodecContext by different threads at the same time */ + + for(i=0; ithread_count= thread_count; + + assert(!s->thread_opaque); + c= av_mallocz(sizeof(ThreadContext)*thread_count); + s->thread_opaque= c; + + for(i=0; iexecute= avcodec_thread_execute; + + return 0; +fail: + avcodec_thread_free(s); + return -1; +} + +/* provide a mean to serialize calls to avcodec_*() for thread safety. */ + +int avcodec_thread_lock_lib(void) +{ + return lock_ben(&av_thread_lib_ben); +} + +int avcodec_thread_unlock_lib(void) +{ + return unlock_ben(&av_thread_lib_ben); +} + +/* our versions of _init and _fini (which are called by those actually from crt.o) */ + +void initialize_after(void) +{ + av_thread_lib_ben.atom = 0; + av_thread_lib_ben.sem = create_sem(0, "libavcodec benaphore"); +} + +void uninitialize_before(void) +{ + delete_sem(av_thread_lib_ben.sem); +} + + + Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/bethsoftvideo.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/bethsoftvideo.c 2008-09-15 14:00:59 UTC (rev 27542) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/bethsoftvideo.c 2008-09-15 14:02:05 UTC (rev 27543) @@ -0,0 +1,140 @@ +/* + * Bethesda VID video decoder + * Copyright (C) 2007 Nicholas Tung + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file bethsoftvideo.c + * @brief Bethesda Softworks VID Video Decoder + * @author Nicholas Tung [ntung (at. ntung com] (2007-03) + * @sa http://wiki.multimedia.cx/index.php?title=Bethsoft_VID + * @sa http://www.svatopluk.com/andux/docs/dfvid.html + */ + +#include "libavutil/common.h" +#include "dsputil.h" +#include "bethsoftvideo.h" +#include "bytestream.h" + +typedef struct BethsoftvidContext { + AVFrame frame; +} BethsoftvidContext; + +static av_cold int bethsoftvid_decode_init(AVCodecContext *avctx) +{ + BethsoftvidContext *vid = avctx->priv_data; + vid->frame.reference = 1; + vid->frame.buffer_hints = FF_BUFFER_HINTS_VALID | + FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; + avctx->pix_fmt = PIX_FMT_PAL8; + return 0; +} + +static void set_palette(AVFrame * frame, const uint8_t * palette_buffer) +{ + uint32_t * palette = (uint32_t *)frame->data[1]; + int a; + for(a = 0; a < 256; a++){ + palette[a] = AV_RB24(&palette_buffer[a * 3]) * 4; + } + frame->palette_has_changed = 1; +} + +static int bethsoftvid_decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + const uint8_t *buf, int buf_size) +{ + BethsoftvidContext * vid = avctx->priv_data; + char block_type; + uint8_t * dst; + uint8_t * frame_end; + int remaining = avctx->width; // number of bytes remaining on a line + const int wrap_to_next_line = vid->frame.linesize[0] - avctx->width; + int code; + int yoffset; + + if (avctx->reget_buffer(avctx, &vid->frame)) { + av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); + return -1; + } + dst = vid->frame.data[0]; + frame_end = vid->frame.data[0] + vid->frame.linesize[0] * avctx->height; + + switch(block_type = *buf++){ + case PALETTE_BLOCK: + set_palette(&vid->frame, buf); + return 0; + case VIDEO_YOFF_P_FRAME: + yoffset = bytestream_get_le16(&buf); + if(yoffset >= avctx->height) + return -1; + dst += vid->frame.linesize[0] * yoffset; + } + + // main code + while((code = *buf++)){ + int length = code & 0x7f; + + // copy any bytes starting at the current position, and ending at the frame width + while(length > remaining){ + if(code < 0x80) + bytestream_get_buffer(&buf, dst, remaining); + else if(block_type == VIDEO_I_FRAME) + memset(dst, buf[0], remaining); + length -= remaining; // decrement the number of bytes to be copied + dst += remaining + wrap_to_next_line; // skip over extra bytes at end of frame + remaining = avctx->width; + if(dst == frame_end) + goto end; + } + + // copy any remaining bytes after / if line overflows + if(code < 0x80) + bytestream_get_buffer(&buf, dst, length); + else if(block_type == VIDEO_I_FRAME) + memset(dst, *buf++, length); + remaining -= length; + dst += length; + } + end: + + *data_size = sizeof(AVFrame); + *(AVFrame*)data = vid->frame; + + return buf_size; +} + +static av_cold int bethsoftvid_decode_end(AVCodecContext *avctx) +{ + BethsoftvidContext * vid = avctx->priv_data; + if(vid->frame.data[0]) + avctx->release_buffer(avctx, &vid->frame); + return 0; +} + +AVCodec bethsoftvid_decoder = { + .name = "bethsoftvid", + .type = CODEC_TYPE_VIDEO, + .id = CODEC_ID_BETHSOFTVID, + .priv_data_size = sizeof(BethsoftvidContext), + .init = bethsoftvid_decode_init, + .close = bethsoftvid_decode_end, + .decode = bethsoftvid_decode_frame, + .long_name = NULL_IF_CONFIG_SMALL("Bethesda VID video"), +}; Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/bethsoftvideo.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/bethsoftvideo.h 2008-09-15 14:00:59 UTC (rev 27542) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/bethsoftvideo.h 2008-09-15 14:02:05 UTC (rev 27543) @@ -0,0 +1,36 @@ +/* + * Bethesda VID video decoder + * Copyright (C) 2007 Nicholas Tung + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_BETHSOFTVIDEO_H +#define FFMPEG_BETHSOFTVIDEO_H + +enum BethsoftVidBlockType +{ + PALETTE_BLOCK = 0x02, + FIRST_AUDIO_BLOCK = 0x7c, + AUDIO_BLOCK = 0x7d, + VIDEO_I_FRAME = 0x03, + VIDEO_P_FRAME = 0x01, + VIDEO_YOFF_P_FRAME = 0x04, + EOF_BLOCK = 0x14, +}; + +#endif /* FFMPEG_BETHSOFTVIDEO_H */ Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/bfi.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/bfi.c 2008-09-15 14:00:59 UTC (rev 27542) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/bfi.c 2008-09-15 14:02:05 UTC (rev 27543) @@ -0,0 +1,182 @@ +/* + * Brute Force & Ignorance (BFI) video decoder + * Copyright (c) 2008 Sisir Koppaka + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file bfi.c + * @brief Brute Force & Ignorance (.bfi) video decoder + * @author Sisir Koppaka ( sisir.koppaka at gmail dot com ) + * @sa http://wiki.multimedia.cx/index.php?title=BFI + */ + +#include "common.h" +#include "avcodec.h" +#include "bytestream.h" + +typedef struct BFIContext { + AVCodecContext *avctx; + AVFrame frame; + uint8_t *dst; +} BFIContext; + +static int bfi_decode_init(AVCodecContext * avctx) +{ + BFIContext *bfi = avctx->priv_data; + avctx->pix_fmt = PIX_FMT_PAL8; + bfi->dst = av_mallocz(avctx->width * avctx->height); + return 0; +} + +static int bfi_decode_frame(AVCodecContext * avctx, void *data, + int *data_size, const uint8_t * buf, + int buf_size) +{ + BFIContext *bfi = avctx->priv_data; + uint8_t *dst = bfi->dst; + uint8_t *src, *dst_offset, colour1, colour2; + uint8_t *frame_end = bfi->dst + avctx->width * avctx->height; + uint32_t *pal; + int i, j, height = avctx->height; + + if (bfi->frame.data[0]) + avctx->release_buffer(avctx, &bfi->frame); + + bfi->frame.reference = 1; + + if (avctx->get_buffer(avctx, &bfi->frame) < 0) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } + + /* Set frame parameters and palette, if necessary */ + if (!avctx->frame_number) { + bfi->frame.pict_type = FF_I_TYPE; + bfi->frame.key_frame = 1; + /* Setting the palette */ + if(avctx->extradata_size>768) { + av_log(NULL, AV_LOG_ERROR, "Palette is too large.\n"); + return -1; + } + pal = (uint32_t *) bfi->frame.data[1]; + for (i = 0; i < avctx->extradata_size / 3; i++) { + int shift = 16; + *pal = 0; + for (j = 0; j < 3; j++, shift -= 8) + *pal += + ((avctx->extradata[i * 3 + j] << 2) | + (avctx->extradata[i * 3 + j] >> 4)) << shift; + pal++; + } + bfi->frame.palette_has_changed = 1; + } else { + bfi->frame.pict_type = FF_P_TYPE; + bfi->frame.key_frame = 0; + } + + buf += 4; //Unpacked size, not required. + + while (dst != frame_end) { + static const uint8_t lentab[4]={0,2,0,1}; + unsigned int byte = *buf++, offset; + unsigned int code = byte >> 6; + unsigned int length = byte & ~0xC0; + + /* Get length and offset(if required) */ + if (length == 0) { + if (code == 1) { + length = bytestream_get_byte(&buf); + offset = bytestream_get_le16(&buf); + } else { + length = bytestream_get_le16(&buf); + if (code == 2 && length == 0) + break; + } + } else { + if (code == 1) + offset = bytestream_get_byte(&buf); + } + + /* Do boundary check */ + if (dst + (length< frame_end) + break; + + switch (code) { + + case 0: //Normal Chain + bytestream_get_buffer(&buf, dst, length); + dst += length; + break; + + case 1: //Back Chain + dst_offset = dst - offset; + length *= 4; //Convert dwords to bytes. + if (dst_offset < bfi->dst) + break; + while (length--) + *dst++ = *dst_offset++; + break; + + case 2: //Skip Chain + dst += length; + break; + + case 3: //Fill Chain + colour1 = bytestream_get_byte(&buf); + colour2 = bytestream_get_byte(&buf); + while (length--) { + *dst++ = colour1; + *dst++ = colour2; + } + break; + + } + } + + src = bfi->dst; + dst = bfi->frame.data[0]; + while (height--) { + memcpy(dst, src, avctx->width); + src += avctx->width; + dst += bfi->frame.linesize[0]; + } + *data_size = sizeof(AVFrame); + *(AVFrame *) data = bfi->frame; + return buf_size; +} + +static int bfi_decode_close(AVCodecContext * avctx) +{ + BFIContext *bfi = avctx->priv_data; + if (bfi->frame.data[0]) + avctx->release_buffer(avctx, &bfi->frame); + av_free(bfi->dst); + return 0; +} + +AVCodec bfi_decoder = { + .name = "bfi", + .type = CODEC_TYPE_VIDEO, + .id = CODEC_ID_BFI, + .priv_data_size = sizeof(BFIContext), + .init = bfi_decode_init, + .close = bfi_decode_close, + .decode = bfi_decode_frame, + .long_name = NULL_IF_CONFIG_SMALL("Brute Force & Ignorance"), +}; Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/bitstream.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/bitstream.c 2008-09-15 14:00:59 UTC (rev 27542) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/bitstream.c 2008-09-15 14:02:05 UTC (rev 27543) @@ -0,0 +1,320 @@ +/* + * Common bit i/o utils + * Copyright (c) 2000, 2001 Fabrice Bellard. + * Copyright (c) 2002-2004 Michael Niedermayer + * + * alternative bitstream reader & writer by Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file bitstream.c + * bitstream api. + */ + +#include "avcodec.h" +#include "bitstream.h" + +const uint8_t ff_log2_run[32]={ + 0, 0, 0, 0, 1, 1, 1, 1, + 2, 2, 2, 2, 3, 3, 3, 3, + 4, 4, 5, 5, 6, 6, 7, 7, + 8, 9,10,11,12,13,14,15 +}; + +/** + * Same as av_mallocz_static(), but does a realloc. + * + * @param[in] ptr The block of memory to reallocate. + * @param[in] size The requested size. + * @return Block of memory of requested size. + * @deprecated. Code which uses ff_realloc_static is broken/misdesigned + * and should correctly use static arrays + */ +attribute_deprecated av_alloc_size(2) +static void *ff_realloc_static(void *ptr, unsigned int size); + +static void *ff_realloc_static(void *ptr, unsigned int size) +{ + return av_realloc(ptr, size); +} + +void align_put_bits(PutBitContext *s) +{ +#ifdef ALT_BITSTREAM_WRITER + put_bits(s,( - s->index) & 7,0); +#else + put_bits(s,s->bit_left & 7,0); +#endif +} + +void ff_put_string(PutBitContext * pbc, const char *s, int put_zero) +{ + while(*s){ + put_bits(pbc, 8, *s); + s++; + } + if(put_zero) + put_bits(pbc, 8, 0); +} + +void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length) +{ + const uint16_t *srcw= (const uint16_t*)src; + int words= length>>4; + int bits= length&15; + int i; + + if(length==0) return; + + if(ENABLE_SMALL || words < 16 || put_bits_count(pb)&7){ + for(i=0; i>(16-bits)); +} + +/* VLC decoding */ + +//#define DEBUG_VLC + +#define GET_DATA(v, table, i, wrap, size) \ +{\ + const uint8_t *ptr = (const uint8_t *)table + i * wrap;\ + switch(size) {\ + case 1:\ + v = *(const uint8_t *)ptr;\ + break;\ + case 2:\ + v = *(const uint16_t *)ptr;\ + break;\ + default:\ + v = *(const uint32_t *)ptr;\ + break;\ + }\ +} + + +static int alloc_table(VLC *vlc, int size, int use_static) +{ + int index; + index = vlc->table_size; + vlc->table_size += size; + if (vlc->table_size > vlc->table_allocated) { + if(use_static>1) + abort(); //cant do anything, init_vlc() is used with too little memory + vlc->table_allocated += (1 << vlc->bits); + if(use_static) + vlc->table = ff_realloc_static(vlc->table, + sizeof(VLC_TYPE) * 2 * vlc->table_allocated); + else + vlc->table = av_realloc(vlc->table, + sizeof(VLC_TYPE) * 2 * vlc->table_allocated); + if (!vlc->table) + return -1; + } + return index; +} + +static int build_table(VLC *vlc, int table_nb_bits, + int nb_codes, + const void *bits, int bits_wrap, int bits_size, + const void *codes, int codes_wrap, int codes_size, + const void *symbols, int symbols_wrap, int symbols_size, + uint32_t code_prefix, int n_prefix, int flags) +{ + int i, j, k, n, table_size, table_index, nb, n1, index, code_prefix2, symbol; + uint32_t code; + VLC_TYPE (*table)[2]; + + table_size = 1 << table_nb_bits; + table_index = alloc_table(vlc, table_size, flags & (INIT_VLC_USE_STATIC|INIT_VLC_USE_NEW_STATIC)); +#ifdef DEBUG_VLC + av_log(NULL,AV_LOG_DEBUG,"new table index=%d size=%d code_prefix=%x n=%d\n", + table_index, table_size, code_prefix, n_prefix); +#endif + if (table_index < 0) + return -1; + table = &vlc->table[table_index]; + + for(i=0;i=32 ? 0xffffffff : (1 << n_prefix)-1); + else + code_prefix2= code >> n; + if (n > 0 && code_prefix2 == code_prefix) { + if (n <= table_nb_bits) { + /* no need to add another table */ + j = (code << (table_nb_bits - n)) & (table_size - 1); + nb = 1 << (table_nb_bits - n); + for(k=0;k> n_prefix) + (k<> ((flags & INIT_VLC_LE) ? n_prefix : n)) & ((1 << table_nb_bits) - 1); +#ifdef DEBUG_VLC + av_log(NULL,AV_LOG_DEBUG,"%4x: n=%d (subtable)\n", + j, n); +#endif + /* compute table size */ + n1 = -table[j][1]; //bits + if (n > n1) + n1 = n; + table[j][1] = -n1; //bits + } + } + } + + /* second pass : fill auxillary tables recursively */ + for(i=0;i table_nb_bits) { + n = table_nb_bits; + table[i][1] = -n; //bits + } + index = build_table(vlc, n, nb_codes, + bits, bits_wrap, bits_size, + codes, codes_wrap, codes_size, + symbols, symbols_wrap, symbols_size, + (flags & INIT_VLC_LE) ? (code_prefix | (i << n_prefix)) : ((code_prefix << table_nb_bits) | i), + n_prefix + table_nb_bits, flags); + if (index < 0) + return -1; + /* note: realloc has been done, so reload tables */ + table = &vlc->table[table_index]; + table[i][0] = index; //code + } + } + return table_index; +} + + +/* Build VLC decoding tables suitable for use with get_vlc(). + + 'nb_bits' set thee decoding table size (2^nb_bits) entries. The + bigger it is, the faster is the decoding. But it should not be too + big to save memory and L1 cache. '9' is a good compromise. + + 'nb_codes' : number of vlcs codes + + 'bits' : table which gives the size (in bits) of each vlc code. + + 'codes' : table which gives the bit pattern of of each vlc code. + + 'symbols' : table which gives the values to be returned from get_vlc(). + + 'xxx_wrap' : give the number of bytes between each entry of the + 'bits' or 'codes' tables. + + 'xxx_size' : gives the number of bytes of each entry of the 'bits' + or 'codes' tables. + + 'wrap' and 'size' allows to use any memory configuration and types + (byte/word/long) to store the 'bits', 'codes', and 'symbols' tables. + + 'use_static' should be set to 1 for tables, which should be freed + with av_free_static(), 0 if free_vlc() will be used. +*/ +int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, + const void *bits, int bits_wrap, int bits_size, + const void *codes, int codes_wrap, int codes_size, + const void *symbols, int symbols_wrap, int symbols_size, + int flags) +{ + vlc->bits = nb_bits; + if(flags & INIT_VLC_USE_NEW_STATIC){ + if(vlc->table_size && vlc->table_size == vlc->table_allocated){ + return 0; + }else if(vlc->table_size){ + abort(); // fatal error, we are called on a partially initialized table + } + }else if(!(flags & INIT_VLC_USE_STATIC)) { + vlc->table = NULL; + vlc->table_allocated = 0; + vlc->table_size = 0; + } else { + /* Static tables are initially always NULL, return + if vlc->table != NULL to avoid double allocation */ + if(vlc->table) + return 0; + } + +#ifdef DEBUG_VLC + av_log(NULL,AV_LOG_DEBUG,"build table nb_codes=%d\n", nb_codes); +#endif + + if (build_table(vlc, nb_bits, nb_codes, + bits, bits_wrap, bits_size, + codes, codes_wrap, codes_size, + symbols, symbols_wrap, symbols_size, + 0, 0, flags) < 0) { + av_freep(&vlc->table); + return -1; + } + if((flags & INIT_VLC_USE_NEW_STATIC) && vlc->table_size != vlc->table_allocated) + av_log(NULL, AV_LOG_ERROR, "needed %d had %d\n", vlc->table_size, vlc->table_allocated); + return 0; +} + + +void free_vlc(VLC *vlc) +{ + av_freep(&vlc->table); +} + Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/bitstream.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/bitstream.h 2008-09-15 14:00:59 UTC (rev 27542) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/bitstream.h 2008-09-15 14:02:05 UTC (rev 27543) @@ -0,0 +1,931 @@ +/* + * copyright (c) 2004 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file bitstream.h + * bitstream api header. + */ + +#ifndef FFMPEG_BITSTREAM_H +#define FFMPEG_BITSTREAM_H + +#include +#include +#include +#include "bswap.h" +#include "common.h" +#include "intreadwrite.h" +#include "log.h" + +#if defined(ALT_BITSTREAM_READER_LE) && !defined(ALT_BITSTREAM_READER) +# define ALT_BITSTREAM_READER +#endif + +//#define ALT_BITSTREAM_WRITER +//#define ALIGNED_BITSTREAM_WRITER +#if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER) +# ifdef ARCH_ARMV4L +# define A32_BITSTREAM_READER +# else +# define ALT_BITSTREAM_READER +//#define LIBMPEG2_BITSTREAM_READER +//#define A32_BITSTREAM_READER +# endif +#endif + +extern const uint8_t ff_reverse[256]; + +#if defined(ARCH_X86) +// avoid +32 for shift optimization (gcc should do that ...) +static inline int32_t NEG_SSR32( int32_t a, int8_t s){ + asm ("sarl %1, %0\n\t" + : "+r" (a) + : "ic" ((uint8_t)(-s)) + ); + return a; +} +static inline uint32_t NEG_USR32(uint32_t a, int8_t s){ + asm ("shrl %1, %0\n\t" + : "+r" (a) + : "ic" ((uint8_t)(-s)) + ); + return a; +} +#else +# define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s))) +# define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s))) +#endif + +/* bit output */ + +/* buf and buf_end must be present and used by every alternative writer. */ +typedef struct PutBitContext { +#ifdef ALT_BITSTREAM_WRITER + uint8_t *buf, *buf_end; + int index; +#else + uint32_t bit_buf; + int bit_left; + uint8_t *buf, *buf_ptr, *buf_end; +#endif +} PutBitContext; + +static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size) +{ + if(buffer_size < 0) { + buffer_size = 0; + buffer = NULL; + } + + s->buf = buffer; + s->buf_end = s->buf + buffer_size; +#ifdef ALT_BITSTREAM_WRITER + s->index=0; + ((uint32_t*)(s->buf))[0]=0; +// memset(buffer, 0, buffer_size); +#else + s->buf_ptr = s->buf; + s->bit_left=32; + s->bit_buf=0; +#endif [... truncated: 1388 lines follow ...] From dlmcpaul at mail.berlios.de Mon Sep 15 16:02:22 2008 From: dlmcpaul at mail.berlios.de (dlmcpaul at BerliOS) Date: Mon, 15 Sep 2008 16:02:22 +0200 Subject: [Haiku-commits] r27544 - haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec Message-ID: <200809151402.m8FE2M2P032755@sheep.berlios.de> Author: dlmcpaul Date: 2008-09-15 16:02:19 +0200 (Mon, 15 Sep 2008) New Revision: 27544 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27544&view=rev Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/c93.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/cavs.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/cavs.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/cavs_parser.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/cavsdata.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/cavsdec.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/cavsdsp.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/colorspace.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/cook.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/cookdata.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/cscd.c Modified: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/cabac.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/cabac.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/cinepak.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/cljr.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/config.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/cyuv.c Log: Update avcodec to 20080825 Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/c93.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/c93.c 2008-09-15 14:02:05 UTC (rev 27543) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/c93.c 2008-09-15 14:02:19 UTC (rev 27544) @@ -0,0 +1,254 @@ +/* + * Interplay C93 video decoder + * Copyright (c) 2007 Anssi Hannula + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avcodec.h" +#include "bytestream.h" + +typedef struct { + AVFrame pictures[2]; + int currentpic; +} C93DecoderContext; + +typedef enum { + C93_8X8_FROM_PREV = 0x02, + C93_4X4_FROM_PREV = 0x06, + C93_4X4_FROM_CURR = 0x07, + C93_8X8_2COLOR = 0x08, + C93_4X4_2COLOR = 0x0A, + C93_4X4_4COLOR_GRP = 0x0B, + C93_4X4_4COLOR = 0x0D, + C93_NOOP = 0x0E, + C93_8X8_INTRA = 0x0F, +} C93BlockType; + +#define WIDTH 320 +#define HEIGHT 192 + +#define C93_HAS_PALETTE 0x01 +#define C93_FIRST_FRAME 0x02 + +static av_cold int decode_init(AVCodecContext *avctx) +{ + avctx->pix_fmt = PIX_FMT_PAL8; + return 0; +} + +static av_cold int decode_end(AVCodecContext *avctx) +{ + C93DecoderContext * const c93 = avctx->priv_data; + + if (c93->pictures[0].data[0]) + avctx->release_buffer(avctx, &c93->pictures[0]); + if (c93->pictures[1].data[0]) + avctx->release_buffer(avctx, &c93->pictures[1]); + return 0; +} + +static inline int copy_block(AVCodecContext *avctx, uint8_t *to, + uint8_t *from, int offset, int height, int stride) +{ + int i; + int width = height; + int from_x = offset % WIDTH; + int from_y = offset / WIDTH; + int overflow = from_x + width - WIDTH; + + if (!from) { + /* silently ignoring predictive blocks in first frame */ + return 0; + } + + if (from_y + height > HEIGHT) { + av_log(avctx, AV_LOG_ERROR, "invalid offset %d during C93 decoding\n", + offset); + return -1; + } + + if (overflow > 0) { + width -= overflow; + for (i = 0; i < height; i++) { + memcpy(&to[i*stride+width], &from[(from_y+i)*stride], overflow); + } + } + + for (i = 0; i < height; i++) { + memcpy(&to[i*stride], &from[(from_y+i)*stride+from_x], width); + } + + return 0; +} + +static inline void draw_n_color(uint8_t *out, int stride, int width, + int height, int bpp, uint8_t cols[4], uint8_t grps[4], uint32_t col) +{ + int x, y; + for (y = 0; y < height; y++) { + if (grps) + cols[0] = grps[3 * (y >> 1)]; + for (x = 0; x < width; x++) { + if (grps) + cols[1]= grps[(x >> 1) + 1]; + out[x + y*stride] = cols[col & ((1 << bpp) - 1)]; + col >>= bpp; + } + } +} + +static int decode_frame(AVCodecContext *avctx, void *data, + int *data_size, const uint8_t * buf, int buf_size) +{ + C93DecoderContext * const c93 = avctx->priv_data; + AVFrame * const newpic = &c93->pictures[c93->currentpic]; + AVFrame * const oldpic = &c93->pictures[c93->currentpic^1]; + AVFrame *picture = data; + uint8_t *out; + int stride, i, x, y, bt = 0; + + c93->currentpic ^= 1; + + newpic->reference = 1; + newpic->buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | + FF_BUFFER_HINTS_REUSABLE | FF_BUFFER_HINTS_READABLE; + if (avctx->reget_buffer(avctx, newpic)) { + av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); + return -1; + } + + stride = newpic->linesize[0]; + + if (buf[0] & C93_FIRST_FRAME) { + newpic->pict_type = FF_I_TYPE; + newpic->key_frame = 1; + } else { + newpic->pict_type = FF_P_TYPE; + newpic->key_frame = 0; + } + + if (*buf++ & C93_HAS_PALETTE) { + uint32_t *palette = (uint32_t *) newpic->data[1]; + const uint8_t *palbuf = buf + buf_size - 768 - 1; + for (i = 0; i < 256; i++) { + palette[i] = bytestream_get_be24(&palbuf); + } + } else { + if (oldpic->data[1]) + memcpy(newpic->data[1], oldpic->data[1], 256 * 4); + } + + for (y = 0; y < HEIGHT; y += 8) { + out = newpic->data[0] + y * stride; + for (x = 0; x < WIDTH; x += 8) { + uint8_t *copy_from = oldpic->data[0]; + unsigned int offset, j; + uint8_t cols[4], grps[4]; + C93BlockType block_type; + + if (!bt) + bt = *buf++; + + block_type= bt & 0x0F; + switch (block_type) { + case C93_8X8_FROM_PREV: + offset = bytestream_get_le16(&buf); + if (copy_block(avctx, out, copy_from, offset, 8, stride)) + return -1; + break; + + case C93_4X4_FROM_CURR: + copy_from = newpic->data[0]; + case C93_4X4_FROM_PREV: + for (j = 0; j < 8; j += 4) { + for (i = 0; i < 8; i += 4) { + offset = bytestream_get_le16(&buf); + if (copy_block(avctx, &out[j*stride+i], + copy_from, offset, 4, stride)) + return -1; + } + } + break; + + case C93_8X8_2COLOR: + bytestream_get_buffer(&buf, cols, 2); + for (i = 0; i < 8; i++) { + draw_n_color(out + i*stride, stride, 8, 1, 1, cols, + NULL, *buf++); + } + + break; + + case C93_4X4_2COLOR: + case C93_4X4_4COLOR: + case C93_4X4_4COLOR_GRP: + for (j = 0; j < 8; j += 4) { + for (i = 0; i < 8; i += 4) { + if (block_type == C93_4X4_2COLOR) { + bytestream_get_buffer(&buf, cols, 2); + draw_n_color(out + i + j*stride, stride, 4, 4, + 1, cols, NULL, bytestream_get_le16(&buf)); + } else if (block_type == C93_4X4_4COLOR) { + bytestream_get_buffer(&buf, cols, 4); + draw_n_color(out + i + j*stride, stride, 4, 4, + 2, cols, NULL, bytestream_get_le32(&buf)); + } else { + bytestream_get_buffer(&buf, grps, 4); + draw_n_color(out + i + j*stride, stride, 4, 4, + 1, cols, grps, bytestream_get_le16(&buf)); + } + } + } + break; + + case C93_NOOP: + break; + + case C93_8X8_INTRA: + for (j = 0; j < 8; j++) + bytestream_get_buffer(&buf, out + j*stride, 8); + break; + + default: + av_log(avctx, AV_LOG_ERROR, "unexpected type %x at %dx%d\n", + block_type, x, y); + return -1; + } + bt >>= 4; + out += 8; + } + } + + *picture = *newpic; + *data_size = sizeof(AVFrame); + + return buf_size; +} + +AVCodec c93_decoder = { + "c93", + CODEC_TYPE_VIDEO, + CODEC_ID_C93, + sizeof(C93DecoderContext), + decode_init, + NULL, + decode_end, + decode_frame, + CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Interplay C93"), +}; Modified: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/cabac.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/cabac.c 2008-09-15 14:02:05 UTC (rev 27543) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/cabac.c 2008-09-15 14:02:19 UTC (rev 27544) @@ -2,20 +2,21 @@ * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder * Copyright (c) 2003 Michael Niedermayer * - * This library is free software; you can redistribute it and/or + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. + * version 2.1 of the License, or (at your option) any later version. * - * This library is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** @@ -26,9 +27,10 @@ #include #include "common.h" +#include "bitstream.h" #include "cabac.h" -const uint8_t ff_h264_lps_range[64][4]= { +static const uint8_t lps_range[64][4]= { {128,176,208,240}, {128,167,197,227}, {128,158,187,216}, {123,150,178,205}, {116,142,169,195}, {111,135,160,185}, {105,128,152,175}, {100,122,144,166}, { 95,116,137,158}, { 90,110,130,150}, { 85,104,123,142}, { 81, 99,117,135}, @@ -47,7 +49,12 @@ { 6, 8, 9, 11}, { 6, 7, 9, 10}, { 6, 7, 8, 9}, { 2, 2, 2, 2}, }; -const uint8_t ff_h264_mps_state[64]= { +uint8_t ff_h264_mlps_state[4*64]; +uint8_t ff_h264_lps_range[4*2*64]; +uint8_t ff_h264_lps_state[2*64]; +uint8_t ff_h264_mps_state[2*64]; + +static const uint8_t mps_state[64]= { 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16, 17,18,19,20,21,22,23,24, @@ -58,7 +65,7 @@ 57,58,59,60,61,62,62,63, }; -const uint8_t ff_h264_lps_state[64]= { +static const uint8_t lps_state[64]= { 0, 0, 1, 2, 2, 4, 4, 5, 6, 7, 8, 9, 9,11,11,12, 13,13,15,15,16,16,18,18, @@ -68,6 +75,40 @@ 33,33,34,34,35,35,35,36, 36,36,37,37,37,38,38,63, }; +#if 0 +const uint8_t ff_h264_norm_shift_old[128]= { + 7,6,5,5,4,4,4,4,3,3,3,3,3,3,3,3, + 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +}; +#endif +const uint8_t ff_h264_norm_shift[512]= { + 9,8,7,7,6,6,6,6,5,5,5,5,5,5,5,5, + 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, + 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, + 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, + 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, + 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, + 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, + 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +}; /** * @@ -82,7 +123,7 @@ #ifdef STRICT_LIMITS c->sym_count =0; #endif - + c->pb.bit_left++; //avoids firstBitFlag } @@ -90,61 +131,80 @@ * * @param buf_size size of buf in bits */ -void ff_init_cabac_decoder(CABACContext *c, uint8_t *buf, int buf_size){ - c->bytestream_start= +void ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size){ + c->bytestream_start= c->bytestream= buf; + c->bytestream_end= buf + buf_size; - c->low= *c->bytestream++; - c->low= (c->low<<9) + ((*c->bytestream++)<<1); - c->range= 0x1FE00; - c->bits_left= 7; +#if CABAC_BITS == 16 + c->low = (*c->bytestream++)<<18; + c->low+= (*c->bytestream++)<<10; +#else + c->low = (*c->bytestream++)<<10; +#endif + c->low+= ((*c->bytestream++)<<2) + 2; + c->range= 0x1FE; } -void ff_init_cabac_states(CABACContext *c, uint8_t const (*lps_range)[4], - uint8_t const *mps_state, uint8_t const *lps_state, int state_count){ +void ff_init_cabac_states(CABACContext *c){ int i, j; - - for(i=0; ilps_range[2*i+0][j]= - c->lps_range[2*i+1][j]= lps_range[i][j]; + ff_h264_lps_range[j*2*64+2*i+0]= + ff_h264_lps_range[j*2*64+2*i+1]= lps_range[i][j]; } - c->mps_state[2*i+0]= 2*mps_state[i]; - c->mps_state[2*i+1]= 2*mps_state[i]+1; + ff_h264_mlps_state[128+2*i+0]= + ff_h264_mps_state[2*i+0]= 2*mps_state[i]+0; + ff_h264_mlps_state[128+2*i+1]= + ff_h264_mps_state[2*i+1]= 2*mps_state[i]+1; - if(lps_state[i]){ - c->lps_state[2*i+0]= 2*lps_state[i]; - c->lps_state[2*i+1]= 2*lps_state[i]+1; + if( i ){ +#ifdef BRANCHLESS_CABAC_DECODER + ff_h264_mlps_state[128-2*i-1]= 2*lps_state[i]+0; + ff_h264_mlps_state[128-2*i-2]= 2*lps_state[i]+1; }else{ - c->lps_state[2*i+0]= 1; - c->lps_state[2*i+1]= 0; + ff_h264_mlps_state[128-2*i-1]= 1; + ff_h264_mlps_state[128-2*i-2]= 0; +#else + ff_h264_lps_state[2*i+0]= 2*lps_state[i]+0; + ff_h264_lps_state[2*i+1]= 2*lps_state[i]+1; + }else{ + ff_h264_lps_state[2*i+0]= 1; + ff_h264_lps_state[2*i+1]= 0; +#endif } } } -#if 0 //selftest +#ifdef TEST +#undef random #define SIZE 10240 -int main(){ + +#include "avcodec.h" +#include "cabac.h" + +int main(void){ CABACContext c; uint8_t b[9*SIZE]; uint8_t r[9*SIZE]; int i; uint8_t state[10]= {0}; - + ff_init_cabac_encoder(&c, b, SIZE); - ff_init_cabac_states(&c, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64); - + ff_init_cabac_states(&c); + for(i=0; i * - * This library is free software; you can redistribute it and/or + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. + * version 2.1 of the License, or (at your option) any later version. * - * This library is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ - + /** * @file cabac.h * Context Adaptive Binary Arithmetic Coder. */ +#ifndef FFMPEG_CABAC_H +#define FFMPEG_CABAC_H -#undef NDEBUG +#include "bitstream.h" + +//#undef NDEBUG #include +#ifdef ARCH_X86 +#include "x86_cpu.h" +#endif +#define CABAC_BITS 16 +#define CABAC_MASK ((1<pb, 1, b); - for(;c->outstanding_count; c->outstanding_count--){ + put_bits(&c->pb, 1, b); + for(;c->outstanding_count; c->outstanding_count--){ put_bits(&c->pb, 1, 1-b); } } @@ -72,24 +84,25 @@ put_cabac_bit(c, 1); c->low -= 0x200; } - + c->range+= c->range; c->low += c->low; } } -static inline void put_cabac(CABACContext *c, uint8_t * const state, int bit){ - int RangeLPS= c->lps_range[*state][((c->range)>>6)&3]; - +#ifdef TEST +static void put_cabac(CABACContext *c, uint8_t * const state, int bit){ + int RangeLPS= ff_h264_lps_range[2*(c->range&0xC0) + *state]; + if(bit == ((*state)&1)){ c->range -= RangeLPS; - *state= c->mps_state[*state]; + *state= ff_h264_mps_state[*state]; }else{ c->low += c->range - RangeLPS; c->range = RangeLPS; - *state= c->lps_state[*state]; + *state= ff_h264_lps_state[*state]; } - + renorm_cabac_encoder(c); #ifdef STRICT_LIMITS @@ -97,7 +110,7 @@ #endif } -static inline void put_cabac_static(CABACContext *c, int RangeLPS, int bit){ +static void put_cabac_static(CABACContext *c, int RangeLPS, int bit){ assert(c->range > RangeLPS); if(!bit){ @@ -117,7 +130,7 @@ /** * @param bit 0 -> write zero bit, !=0 write one bit */ -static inline void put_cabac_bypass(CABACContext *c, int bit){ +static void put_cabac_bypass(CABACContext *c, int bit){ c->low += c->low; if(bit){ @@ -133,7 +146,7 @@ put_cabac_bit(c, 1); c->low -= 0x400; } - + #ifdef STRICT_LIMITS c->symCount++; #endif @@ -143,7 +156,7 @@ * * @return the number of bytes written */ -static inline int put_cabac_terminate(CABACContext *c, int bit){ +static int put_cabac_terminate(CABACContext *c, int bit){ c->range -= 2; if(!bit){ @@ -151,31 +164,31 @@ }else{ c->low += c->range; c->range= 2; - + renorm_cabac_encoder(c); assert(c->low <= 0x1FF); put_cabac_bit(c, c->low>>9); put_bits(&c->pb, 2, ((c->low>>7)&3)|1); - + flush_put_bits(&c->pb); //FIXME FIXME FIXME XXX wrong } - + #ifdef STRICT_LIMITS c->symCount++; #endif - return (get_bit_count(&c->pb)+7)>>3; + return (put_bits_count(&c->pb)+7)>>3; } /** * put (truncated) unary binarization. */ -static inline void put_cabac_u(CABACContext *c, uint8_t * state, int v, int max, int max_index, int truncated){ +static void put_cabac_u(CABACContext *c, uint8_t * state, int v, int max, int max_index, int truncated){ int i; - + assert(v <= max); - + #if 1 for(i=0; ilow+= (c->bytestream[0]<<9) + (c->bytestream[1]<<1); +#else + c->low+= c->bytestream[0]<<1; +#endif + c->low -= CABAC_MASK; + c->bytestream+= CABAC_BITS/8; +} + +#if ! ( defined(ARCH_X86) && defined(HAVE_7REGS) && defined(HAVE_EBX_AVAILABLE) && !defined(BROKEN_RELOCATIONS) ) +static void refill2(CABACContext *c){ + int i, x; + + x= c->low ^ (c->low-1); + i= 7 - ff_h264_norm_shift[x>>(CABAC_BITS-1)]; + + x= -CABAC_MASK; + +#if CABAC_BITS == 16 + x+= (c->bytestream[0]<<9) + (c->bytestream[1]<<1); +#else + x+= c->bytestream[0]<<1; +#endif + + c->low += x<bytestream+= CABAC_BITS/8; +} +#endif + static inline void renorm_cabac_decoder(CABACContext *c){ - while(c->range < 0x10000){ + while(c->range < 0x100){ c->range+= c->range; c->low+= c->low; - if(--c->bits_left == 0){ - c->low+= *c->bytestream++; - c->bits_left= 8; - } + if(!(c->low & CABAC_MASK)) + refill(c); } } -static inline int get_cabac(CABACContext *c, uint8_t * const state){ - int RangeLPS= c->lps_range[*state][((c->range)>>14)&3]<<8; - int bit; - - c->range -= RangeLPS; - if(c->low < c->range){ - bit= (*state)&1; - *state= c->mps_state[*state]; - }else{ - bit= ((*state)&1)^1; - c->low -= c->range; - c->range = RangeLPS; - *state= c->lps_state[*state]; - } - renorm_cabac_decoder(c); - - return bit; +static inline void renorm_cabac_decoder_once(CABACContext *c){ +#ifdef ARCH_X86_DISABLED + int temp; +#if 0 + //P3:683 athlon:475 + asm( + "lea -0x100(%0), %2 \n\t" + "shr $31, %2 \n\t" //FIXME 31->63 for x86-64 + "shl %%cl, %0 \n\t" + "shl %%cl, %1 \n\t" + : "+r"(c->range), "+r"(c->low), "+c"(temp) + ); +#elif 0 + //P3:680 athlon:474 + asm( + "cmp $0x100, %0 \n\t" + "setb %%cl \n\t" //FIXME 31->63 for x86-64 + "shl %%cl, %0 \n\t" + "shl %%cl, %1 \n\t" + : "+r"(c->range), "+r"(c->low), "+c"(temp) + ); +#elif 1 + int temp2; + //P3:665 athlon:517 + asm( + "lea -0x100(%0), %%eax \n\t" + "cltd \n\t" + "mov %0, %%eax \n\t" + "and %%edx, %0 \n\t" + "and %1, %%edx \n\t" + "add %%eax, %0 \n\t" + "add %%edx, %1 \n\t" + : "+r"(c->range), "+r"(c->low), "+a"(temp), "+d"(temp2) + ); +#elif 0 + int temp2; + //P3:673 athlon:509 + asm( + "cmp $0x100, %0 \n\t" + "sbb %%edx, %%edx \n\t" + "mov %0, %%eax \n\t" + "and %%edx, %0 \n\t" + "and %1, %%edx \n\t" + "add %%eax, %0 \n\t" + "add %%edx, %1 \n\t" + : "+r"(c->range), "+r"(c->low), "+a"(temp), "+d"(temp2) + ); +#else + int temp2; + //P3:677 athlon:511 + asm( + "cmp $0x100, %0 \n\t" + "lea (%0, %0), %%eax \n\t" + "lea (%1, %1), %%edx \n\t" + "cmovb %%eax, %0 \n\t" + "cmovb %%edx, %1 \n\t" + : "+r"(c->range), "+r"(c->low), "+a"(temp), "+d"(temp2) + ); +#endif +#else + //P3:675 athlon:476 + int shift= (uint32_t)(c->range - 0x100)>>31; + c->range<<= shift; + c->low <<= shift; +#endif + if(!(c->low & CABAC_MASK)) + refill(c); } -static inline int get_cabac_static(CABACContext *c, int RangeLPS){ +static av_always_inline int get_cabac_inline(CABACContext *c, uint8_t * const state){ + //FIXME gcc generates duplicate load/stores for c->low and c->range +#define LOW "0" +#define RANGE "4" +#ifdef ARCH_X86_64 +#define BYTESTART "16" +#define BYTE "24" +#define BYTEEND "32" +#else +#define BYTESTART "12" +#define BYTE "16" +#define BYTEEND "20" +#endif +#if defined(ARCH_X86) && defined(HAVE_7REGS) && defined(HAVE_EBX_AVAILABLE) && !defined(BROKEN_RELOCATIONS) int bit; - + +#ifndef BRANCHLESS_CABAC_DECODER + asm volatile( + "movzbl (%1), %0 \n\t" + "movl "RANGE "(%2), %%ebx \n\t" + "movl "RANGE "(%2), %%edx \n\t" + "andl $0xC0, %%ebx \n\t" + "movzbl "MANGLE(ff_h264_lps_range)"(%0, %%ebx, 2), %%esi\n\t" + "movl "LOW "(%2), %%ebx \n\t" +//eax:state ebx:low, edx:range, esi:RangeLPS + "subl %%esi, %%edx \n\t" + "movl %%edx, %%ecx \n\t" + "shll $17, %%ecx \n\t" + "cmpl %%ecx, %%ebx \n\t" + " ja 1f \n\t" + +#if 1 + //athlon:4067 P3:4110 + "lea -0x100(%%edx), %%ecx \n\t" + "shr $31, %%ecx \n\t" + "shl %%cl, %%edx \n\t" + "shl %%cl, %%ebx \n\t" +#else + //athlon:4057 P3:4130 + "cmp $0x100, %%edx \n\t" //FIXME avoidable + "setb %%cl \n\t" + "shl %%cl, %%edx \n\t" + "shl %%cl, %%ebx \n\t" +#endif + "movzbl "MANGLE(ff_h264_mps_state)"(%0), %%ecx \n\t" + "movb %%cl, (%1) \n\t" +//eax:state ebx:low, edx:range, esi:RangeLPS + "test %%bx, %%bx \n\t" + " jnz 2f \n\t" + "mov "BYTE "(%2), %%"REG_S" \n\t" + "subl $0xFFFF, %%ebx \n\t" + "movzwl (%%"REG_S"), %%ecx \n\t" + "bswap %%ecx \n\t" + "shrl $15, %%ecx \n\t" + "add $2, %%"REG_S" \n\t" + "addl %%ecx, %%ebx \n\t" + "mov %%"REG_S", "BYTE "(%2) \n\t" + "jmp 2f \n\t" + "1: \n\t" +//eax:state ebx:low, edx:range, esi:RangeLPS + "subl %%ecx, %%ebx \n\t" + "movl %%esi, %%edx \n\t" + "movzbl " MANGLE(ff_h264_norm_shift) "(%%esi), %%ecx \n\t" + "shll %%cl, %%ebx \n\t" + "shll %%cl, %%edx \n\t" + "movzbl "MANGLE(ff_h264_lps_state)"(%0), %%ecx \n\t" + "movb %%cl, (%1) \n\t" + "add $1, %0 \n\t" + "test %%bx, %%bx \n\t" + " jnz 2f \n\t" + + "mov "BYTE "(%2), %%"REG_c" \n\t" + "movzwl (%%"REG_c"), %%esi \n\t" + "bswap %%esi \n\t" + "shrl $15, %%esi \n\t" + "subl $0xFFFF, %%esi \n\t" + "add $2, %%"REG_c" \n\t" + "mov %%"REG_c", "BYTE "(%2) \n\t" + [... truncated: 6568 lines follow ...] From dlmcpaul at mail.berlios.de Mon Sep 15 16:02:57 2008 From: dlmcpaul at mail.berlios.de (dlmcpaul at BerliOS) Date: Mon, 15 Sep 2008 16:02:57 +0200 Subject: [Haiku-commits] r27545 - haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec Message-ID: <200809151402.m8FE2vrQ000057@sheep.berlios.de> Author: dlmcpaul Date: 2008-09-15 16:02:50 +0200 (Mon, 15 Sep 2008) New Revision: 27545 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27545&view=rev Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/dca.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/dca.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/dca_parser.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/dcadata.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/dcahuff.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/dct-test.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/dirac_parser.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/dnxhddata.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/dnxhddata.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/dnxhddec.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/dnxhdenc.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/dsicinav.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/dump_extradata_bsf.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/dvbsub.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/dvbsub_parser.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/dvbsubdec.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/dvdsub_parser.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/dvdsubdec.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/dvdsubenc.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/dxa.c Modified: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/dpcm.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/dsputil.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/dsputil.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/dv.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/dvdata.h Log: Update avcodec to 20080825 (sorry for the spam, needed to break this up) Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/dca.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/dca.c 2008-09-15 14:02:19 UTC (rev 27544) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/dca.c 2008-09-15 14:02:50 UTC (rev 27545) @@ -0,0 +1,1269 @@ +/* + * DCA compatible decoder + * Copyright (C) 2004 Gildas Bazin + * Copyright (C) 2004 Benjamin Zores + * Copyright (C) 2006 Benjamin Larsson + * Copyright (C) 2007 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file dca.c + */ + +#include +#include +#include + +#include "avcodec.h" +#include "dsputil.h" +#include "bitstream.h" +#include "dcadata.h" +#include "dcahuff.h" +#include "dca.h" + +//#define TRACE + +#define DCA_PRIM_CHANNELS_MAX (5) +#define DCA_SUBBANDS (32) +#define DCA_ABITS_MAX (32) /* Should be 28 */ +#define DCA_SUBSUBFAMES_MAX (4) +#define DCA_LFE_MAX (3) + +enum DCAMode { + DCA_MONO = 0, + DCA_CHANNEL, + DCA_STEREO, + DCA_STEREO_SUMDIFF, + DCA_STEREO_TOTAL, + DCA_3F, + DCA_2F1R, + DCA_3F1R, + DCA_2F2R, + DCA_3F2R, + DCA_4F2R +}; + +#define DCA_DOLBY 101 /* FIXME */ + +#define DCA_CHANNEL_BITS 6 +#define DCA_CHANNEL_MASK 0x3F + +#define DCA_LFE 0x80 + +#define HEADER_SIZE 14 +#define CONVERT_BIAS 384 + +#define DCA_MAX_FRAME_SIZE 16384 + +/** Bit allocation */ +typedef struct { + int offset; ///< code values offset + int maxbits[8]; ///< max bits in VLC + int wrap; ///< wrap for get_vlc2() + VLC vlc[8]; ///< actual codes +} BitAlloc; + +static BitAlloc dca_bitalloc_index; ///< indexes for samples VLC select +static BitAlloc dca_tmode; ///< transition mode VLCs +static BitAlloc dca_scalefactor; ///< scalefactor VLCs +static BitAlloc dca_smpl_bitalloc[11]; ///< samples VLCs + +/** Pre-calculated cosine modulation coefs for the QMF */ +static float cos_mod[544]; + +static av_always_inline int get_bitalloc(GetBitContext *gb, BitAlloc *ba, int idx) +{ + return get_vlc2(gb, ba->vlc[idx].table, ba->vlc[idx].bits, ba->wrap) + ba->offset; +} + +typedef struct { + AVCodecContext *avctx; + /* Frame header */ + int frame_type; ///< type of the current frame + int samples_deficit; ///< deficit sample count + int crc_present; ///< crc is present in the bitstream + int sample_blocks; ///< number of PCM sample blocks + int frame_size; ///< primary frame byte size + int amode; ///< audio channels arrangement + int sample_rate; ///< audio sampling rate + int bit_rate; ///< transmission bit rate + + int downmix; ///< embedded downmix enabled + int dynrange; ///< embedded dynamic range flag + int timestamp; ///< embedded time stamp flag + int aux_data; ///< auxiliary data flag + int hdcd; ///< source material is mastered in HDCD + int ext_descr; ///< extension audio descriptor flag + int ext_coding; ///< extended coding flag + int aspf; ///< audio sync word insertion flag + int lfe; ///< low frequency effects flag + int predictor_history; ///< predictor history flag + int header_crc; ///< header crc check bytes + int multirate_inter; ///< multirate interpolator switch + int version; ///< encoder software revision + int copy_history; ///< copy history + int source_pcm_res; ///< source pcm resolution + int front_sum; ///< front sum/difference flag + int surround_sum; ///< surround sum/difference flag + int dialog_norm; ///< dialog normalisation parameter + + /* Primary audio coding header */ + int subframes; ///< number of subframes + int total_channels; ///< number of channels including extensions + int prim_channels; ///< number of primary audio channels + int subband_activity[DCA_PRIM_CHANNELS_MAX]; ///< subband activity count + int vq_start_subband[DCA_PRIM_CHANNELS_MAX]; ///< high frequency vq start subband + int joint_intensity[DCA_PRIM_CHANNELS_MAX]; ///< joint intensity coding index + int transient_huffman[DCA_PRIM_CHANNELS_MAX]; ///< transient mode code book + int scalefactor_huffman[DCA_PRIM_CHANNELS_MAX]; ///< scale factor code book + int bitalloc_huffman[DCA_PRIM_CHANNELS_MAX]; ///< bit allocation quantizer select + int quant_index_huffman[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX]; ///< quantization index codebook select + float scalefactor_adj[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX]; ///< scale factor adjustment + + /* Primary audio coding side information */ + int subsubframes; ///< number of subsubframes + int partial_samples; ///< partial subsubframe samples count + int prediction_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< prediction mode (ADPCM used or not) + int prediction_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< prediction VQ coefs + int bitalloc[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< bit allocation index + int transition_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< transition mode (transients) + int scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][2]; ///< scale factors (2 if transient) + int joint_huff[DCA_PRIM_CHANNELS_MAX]; ///< joint subband scale factors codebook + int joint_scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< joint subband scale factors + int downmix_coef[DCA_PRIM_CHANNELS_MAX][2]; ///< stereo downmix coefficients + int dynrange_coef; ///< dynamic range coefficient + + int high_freq_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< VQ encoded high frequency subbands + + float lfe_data[2 * DCA_SUBSUBFAMES_MAX * DCA_LFE_MAX * + 2 /*history */ ]; ///< Low frequency effect data + int lfe_scale_factor; + + /* Subband samples history (for ADPCM) */ + float subband_samples_hist[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][4]; + float subband_fir_hist[DCA_PRIM_CHANNELS_MAX][512]; + float subband_fir_noidea[DCA_PRIM_CHANNELS_MAX][64]; + + int output; ///< type of output + int bias; ///< output bias + + DECLARE_ALIGNED_16(float, samples[1536]); /* 6 * 256 = 1536, might only need 5 */ + DECLARE_ALIGNED_16(int16_t, tsamples[1536]); + + uint8_t dca_buffer[DCA_MAX_FRAME_SIZE]; + int dca_buffer_size; ///< how much data is in the dca_buffer + + GetBitContext gb; + /* Current position in DCA frame */ + int current_subframe; + int current_subsubframe; + + int debug_flag; ///< used for suppressing repeated error messages output + DSPContext dsp; +} DCAContext; + +static av_cold void dca_init_vlcs(void) +{ + static int vlcs_initialized = 0; + int i, j; + + if (vlcs_initialized) + return; + + dca_bitalloc_index.offset = 1; + dca_bitalloc_index.wrap = 2; + for (i = 0; i < 5; i++) + init_vlc(&dca_bitalloc_index.vlc[i], bitalloc_12_vlc_bits[i], 12, + bitalloc_12_bits[i], 1, 1, + bitalloc_12_codes[i], 2, 2, 1); + dca_scalefactor.offset = -64; + dca_scalefactor.wrap = 2; + for (i = 0; i < 5; i++) + init_vlc(&dca_scalefactor.vlc[i], SCALES_VLC_BITS, 129, + scales_bits[i], 1, 1, + scales_codes[i], 2, 2, 1); + dca_tmode.offset = 0; + dca_tmode.wrap = 1; + for (i = 0; i < 4; i++) + init_vlc(&dca_tmode.vlc[i], tmode_vlc_bits[i], 4, + tmode_bits[i], 1, 1, + tmode_codes[i], 2, 2, 1); + + for(i = 0; i < 10; i++) + for(j = 0; j < 7; j++){ + if(!bitalloc_codes[i][j]) break; + dca_smpl_bitalloc[i+1].offset = bitalloc_offsets[i]; + dca_smpl_bitalloc[i+1].wrap = 1 + (j > 4); + init_vlc(&dca_smpl_bitalloc[i+1].vlc[j], bitalloc_maxbits[i][j], + bitalloc_sizes[i], + bitalloc_bits[i][j], 1, 1, + bitalloc_codes[i][j], 2, 2, 1); + } + vlcs_initialized = 1; +} + +static inline void get_array(GetBitContext *gb, int *dst, int len, int bits) +{ + while(len--) + *dst++ = get_bits(gb, bits); +} + +static int dca_parse_frame_header(DCAContext * s) +{ + int i, j; + static const float adj_table[4] = { 1.0, 1.1250, 1.2500, 1.4375 }; + static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 }; + static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 }; + + s->bias = CONVERT_BIAS; + + init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8); + + /* Sync code */ + get_bits(&s->gb, 32); + + /* Frame header */ + s->frame_type = get_bits(&s->gb, 1); + s->samples_deficit = get_bits(&s->gb, 5) + 1; + s->crc_present = get_bits(&s->gb, 1); + s->sample_blocks = get_bits(&s->gb, 7) + 1; + s->frame_size = get_bits(&s->gb, 14) + 1; + if (s->frame_size < 95) + return -1; + s->amode = get_bits(&s->gb, 6); + s->sample_rate = dca_sample_rates[get_bits(&s->gb, 4)]; + if (!s->sample_rate) + return -1; + s->bit_rate = dca_bit_rates[get_bits(&s->gb, 5)]; + if (!s->bit_rate) + return -1; + + s->downmix = get_bits(&s->gb, 1); + s->dynrange = get_bits(&s->gb, 1); + s->timestamp = get_bits(&s->gb, 1); + s->aux_data = get_bits(&s->gb, 1); + s->hdcd = get_bits(&s->gb, 1); + s->ext_descr = get_bits(&s->gb, 3); + s->ext_coding = get_bits(&s->gb, 1); + s->aspf = get_bits(&s->gb, 1); + s->lfe = get_bits(&s->gb, 2); + s->predictor_history = get_bits(&s->gb, 1); + + /* TODO: check CRC */ + if (s->crc_present) + s->header_crc = get_bits(&s->gb, 16); + + s->multirate_inter = get_bits(&s->gb, 1); + s->version = get_bits(&s->gb, 4); + s->copy_history = get_bits(&s->gb, 2); + s->source_pcm_res = get_bits(&s->gb, 3); + s->front_sum = get_bits(&s->gb, 1); + s->surround_sum = get_bits(&s->gb, 1); + s->dialog_norm = get_bits(&s->gb, 4); + + /* FIXME: channels mixing levels */ + s->output = s->amode; + if(s->lfe) s->output |= DCA_LFE; + +#ifdef TRACE + av_log(s->avctx, AV_LOG_DEBUG, "frame type: %i\n", s->frame_type); + av_log(s->avctx, AV_LOG_DEBUG, "samples deficit: %i\n", s->samples_deficit); + av_log(s->avctx, AV_LOG_DEBUG, "crc present: %i\n", s->crc_present); + av_log(s->avctx, AV_LOG_DEBUG, "sample blocks: %i (%i samples)\n", + s->sample_blocks, s->sample_blocks * 32); + av_log(s->avctx, AV_LOG_DEBUG, "frame size: %i bytes\n", s->frame_size); + av_log(s->avctx, AV_LOG_DEBUG, "amode: %i (%i channels)\n", + s->amode, dca_channels[s->amode]); + av_log(s->avctx, AV_LOG_DEBUG, "sample rate: %i (%i Hz)\n", + s->sample_rate, dca_sample_rates[s->sample_rate]); + av_log(s->avctx, AV_LOG_DEBUG, "bit rate: %i (%i bits/s)\n", + s->bit_rate, dca_bit_rates[s->bit_rate]); + av_log(s->avctx, AV_LOG_DEBUG, "downmix: %i\n", s->downmix); + av_log(s->avctx, AV_LOG_DEBUG, "dynrange: %i\n", s->dynrange); + av_log(s->avctx, AV_LOG_DEBUG, "timestamp: %i\n", s->timestamp); + av_log(s->avctx, AV_LOG_DEBUG, "aux_data: %i\n", s->aux_data); + av_log(s->avctx, AV_LOG_DEBUG, "hdcd: %i\n", s->hdcd); + av_log(s->avctx, AV_LOG_DEBUG, "ext descr: %i\n", s->ext_descr); + av_log(s->avctx, AV_LOG_DEBUG, "ext coding: %i\n", s->ext_coding); + av_log(s->avctx, AV_LOG_DEBUG, "aspf: %i\n", s->aspf); + av_log(s->avctx, AV_LOG_DEBUG, "lfe: %i\n", s->lfe); + av_log(s->avctx, AV_LOG_DEBUG, "predictor history: %i\n", + s->predictor_history); + av_log(s->avctx, AV_LOG_DEBUG, "header crc: %i\n", s->header_crc); + av_log(s->avctx, AV_LOG_DEBUG, "multirate inter: %i\n", + s->multirate_inter); + av_log(s->avctx, AV_LOG_DEBUG, "version number: %i\n", s->version); + av_log(s->avctx, AV_LOG_DEBUG, "copy history: %i\n", s->copy_history); + av_log(s->avctx, AV_LOG_DEBUG, + "source pcm resolution: %i (%i bits/sample)\n", + s->source_pcm_res, dca_bits_per_sample[s->source_pcm_res]); + av_log(s->avctx, AV_LOG_DEBUG, "front sum: %i\n", s->front_sum); + av_log(s->avctx, AV_LOG_DEBUG, "surround sum: %i\n", s->surround_sum); + av_log(s->avctx, AV_LOG_DEBUG, "dialog norm: %i\n", s->dialog_norm); + av_log(s->avctx, AV_LOG_DEBUG, "\n"); +#endif + + /* Primary audio coding header */ + s->subframes = get_bits(&s->gb, 4) + 1; + s->total_channels = get_bits(&s->gb, 3) + 1; + s->prim_channels = s->total_channels; + if (s->prim_channels > DCA_PRIM_CHANNELS_MAX) + s->prim_channels = DCA_PRIM_CHANNELS_MAX; /* We only support DTS core */ + + + for (i = 0; i < s->prim_channels; i++) { + s->subband_activity[i] = get_bits(&s->gb, 5) + 2; + if (s->subband_activity[i] > DCA_SUBBANDS) + s->subband_activity[i] = DCA_SUBBANDS; + } + for (i = 0; i < s->prim_channels; i++) { + s->vq_start_subband[i] = get_bits(&s->gb, 5) + 1; + if (s->vq_start_subband[i] > DCA_SUBBANDS) + s->vq_start_subband[i] = DCA_SUBBANDS; + } + get_array(&s->gb, s->joint_intensity, s->prim_channels, 3); + get_array(&s->gb, s->transient_huffman, s->prim_channels, 2); + get_array(&s->gb, s->scalefactor_huffman, s->prim_channels, 3); + get_array(&s->gb, s->bitalloc_huffman, s->prim_channels, 3); + + /* Get codebooks quantization indexes */ + memset(s->quant_index_huffman, 0, sizeof(s->quant_index_huffman)); + for (j = 1; j < 11; j++) + for (i = 0; i < s->prim_channels; i++) + s->quant_index_huffman[i][j] = get_bits(&s->gb, bitlen[j]); + + /* Get scale factor adjustment */ + for (j = 0; j < 11; j++) + for (i = 0; i < s->prim_channels; i++) + s->scalefactor_adj[i][j] = 1; + + for (j = 1; j < 11; j++) + for (i = 0; i < s->prim_channels; i++) + if (s->quant_index_huffman[i][j] < thr[j]) + s->scalefactor_adj[i][j] = adj_table[get_bits(&s->gb, 2)]; + + if (s->crc_present) { + /* Audio header CRC check */ + get_bits(&s->gb, 16); + } + + s->current_subframe = 0; + s->current_subsubframe = 0; + +#ifdef TRACE + av_log(s->avctx, AV_LOG_DEBUG, "subframes: %i\n", s->subframes); + av_log(s->avctx, AV_LOG_DEBUG, "prim channels: %i\n", s->prim_channels); + for(i = 0; i < s->prim_channels; i++){ + av_log(s->avctx, AV_LOG_DEBUG, "subband activity: %i\n", s->subband_activity[i]); + av_log(s->avctx, AV_LOG_DEBUG, "vq start subband: %i\n", s->vq_start_subband[i]); + av_log(s->avctx, AV_LOG_DEBUG, "joint intensity: %i\n", s->joint_intensity[i]); + av_log(s->avctx, AV_LOG_DEBUG, "transient mode codebook: %i\n", s->transient_huffman[i]); + av_log(s->avctx, AV_LOG_DEBUG, "scale factor codebook: %i\n", s->scalefactor_huffman[i]); + av_log(s->avctx, AV_LOG_DEBUG, "bit allocation quantizer: %i\n", s->bitalloc_huffman[i]); + av_log(s->avctx, AV_LOG_DEBUG, "quant index huff:"); + for (j = 0; j < 11; j++) + av_log(s->avctx, AV_LOG_DEBUG, " %i", + s->quant_index_huffman[i][j]); + av_log(s->avctx, AV_LOG_DEBUG, "\n"); + av_log(s->avctx, AV_LOG_DEBUG, "scalefac adj:"); + for (j = 0; j < 11; j++) + av_log(s->avctx, AV_LOG_DEBUG, " %1.3f", s->scalefactor_adj[i][j]); + av_log(s->avctx, AV_LOG_DEBUG, "\n"); + } +#endif + + return 0; +} + + +static inline int get_scale(GetBitContext *gb, int level, int value) +{ + if (level < 5) { + /* huffman encoded */ + value += get_bitalloc(gb, &dca_scalefactor, level); + } else if(level < 8) + value = get_bits(gb, level + 1); + return value; +} + +static int dca_subframe_header(DCAContext * s) +{ + /* Primary audio coding side information */ + int j, k; + + s->subsubframes = get_bits(&s->gb, 2) + 1; + s->partial_samples = get_bits(&s->gb, 3); + for (j = 0; j < s->prim_channels; j++) { + for (k = 0; k < s->subband_activity[j]; k++) + s->prediction_mode[j][k] = get_bits(&s->gb, 1); + } + + /* Get prediction codebook */ + for (j = 0; j < s->prim_channels; j++) { + for (k = 0; k < s->subband_activity[j]; k++) { + if (s->prediction_mode[j][k] > 0) { + /* (Prediction coefficient VQ address) */ + s->prediction_vq[j][k] = get_bits(&s->gb, 12); + } + } + } + + /* Bit allocation index */ + for (j = 0; j < s->prim_channels; j++) { + for (k = 0; k < s->vq_start_subband[j]; k++) { + if (s->bitalloc_huffman[j] == 6) + s->bitalloc[j][k] = get_bits(&s->gb, 5); + else if (s->bitalloc_huffman[j] == 5) + s->bitalloc[j][k] = get_bits(&s->gb, 4); + else if (s->bitalloc_huffman[j] == 7) { + av_log(s->avctx, AV_LOG_ERROR, + "Invalid bit allocation index\n"); + return -1; + } else { + s->bitalloc[j][k] = + get_bitalloc(&s->gb, &dca_bitalloc_index, s->bitalloc_huffman[j]); + } + + if (s->bitalloc[j][k] > 26) { +// av_log(s->avctx,AV_LOG_DEBUG,"bitalloc index [%i][%i] too big (%i)\n", +// j, k, s->bitalloc[j][k]); + return -1; + } + } + } + + /* Transition mode */ + for (j = 0; j < s->prim_channels; j++) { + for (k = 0; k < s->subband_activity[j]; k++) { + s->transition_mode[j][k] = 0; + if (s->subsubframes > 1 && + k < s->vq_start_subband[j] && s->bitalloc[j][k] > 0) { + s->transition_mode[j][k] = + get_bitalloc(&s->gb, &dca_tmode, s->transient_huffman[j]); + } + } + } + + for (j = 0; j < s->prim_channels; j++) { + const uint32_t *scale_table; + int scale_sum; + + memset(s->scale_factor[j], 0, s->subband_activity[j] * sizeof(s->scale_factor[0][0][0]) * 2); + + if (s->scalefactor_huffman[j] == 6) + scale_table = scale_factor_quant7; + else + scale_table = scale_factor_quant6; + + /* When huffman coded, only the difference is encoded */ + scale_sum = 0; + + for (k = 0; k < s->subband_activity[j]; k++) { + if (k >= s->vq_start_subband[j] || s->bitalloc[j][k] > 0) { + scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum); + s->scale_factor[j][k][0] = scale_table[scale_sum]; + } + + if (k < s->vq_start_subband[j] && s->transition_mode[j][k]) { + /* Get second scale factor */ + scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum); + s->scale_factor[j][k][1] = scale_table[scale_sum]; + } + } + } + + /* Joint subband scale factor codebook select */ + for (j = 0; j < s->prim_channels; j++) { + /* Transmitted only if joint subband coding enabled */ + if (s->joint_intensity[j] > 0) + s->joint_huff[j] = get_bits(&s->gb, 3); + } + + /* Scale factors for joint subband coding */ + for (j = 0; j < s->prim_channels; j++) { + int source_channel; + + /* Transmitted only if joint subband coding enabled */ + if (s->joint_intensity[j] > 0) { + int scale = 0; + source_channel = s->joint_intensity[j] - 1; + + /* When huffman coded, only the difference is encoded + * (is this valid as well for joint scales ???) */ + + for (k = s->subband_activity[j]; k < s->subband_activity[source_channel]; k++) { + scale = get_scale(&s->gb, s->joint_huff[j], 0); + scale += 64; /* bias */ + s->joint_scale_factor[j][k] = scale; /*joint_scale_table[scale]; */ + } + + if (!s->debug_flag & 0x02) { + av_log(s->avctx, AV_LOG_DEBUG, + "Joint stereo coding not supported\n"); + s->debug_flag |= 0x02; + } + } + } + + /* Stereo downmix coefficients */ + if (s->prim_channels > 2) { + if(s->downmix) { + for (j = 0; j < s->prim_channels; j++) { + s->downmix_coef[j][0] = get_bits(&s->gb, 7); + s->downmix_coef[j][1] = get_bits(&s->gb, 7); + } + } else { + int am = s->amode & DCA_CHANNEL_MASK; + for (j = 0; j < s->prim_channels; j++) { + s->downmix_coef[j][0] = dca_default_coeffs[am][j][0]; + s->downmix_coef[j][1] = dca_default_coeffs[am][j][1]; + } + } + } + + /* Dynamic range coefficient */ + if (s->dynrange) + s->dynrange_coef = get_bits(&s->gb, 8); + + /* Side information CRC check word */ + if (s->crc_present) { + get_bits(&s->gb, 16); + } + + /* + * Primary audio data arrays + */ + + /* VQ encoded high frequency subbands */ + for (j = 0; j < s->prim_channels; j++) + for (k = s->vq_start_subband[j]; k < s->subband_activity[j]; k++) + /* 1 vector -> 32 samples */ + s->high_freq_vq[j][k] = get_bits(&s->gb, 10); + + /* Low frequency effect data */ + if (s->lfe) { + /* LFE samples */ + int lfe_samples = 2 * s->lfe * s->subsubframes; + float lfe_scale; + + for (j = lfe_samples; j < lfe_samples * 2; j++) { + /* Signed 8 bits int */ + s->lfe_data[j] = get_sbits(&s->gb, 8); + } + + /* Scale factor index */ + s->lfe_scale_factor = scale_factor_quant7[get_bits(&s->gb, 8)]; + + /* Quantization step size * scale factor */ + lfe_scale = 0.035 * s->lfe_scale_factor; + + for (j = lfe_samples; j < lfe_samples * 2; j++) + s->lfe_data[j] *= lfe_scale; + } + +#ifdef TRACE + av_log(s->avctx, AV_LOG_DEBUG, "subsubframes: %i\n", s->subsubframes); + av_log(s->avctx, AV_LOG_DEBUG, "partial samples: %i\n", + s->partial_samples); + for (j = 0; j < s->prim_channels; j++) { + av_log(s->avctx, AV_LOG_DEBUG, "prediction mode:"); + for (k = 0; k < s->subband_activity[j]; k++) + av_log(s->avctx, AV_LOG_DEBUG, " %i", s->prediction_mode[j][k]); + av_log(s->avctx, AV_LOG_DEBUG, "\n"); + } + for (j = 0; j < s->prim_channels; j++) { + for (k = 0; k < s->subband_activity[j]; k++) + av_log(s->avctx, AV_LOG_DEBUG, + "prediction coefs: %f, %f, %f, %f\n", + (float) adpcm_vb[s->prediction_vq[j][k]][0] / 8192, + (float) adpcm_vb[s->prediction_vq[j][k]][1] / 8192, + (float) adpcm_vb[s->prediction_vq[j][k]][2] / 8192, + (float) adpcm_vb[s->prediction_vq[j][k]][3] / 8192); + } + for (j = 0; j < s->prim_channels; j++) { + av_log(s->avctx, AV_LOG_DEBUG, "bitalloc index: "); + for (k = 0; k < s->vq_start_subband[j]; k++) + av_log(s->avctx, AV_LOG_DEBUG, "%2.2i ", s->bitalloc[j][k]); + av_log(s->avctx, AV_LOG_DEBUG, "\n"); + } + for (j = 0; j < s->prim_channels; j++) { + av_log(s->avctx, AV_LOG_DEBUG, "Transition mode:"); + for (k = 0; k < s->subband_activity[j]; k++) + av_log(s->avctx, AV_LOG_DEBUG, " %i", s->transition_mode[j][k]); + av_log(s->avctx, AV_LOG_DEBUG, "\n"); + } + for (j = 0; j < s->prim_channels; j++) { + av_log(s->avctx, AV_LOG_DEBUG, "Scale factor:"); + for (k = 0; k < s->subband_activity[j]; k++) { + if (k >= s->vq_start_subband[j] || s->bitalloc[j][k] > 0) + av_log(s->avctx, AV_LOG_DEBUG, " %i", s->scale_factor[j][k][0]); + if (k < s->vq_start_subband[j] && s->transition_mode[j][k]) + av_log(s->avctx, AV_LOG_DEBUG, " %i(t)", s->scale_factor[j][k][1]); + } + av_log(s->avctx, AV_LOG_DEBUG, "\n"); + } + for (j = 0; j < s->prim_channels; j++) { + if (s->joint_intensity[j] > 0) { + int source_channel = s->joint_intensity[j] - 1; + av_log(s->avctx, AV_LOG_DEBUG, "Joint scale factor index:\n"); + for (k = s->subband_activity[j]; k < s->subband_activity[source_channel]; k++) + av_log(s->avctx, AV_LOG_DEBUG, " %i", s->joint_scale_factor[j][k]); + av_log(s->avctx, AV_LOG_DEBUG, "\n"); + } + } + if (s->prim_channels > 2 && s->downmix) { + av_log(s->avctx, AV_LOG_DEBUG, "Downmix coeffs:\n"); + for (j = 0; j < s->prim_channels; j++) { + av_log(s->avctx, AV_LOG_DEBUG, "Channel 0,%d = %f\n", j, dca_downmix_coeffs[s->downmix_coef[j][0]]); + av_log(s->avctx, AV_LOG_DEBUG, "Channel 1,%d = %f\n", j, dca_downmix_coeffs[s->downmix_coef[j][1]]); + } + av_log(s->avctx, AV_LOG_DEBUG, "\n"); + } + for (j = 0; j < s->prim_channels; j++) + for (k = s->vq_start_subband[j]; k < s->subband_activity[j]; k++) + av_log(s->avctx, AV_LOG_DEBUG, "VQ index: %i\n", s->high_freq_vq[j][k]); + if(s->lfe){ + int lfe_samples = 2 * s->lfe * s->subsubframes; + av_log(s->avctx, AV_LOG_DEBUG, "LFE samples:\n"); + for (j = lfe_samples; j < lfe_samples * 2; j++) + av_log(s->avctx, AV_LOG_DEBUG, " %f", s->lfe_data[j]); + av_log(s->avctx, AV_LOG_DEBUG, "\n"); + } +#endif + + return 0; +} + +static void qmf_32_subbands(DCAContext * s, int chans, + float samples_in[32][8], float *samples_out, + float scale, float bias) +{ + const float *prCoeff; + int i, j, k; + float praXin[33], *raXin = &praXin[1]; + + float *subband_fir_hist = s->subband_fir_hist[chans]; + float *subband_fir_hist2 = s->subband_fir_noidea[chans]; + + int chindex = 0, subindex; + + praXin[0] = 0.0; + + /* Select filter */ + if (!s->multirate_inter) /* Non-perfect reconstruction */ + prCoeff = fir_32bands_nonperfect; + else /* Perfect reconstruction */ + prCoeff = fir_32bands_perfect; + + /* Reconstructed channel sample index */ + for (subindex = 0; subindex < 8; subindex++) { + float t1, t2, sum[16], diff[16]; + + /* Load in one sample from each subband and clear inactive subbands */ + for (i = 0; i < s->subband_activity[chans]; i++) + raXin[i] = samples_in[i][subindex]; + for (; i < 32; i++) + raXin[i] = 0.0; + + /* Multiply by cosine modulation coefficients and + * create temporary arrays SUM and DIFF */ + for (j = 0, k = 0; k < 16; k++) { + t1 = 0.0; + t2 = 0.0; + for (i = 0; i < 16; i++, j++){ + t1 += (raXin[2 * i] + raXin[2 * i + 1]) * cos_mod[j]; + t2 += (raXin[2 * i] + raXin[2 * i - 1]) * cos_mod[j + 256]; + } + sum[k] = t1 + t2; + diff[k] = t1 - t2; + } + + j = 512; + /* Store history */ + for (k = 0; k < 16; k++) + subband_fir_hist[k] = cos_mod[j++] * sum[k]; + for (k = 0; k < 16; k++) + subband_fir_hist[32-k-1] = cos_mod[j++] * diff[k]; + + /* Multiply by filter coefficients */ + for (k = 31, i = 0; i < 32; i++, k--) + for (j = 0; j < 512; j += 64){ + subband_fir_hist2[i] += prCoeff[i+j] * ( subband_fir_hist[i+j] - subband_fir_hist[j+k]); + subband_fir_hist2[i+32] += prCoeff[i+j+32]*(-subband_fir_hist[i+j] - subband_fir_hist[j+k]); + } + + /* Create 32 PCM output samples */ + for (i = 0; i < 32; i++) + samples_out[chindex++] = subband_fir_hist2[i] * scale + bias; + + /* Update working arrays */ + memmove(&subband_fir_hist[32], &subband_fir_hist[0], (512 - 32) * sizeof(float)); + memmove(&subband_fir_hist2[0], &subband_fir_hist2[32], 32 * sizeof(float)); + memset(&subband_fir_hist2[32], 0, 32 * sizeof(float)); + } +} + +static void lfe_interpolation_fir(int decimation_select, + int num_deci_sample, float *samples_in, + float *samples_out, float scale, + float bias) +{ + /* samples_in: An array holding decimated samples. + * Samples in current subframe starts from samples_in[0], + * while samples_in[-1], samples_in[-2], ..., stores samples + * from last subframe as history. + * + * samples_out: An array holding interpolated samples + */ + + int decifactor, k, j; + const float *prCoeff; + + int interp_index = 0; /* Index to the interpolated samples */ + int deciindex; + + /* Select decimation filter */ + if (decimation_select == 1) { + decifactor = 128; + prCoeff = lfe_fir_128; + } else { + decifactor = 64; + prCoeff = lfe_fir_64; + } + /* Interpolation */ + for (deciindex = 0; deciindex < num_deci_sample; deciindex++) { + /* One decimated sample generates decifactor interpolated ones */ + for (k = 0; k < decifactor; k++) { + float rTmp = 0.0; + //FIXME the coeffs are symetric, fix that + for (j = 0; j < 512 / decifactor; j++) + rTmp += samples_in[deciindex - j] * prCoeff[k + j * decifactor]; + samples_out[interp_index++] = rTmp / scale + bias; + } + } +} + +/* downmixing routines */ +#define MIX_REAR1(samples, si1, rs, coef) \ + samples[i] += samples[si1] * coef[rs][0]; \ + samples[i+256] += samples[si1] * coef[rs][1]; + +#define MIX_REAR2(samples, si1, si2, rs, coef) \ + samples[i] += samples[si1] * coef[rs][0] + samples[si2] * coef[rs+1][0]; \ + samples[i+256] += samples[si1] * coef[rs][1] + samples[si2] * coef[rs+1][1]; + +#define MIX_FRONT3(samples, coef) \ + t = samples[i]; \ + samples[i] = t * coef[0][0] + samples[i+256] * coef[1][0] + samples[i+512] * coef[2][0]; \ + samples[i+256] = t * coef[0][1] + samples[i+256] * coef[1][1] + samples[i+512] * coef[2][1]; + +#define DOWNMIX_TO_STEREO(op1, op2) \ + for(i = 0; i < 256; i++){ \ + op1 \ + op2 \ + } + +static void dca_downmix(float *samples, int srcfmt, + int downmix_coef[DCA_PRIM_CHANNELS_MAX][2]) +{ + int i; + float t; + float coef[DCA_PRIM_CHANNELS_MAX][2]; + + for(i=0; i> 1; + + for (i = 0; i < 4; i++) { + values[i] = (code % levels) - offset; + code /= levels; + } + + if (code == 0) + return 0; + else { + av_log(NULL, AV_LOG_ERROR, "ERROR: block code look-up failed\n"); + return -1; + } +} + +static const uint8_t abits_sizes[7] = { 7, 10, 12, 13, 15, 17, 19 }; +static const uint8_t abits_levels[7] = { 3, 5, 7, 9, 13, 17, 25 }; + +static int dca_subsubframe(DCAContext * s) +{ + int k, l; + int subsubframe = s->current_subsubframe; + + const float *quant_step_table; + + /* FIXME */ + float subband_samples[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][8]; + + /* + * Audio data + */ + + /* Select quantization step size table */ + if (s->bit_rate == 0x1f) + quant_step_table = lossless_quant_d; + else + quant_step_table = lossy_quant_d; + + for (k = 0; k < s->prim_channels; k++) { + for (l = 0; l < s->vq_start_subband[k]; l++) { + int m; + + /* Select the mid-tread linear quantizer */ + int abits = s->bitalloc[k][l]; + + float quant_step_size = quant_step_table[abits]; + float rscale; + + /* + * Determine quantization index code book and its type + */ + + /* Select quantization index code book */ + int sel = s->quant_index_huffman[k][abits]; + + /* + * Extract bits from the bit stream + */ + if(!abits){ + memset(subband_samples[k][l], 0, 8 * sizeof(subband_samples[0][0][0])); + }else if(abits >= 11 || !dca_smpl_bitalloc[abits].vlc[sel].table){ + if(abits <= 7){ + /* Block code */ + int block_code1, block_code2, size, levels; + int block[8]; + + size = abits_sizes[abits-1]; + levels = abits_levels[abits-1]; + + block_code1 = get_bits(&s->gb, size); + /* FIXME Should test return value */ + decode_blockcode(block_code1, levels, block); + block_code2 = get_bits(&s->gb, size); + decode_blockcode(block_code2, levels, &block[4]); + for (m = 0; m < 8; m++) + subband_samples[k][l][m] = block[m]; + }else{ + /* no coding */ + for (m = 0; m < 8; m++) + subband_samples[k][l][m] = get_sbits(&s->gb, abits - 3); + } + }else{ + /* Huffman coded */ + for (m = 0; m < 8; m++) + subband_samples[k][l][m] = get_bitalloc(&s->gb, &dca_smpl_bitalloc[abits], sel); + } + + /* Deal with transients */ + if (s->transition_mode[k][l] && + subsubframe >= s->transition_mode[k][l]) + rscale = quant_step_size * s->scale_factor[k][l][1]; + else + rscale = quant_step_size * s->scale_factor[k][l][0]; + + rscale *= s->scalefactor_adj[k][sel]; + + for (m = 0; m < 8; m++) + subband_samples[k][l][m] *= rscale; + + /* + * Inverse ADPCM if in prediction mode + */ + if (s->prediction_mode[k][l]) { + int n; + for (m = 0; m < 8; m++) { + for (n = 1; n <= 4; n++) + if (m >= n) + subband_samples[k][l][m] += + (adpcm_vb[s->prediction_vq[k][l]][n - 1] * + subband_samples[k][l][m - n] / 8192); + else if (s->predictor_history) + subband_samples[k][l][m] += + (adpcm_vb[s->prediction_vq[k][l]][n - 1] * + s->subband_samples_hist[k][l][m - n + + 4] / 8192); + } + } + } + + /* + * Decode VQ encoded high frequencies + */ + for (l = s->vq_start_subband[k]; l < s->subband_activity[k]; l++) { + /* 1 vector -> 32 samples but we only need the 8 samples + * for this subsubframe. */ + int m; + + if (!s->debug_flag & 0x01) { + av_log(s->avctx, AV_LOG_DEBUG, "Stream with high frequencies VQ coding\n"); + s->debug_flag |= 0x01; + } + + for (m = 0; m < 8; m++) { + subband_samples[k][l][m] = + high_freq_vq[s->high_freq_vq[k][l]][subsubframe * 8 + + m] + * (float) s->scale_factor[k][l][0] / 16.0; + } + } + } + + /* Check for DSYNC after subsubframe */ + if (s->aspf || subsubframe == s->subsubframes - 1) { + if (0xFFFF == get_bits(&s->gb, 16)) { /* 0xFFFF */ +#ifdef TRACE + av_log(s->avctx, AV_LOG_DEBUG, "Got subframe DSYNC\n"); +#endif + } else { + av_log(s->avctx, AV_LOG_ERROR, "Didn't get subframe DSYNC\n"); + } + } + + /* Backup predictor history for adpcm */ + for (k = 0; k < s->prim_channels; k++) + for (l = 0; l < s->vq_start_subband[k]; l++) + memcpy(s->subband_samples_hist[k][l], &subband_samples[k][l][4], + 4 * sizeof(subband_samples[0][0][0])); + + /* 32 subbands QMF */ + for (k = 0; k < s->prim_channels; k++) { +/* static float pcm_to_double[8] = + {32768.0, 32768.0, 524288.0, 524288.0, 0, 8388608.0, 8388608.0};*/ + qmf_32_subbands(s, k, subband_samples[k], &s->samples[256 * k], + M_SQRT1_2 /*pcm_to_double[s->source_pcm_res] */ , + 0 /*s->bias */ ); + } [... truncated: 24749 lines follow ...] From dlmcpaul at mail.berlios.de Mon Sep 15 16:03:18 2008 From: dlmcpaul at mail.berlios.de (dlmcpaul at BerliOS) Date: Mon, 15 Sep 2008 16:03:18 +0200 Subject: [Haiku-commits] r27546 - haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec Message-ID: <200809151403.m8FE3IJG000101@sheep.berlios.de> Author: dlmcpaul Date: 2008-09-15 16:03:17 +0200 (Mon, 15 Sep 2008) New Revision: 27546 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27546&view=rev Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/eac3dec.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/eacmv.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/eatgv.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/elbg.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/elbg.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/escape124.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/eval.h Modified: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/error_resilience.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/eval.c Log: Update avcodec to 20080825 Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/eac3dec.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/eac3dec.c 2008-09-15 14:02:50 UTC (rev 27545) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/eac3dec.c 2008-09-15 14:03:17 UTC (rev 27546) @@ -0,0 +1,80 @@ +/* + * E-AC-3 decoder + * Copyright (c) 2007 Bartlomiej Wolowiec + * Copyright (c) 2008 Justin Ruggles + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avcodec.h" +#include "ac3.h" +#include "ac3_parser.h" +#include "ac3dec.h" +#include "ac3dec_data.h" + +/** gain adaptive quantization mode */ +typedef enum { + EAC3_GAQ_NO =0, + EAC3_GAQ_12, + EAC3_GAQ_14, + EAC3_GAQ_124 +} EAC3GaqMode; + +#define EAC3_SR_CODE_REDUCED 3 + +/** lrint(M_SQRT2*cos(2*M_PI/12)*(1<<23)) */ +#define COEFF_0 10273905LL + +/** lrint(M_SQRT2*cos(0*M_PI/12)*(1<<23)) = lrint(M_SQRT2*(1<<23)) */ +#define COEFF_1 11863283LL + +/** lrint(M_SQRT2*cos(5*M_PI/12)*(1<<23)) */ +#define COEFF_2 3070444LL + +/** + * Calculate 6-point IDCT of the pre-mantissas. + * All calculations are 24-bit fixed-point. + */ +static void idct6(int pre_mant[6]) +{ + int tmp; + int even0, even1, even2, odd0, odd1, odd2; + + odd1 = pre_mant[1] - pre_mant[3] - pre_mant[5]; + + even2 = ( pre_mant[2] * COEFF_0) >> 23; + tmp = ( pre_mant[4] * COEFF_1) >> 23; + odd0 = ((pre_mant[1] + pre_mant[5]) * COEFF_2) >> 23; + + even0 = pre_mant[0] + (tmp >> 1); + even1 = pre_mant[0] - tmp; + + tmp = even0; + even0 = tmp + even2; + even2 = tmp - even2; + + tmp = odd0; + odd0 = tmp + pre_mant[1] + pre_mant[3]; + odd2 = tmp + pre_mant[5] - pre_mant[3]; + + pre_mant[0] = even0 + odd0; + pre_mant[1] = even1 + odd1; + pre_mant[2] = even2 + odd2; + pre_mant[3] = even2 - odd2; + pre_mant[4] = even1 - odd1; + pre_mant[5] = even0 - odd0; +} Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/eacmv.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/eacmv.c 2008-09-15 14:02:50 UTC (rev 27545) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/eacmv.c 2008-09-15 14:03:17 UTC (rev 27546) @@ -0,0 +1,214 @@ +/* + * Electronic Arts CMV Video Decoder + * Copyright (c) 2007-2008 Peter Ross + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file eacmv.c + * Electronic Arts CMV Video Decoder + * by Peter Ross (suxen_drol at hotmail dot com) + * + * Technical details here: + * http://wiki.multimedia.cx/index.php?title=Electronic_Arts_CMV + */ + +#include "avcodec.h" + +typedef struct CmvContext { + AVCodecContext *avctx; + AVFrame frame; ///< current + AVFrame last_frame; ///< last + AVFrame last2_frame; ///< second-last + int width, height; + unsigned int palette[AVPALETTE_COUNT]; +} CmvContext; + +static av_cold int cmv_decode_init(AVCodecContext *avctx){ + CmvContext *s = avctx->priv_data; + s->avctx = avctx; + avctx->pix_fmt = PIX_FMT_PAL8; + return 0; +} + +static void cmv_decode_intra(CmvContext * s, const uint8_t *buf, const uint8_t *buf_end){ + unsigned char *dst = s->frame.data[0]; + int i; + + for (i=0; i < s->avctx->height && buf+s->avctx->width<=buf_end; i++) { + memcpy(dst, buf, s->avctx->width); + dst += s->frame.linesize[0]; + buf += s->avctx->width; + } +} + +static void cmv_motcomp(unsigned char *dst, int dst_stride, + const unsigned char *src, int src_stride, + int x, int y, + int xoffset, int yoffset, + int width, int height){ + int i,j; + + for(j=y;j=0 && i+xoffset=0 && j+yoffsetavctx->width*s->avctx->height/16); + int x,y,i; + + i = 0; + for(y=0; yavctx->height/4; y++) + for(x=0; xavctx->width/4 && buf+iframe.data[0] + (y*4)*s->frame.linesize[0] + x*4; + if (raw+16frame.linesize[0], raw+4, 4); + memcpy(dst+2*s->frame.linesize[0], raw+8, 4); + memcpy(dst+3*s->frame.linesize[0], raw+12, 4); + raw+=16; + }else if(raw> 4)) - 7; + cmv_motcomp(s->frame.data[0], s->frame.linesize[0], + s->last2_frame.data[0], s->last2_frame.linesize[0], + x*4, y*4, xoffset, yoffset, s->avctx->width, s->avctx->height); + raw++; + } + }else{ /* inter using last frame as reference */ + int xoffset = (buf[i] & 0xF) - 7; + int yoffset = ((buf[i] >> 4)) - 7; + cmv_motcomp(s->frame.data[0], s->frame.linesize[0], + s->last_frame.data[0], s->last_frame.linesize[0], + x*4, y*4, xoffset, yoffset, s->avctx->width, s->avctx->height); + } + i++; + } +} + +static void cmv_process_header(CmvContext *s, const uint8_t *buf, const uint8_t *buf_end) +{ + int pal_start, pal_count, i; + + if(buf+16>=buf_end) { + av_log(s->avctx, AV_LOG_WARNING, "truncated header\n"); + return; + } + + s->width = AV_RL16(&buf[4]); + s->height = AV_RL16(&buf[6]); + if (s->avctx->width!=s->width || s->avctx->height!=s->height) + avcodec_set_dimensions(s->avctx, s->width, s->height); + + s->avctx->time_base.num = 1; + s->avctx->time_base.den = AV_RL16(&buf[10]); + + pal_start = AV_RL16(&buf[12]); + pal_count = AV_RL16(&buf[14]); + + buf += 16; + for (i=pal_start; ipalette[i] = AV_RB24(buf); + buf += 3; + } +} + +#define EA_PREAMBLE_SIZE 8 +#define MVIh_TAG MKTAG('M', 'V', 'I', 'h') + +static int cmv_decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + const uint8_t *buf, int buf_size) +{ + CmvContext *s = avctx->priv_data; + const uint8_t *buf_end = buf + buf_size; + + if (AV_RL32(buf)==MVIh_TAG||AV_RB32(buf)==MVIh_TAG) { + cmv_process_header(s, buf+EA_PREAMBLE_SIZE, buf_end); + return buf_size; + } + + if (avcodec_check_dimensions(s->avctx, s->width, s->height)) + return -1; + + /* shuffle */ + if (s->last2_frame.data[0]) + avctx->release_buffer(avctx, &s->last2_frame); + FFSWAP(AVFrame, s->last_frame, s->last2_frame); + FFSWAP(AVFrame, s->frame, s->last_frame); + + s->frame.reference = 1; + s->frame.buffer_hints = FF_BUFFER_HINTS_VALID; + if (avctx->get_buffer(avctx, &s->frame)<0) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } + + memcpy(s->frame.data[1], s->palette, AVPALETTE_SIZE); + + buf += EA_PREAMBLE_SIZE; + if ((buf[0]&1)) { // subtype + cmv_decode_inter(s, buf+2, buf_end); + s->frame.key_frame = 0; + s->frame.pict_type = FF_P_TYPE; + }else{ + s->frame.key_frame = 1; + s->frame.pict_type = FF_I_TYPE; + cmv_decode_intra(s, buf+2, buf_end); + } + + *data_size = sizeof(AVFrame); + *(AVFrame*)data = s->frame; + + return buf_size; +} + +static av_cold int cmv_decode_end(AVCodecContext *avctx){ + CmvContext *s = avctx->priv_data; + if (s->frame.data[0]) + s->avctx->release_buffer(avctx, &s->frame); + if (s->last_frame.data[0]) + s->avctx->release_buffer(avctx, &s->last_frame); + if (s->last2_frame.data[0]) + s->avctx->release_buffer(avctx, &s->last2_frame); + + return 0; +} + +AVCodec eacmv_decoder = { + "eacmv", + CODEC_TYPE_VIDEO, + CODEC_ID_CMV, + sizeof(CmvContext), + cmv_decode_init, + NULL, + cmv_decode_end, + cmv_decode_frame, + CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Electronic Arts CMV Video"), +}; Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/eatgv.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/eatgv.c 2008-09-15 14:02:50 UTC (rev 27545) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/eatgv.c 2008-09-15 14:03:17 UTC (rev 27546) @@ -0,0 +1,340 @@ +/* + * Electronic Arts TGV Video Decoder + * Copyright (c) 2007-2008 Peter Ross + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file eatgv.c + * Electronic Arts TGV Video Decoder + * by Peter Ross (suxen_drol at hotmail dot com) + * + * Technical details here: + * http://wiki.multimedia.cx/index.php?title=Electronic_Arts_TGV + */ + +#include "avcodec.h" +#define ALT_BITSTREAM_READER_LE +#include "bitstream.h" +#include + +#define EA_PREAMBLE_SIZE 8 +#define kVGT_TAG MKTAG('k', 'V', 'G', 'T') + +typedef struct TgvContext { + AVCodecContext *avctx; + AVFrame frame; + AVFrame last_frame; + int width,height; + unsigned int palette[AVPALETTE_COUNT]; + + int (*mv_codebook)[2]; + unsigned char (*block_codebook)[16]; + int num_mvs; ///< current length of mv_codebook + int num_blocks_packed; ///< current length of block_codebook +} TgvContext; + +static av_cold int tgv_decode_init(AVCodecContext *avctx){ + TgvContext *s = avctx->priv_data; + s->avctx = avctx; + avctx->time_base = (AVRational){1, 15}; + avctx->pix_fmt = PIX_FMT_PAL8; + return 0; +} + +/** + * Unpack buffer + * @return 0 on success, -1 on critical buffer underflow + */ +static int unpack(const uint8_t *src, const uint8_t *src_end, unsigned char *dst, int width, int height) { + unsigned char *dst_end = dst + width*height; + int size,size1,size2,offset,run; + unsigned char *dst_start = dst; + + if (src[0] & 0x01) + src += 5; + else + src += 2; + + if (src+3>src_end) + return -1; + size = AV_RB24(src); + src += 3; + + while(size>0 && src> 6 ); + offset = (AV_RB16(&src[1]) & 0x3FFF) + 1; + size2 = (src[0] & 0x3F) + 4; + src += 3; + } + } else { // 0 + offset = ((src[0] & 0x60) << 3) + src[1] + 1; + size2 = ((src[0] & 0x1C) >> 2) + 3; + src += 2; + } + + + /* fetch strip from src */ + if (size1>src_end-src) + break; + + if (size1>0) { + size -= size1; + run = FFMIN(size1, dst_end-dst); + memcpy(dst, src, run); + dst += run; + src += run; + } + + if (size2>0) { + if (dst-dst_startlast_frame.data[0] + s->avctx->width*s->last_frame.linesize[0]; + int num_mvs; + int num_blocks_raw; + int num_blocks_packed; + int vector_bits; + int i,j,x,y; + GetBitContext gb; + int mvbits; + const unsigned char *blocks_raw; + + if(buf+12>buf_end) + return -1; + + num_mvs = AV_RL16(&buf[0]); + num_blocks_raw = AV_RL16(&buf[2]); + num_blocks_packed = AV_RL16(&buf[4]); + vector_bits = AV_RL16(&buf[6]); + buf += 12; + + /* allocate codebook buffers as neccessary */ + if (num_mvs > s->num_mvs) { + s->mv_codebook = av_realloc(s->mv_codebook, num_mvs*2*sizeof(int)); + s->num_mvs = num_mvs; + } + + if (num_blocks_packed > s->num_blocks_packed) { + s->block_codebook = av_realloc(s->block_codebook, num_blocks_packed*16*sizeof(unsigned char)); + s->num_blocks_packed = num_blocks_packed; + } + + /* read motion vectors */ + mvbits = (num_mvs*2*10+31) & ~31; + + if (buf+(mvbits>>3)+16*num_blocks_raw+8*num_blocks_packed>buf_end) + return -1; + + init_get_bits(&gb, buf, mvbits); + for (i=0; imv_codebook[i][0] = get_sbits(&gb, 10); + s->mv_codebook[i][1] = get_sbits(&gb, 10); + } + buf += mvbits>>3; + + /* note ptr to uncompressed blocks */ + blocks_raw = buf; + buf += num_blocks_raw*16; + + /* read compressed blocks */ + init_get_bits(&gb, buf, (buf_end-buf)<<3); + for (i=0; iblock_codebook[i][15-j] = tmp[get_bits(&gb, 2)]; + } + + /* read vectors and build frame */ + for(y=0; yavctx->height/4; y++) + for(x=0; xavctx->width/4; x++) { + unsigned int vector = get_bits(&gb, vector_bits); + const unsigned char *src; + int src_stride; + + if (vector < num_mvs) { + src = s->last_frame.data[0] + + (y*4 + s->mv_codebook[vector][1])*s->last_frame.linesize[0] + + x*4 + s->mv_codebook[vector][0]; + src_stride = s->last_frame.linesize[0]; + if (src+3*src_stride+3>=frame0_end) + continue; + }else{ + int offset = vector - num_mvs; + if (offsetblock_codebook[offset-num_blocks_raw]; + else + continue; + src_stride = 4; + } + + for(j=0; j<4; j++) + for(i=0; i<4; i++) + s->frame.data[0][ (y*4+j)*s->frame.linesize[0] + (x*4+i) ] = + src[j*src_stride + i]; + } + + return 0; +} + +/** release AVFrame buffers if allocated */ +static void cond_release_buffer(AVFrame *pic) +{ + if (pic->data[0]) { + av_freep(&pic->data[0]); + av_free(pic->data[1]); + } +} + +static int tgv_decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + const uint8_t *buf, int buf_size) +{ + TgvContext *s = avctx->priv_data; + const uint8_t *buf_end = buf + buf_size; + int chunk_type; + + chunk_type = AV_RL32(&buf[0]); + buf += EA_PREAMBLE_SIZE; + + if (chunk_type==kVGT_TAG) { + int pal_count, i; + if(buf+12>buf_end) { + av_log(avctx, AV_LOG_WARNING, "truncated header\n"); + return -1; + } + + s->width = AV_RL16(&buf[0]); + s->height = AV_RL16(&buf[2]); + if (s->avctx->width!=s->width || s->avctx->height!=s->height) { + avcodec_set_dimensions(s->avctx, s->width, s->height); + cond_release_buffer(&s->frame); + cond_release_buffer(&s->last_frame); + } + + pal_count = AV_RL16(&buf[6]); + buf += 12; + for(i=0; ipalette[i] = AV_RB24(buf); + buf += 3; + } + } + + if (avcodec_check_dimensions(avctx, s->width, s->height)) + return -1; + + /* shuffle */ + FFSWAP(AVFrame, s->frame, s->last_frame); + if (!s->frame.data[0]) { + s->frame.reference = 1; + s->frame.buffer_hints = FF_BUFFER_HINTS_VALID; + s->frame.linesize[0] = s->width; + + /* allocate additional 12 bytes to accomodate av_memcpy_backptr() OUTBUF_PADDED optimisation */ + s->frame.data[0] = av_malloc(s->width*s->height + 12); + if (!s->frame.data[0]) + return AVERROR_NOMEM; + s->frame.data[1] = av_malloc(AVPALETTE_SIZE); + if (!s->frame.data[1]) { + av_freep(&s->frame.data[0]); + return AVERROR_NOMEM; + } + } + memcpy(s->frame.data[1], s->palette, AVPALETTE_SIZE); + + if(chunk_type==kVGT_TAG) { + s->frame.key_frame = 1; + s->frame.pict_type = FF_I_TYPE; + if (unpack(buf, buf_end, s->frame.data[0], s->avctx->width, s->avctx->height)<0) { + av_log(avctx, AV_LOG_WARNING, "truncated intra frame\n"); + return -1; + } + }else{ + if (!s->last_frame.data[0]) { + av_log(avctx, AV_LOG_WARNING, "inter frame without corresponding intra frame\n"); + return buf_size; + } + s->frame.key_frame = 0; + s->frame.pict_type = FF_P_TYPE; + if (tgv_decode_inter(s, buf, buf_end)<0) { + av_log(avctx, AV_LOG_WARNING, "truncated inter frame\n"); + return -1; + } + } + + *data_size = sizeof(AVFrame); + *(AVFrame*)data = s->frame; + + return buf_size; +} + +static av_cold int tgv_decode_end(AVCodecContext *avctx) +{ + TgvContext *s = avctx->priv_data; + cond_release_buffer(&s->frame); + cond_release_buffer(&s->last_frame); + av_free(s->mv_codebook); + av_free(s->block_codebook); + return 0; +} + +AVCodec eatgv_decoder = { + "eatgv", + CODEC_TYPE_VIDEO, + CODEC_ID_TGV, + sizeof(TgvContext), + tgv_decode_init, + NULL, + tgv_decode_end, + tgv_decode_frame, + .long_name = NULL_IF_CONFIG_SMALL("Electronic Arts TGV Video"), +}; Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/elbg.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/elbg.c 2008-09-15 14:02:50 UTC (rev 27545) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/elbg.c 2008-09-15 14:03:17 UTC (rev 27546) @@ -0,0 +1,425 @@ +/* + * Copyright (C) 2007 Vitor Sessak + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file cbook_gen.c + * Codebook Generator using the ELBG algorithm + */ + +#include + +#include "random.h" +#include "elbg.h" +#include "avcodec.h" + +#define DELTA_ERR_MAX 0.1 ///< Precision of the ELBG algorithm (as percentual error) + +/** + * In the ELBG jargon, a cell is the set of points that are closest to a + * codebook entry. Not to be confused with a RoQ Video cell. */ +typedef struct cell_s { + int index; + struct cell_s *next; +} cell; + +/** + * ELBG internal data + */ +typedef struct{ + int error; + int dim; + int numCB; + int *codebook; + cell **cells; + int *utility; + int *utility_inc; + int *nearest_cb; + int *points; + AVRandomState *rand_state; +} elbg_data; + +static inline int distance_limited(int *a, int *b, int dim, int limit) +{ + int i, dist=0; + for (i=0; i limit) + return INT_MAX; + } + + return dist; +} + +static inline void vect_division(int *res, int *vect, int div, int dim) +{ + int i; + if (div > 1) + for (i=0; inext) + error += distance_limited(centroid, elbg->points + cells->index*elbg->dim, elbg->dim, INT_MAX); + + return error; +} + +static int get_closest_codebook(elbg_data *elbg, int index) +{ + int i, pick=0, diff, diff_min = INT_MAX; + for (i=0; inumCB; i++) + if (i != index) { + diff = distance_limited(elbg->codebook + i*elbg->dim, elbg->codebook + index*elbg->dim, elbg->dim, diff_min); + if (diff < diff_min) { + pick = i; + diff_min = diff; + } + } + return pick; +} + +static int get_high_utility_cell(elbg_data *elbg) +{ + int i=0; + /* Using linear search, do binary if it ever turns to be speed critical */ + int r = av_random(elbg->rand_state)%(elbg->utility_inc[elbg->numCB-1]-1) + 1; + while (elbg->utility_inc[i] < r) + i++; + + assert(!elbg->cells[i]); + + return i; +} + +/** + * Implementation of the simple LBG algorithm for just two codebooks + */ +static int simple_lbg(int dim, + int *centroid[3], + int newutility[3], + int *points, + cell *cells) +{ + int i, idx; + int numpoints[2] = {0,0}; + int newcentroid[2][dim]; + cell *tempcell; + + memset(newcentroid, 0, sizeof(newcentroid)); + + newutility[0] = + newutility[1] = 0; + + for (tempcell = cells; tempcell; tempcell=tempcell->next) { + idx = distance_limited(centroid[0], points + tempcell->index*dim, dim, INT_MAX)>= + distance_limited(centroid[1], points + tempcell->index*dim, dim, INT_MAX); + numpoints[idx]++; + for (i=0; iindex*dim + i]; + } + + vect_division(centroid[0], newcentroid[0], numpoints[0], dim); + vect_division(centroid[1], newcentroid[1], numpoints[1], dim); + + for (tempcell = cells; tempcell; tempcell=tempcell->next) { + int dist[2] = {distance_limited(centroid[0], points + tempcell->index*dim, dim, INT_MAX), + distance_limited(centroid[1], points + tempcell->index*dim, dim, INT_MAX)}; + int idx = dist[0] > dist[1]; + newutility[idx] += dist[idx]; + } + + return newutility[0] + newutility[1]; +} + +static void get_new_centroids(elbg_data *elbg, int huc, int *newcentroid_i, + int *newcentroid_p) +{ + cell *tempcell; + int min[elbg->dim]; + int max[elbg->dim]; + int i; + + for (i=0; i< elbg->dim; i++) { + min[i]=INT_MAX; + max[i]=0; + } + + for (tempcell = elbg->cells[huc]; tempcell; tempcell = tempcell->next) + for(i=0; idim; i++) { + min[i]=FFMIN(min[i], elbg->points[tempcell->index*elbg->dim + i]); + max[i]=FFMAX(max[i], elbg->points[tempcell->index*elbg->dim + i]); + } + + for (i=0; idim; i++) { + newcentroid_i[i] = min[i] + (max[i] - min[i])/3; + newcentroid_p[i] = min[i] + (2*(max[i] - min[i]))/3; + } +} + +/** + * Add the points in the low utility cell to its closest cell. Split the high + * utility cell, putting the separed points in the (now empty) low utility + * cell. + * + * @param elbg Internal elbg data + * @param indexes {luc, huc, cluc} + * @param newcentroid A vector with the position of the new centroids + */ +static void shift_codebook(elbg_data *elbg, int *indexes, + int *newcentroid[3]) +{ + cell *tempdata; + cell **pp = &elbg->cells[indexes[2]]; + + while(*pp) + pp= &(*pp)->next; + + *pp = elbg->cells[indexes[0]]; + + elbg->cells[indexes[0]] = NULL; + tempdata = elbg->cells[indexes[1]]; + elbg->cells[indexes[1]] = NULL; + + while(tempdata) { + cell *tempcell2 = tempdata->next; + int idx = distance_limited(elbg->points + tempdata->index*elbg->dim, + newcentroid[0], elbg->dim, INT_MAX) > + distance_limited(elbg->points + tempdata->index*elbg->dim, + newcentroid[1], elbg->dim, INT_MAX); + + tempdata->next = elbg->cells[indexes[idx]]; + elbg->cells[indexes[idx]] = tempdata; + tempdata = tempcell2; + } +} + +static void evaluate_utility_inc(elbg_data *elbg) +{ + int i, inc=0; + + for (i=0; i < elbg->numCB; i++) { + if (elbg->numCB*elbg->utility[i] > elbg->error) + inc += elbg->utility[i]; + elbg->utility_inc[i] = inc; + } +} + + +static void update_utility_and_n_cb(elbg_data *elbg, int idx, int newutility) +{ + cell *tempcell; + + elbg->utility[idx] = newutility; + for (tempcell=elbg->cells[idx]; tempcell; tempcell=tempcell->next) + elbg->nearest_cb[tempcell->index] = idx; +} + +/** + * Evaluate if a shift lower the error. If it does, call shift_codebooks + * and update elbg->error, elbg->utility and elbg->nearest_cb. + * + * @param elbg Internal elbg data + * @param indexes {luc (low utility cell, huc (high utility cell), cluc (closest cell to low utility cell)} + */ +static void try_shift_candidate(elbg_data *elbg, int idx[3]) +{ + int j, k, olderror=0, newerror, cont=0; + int newutility[3]; + int newcentroid[3][elbg->dim]; + int *newcentroid_ptrs[3]; + cell *tempcell; + + newcentroid_ptrs[0] = newcentroid[0]; + newcentroid_ptrs[1] = newcentroid[1]; + newcentroid_ptrs[2] = newcentroid[2]; + + for (j=0; j<3; j++) + olderror += elbg->utility[idx[j]]; + + memset(newcentroid[2], 0, elbg->dim*sizeof(int)); + + for (k=0; k<2; k++) + for (tempcell=elbg->cells[idx[2*k]]; tempcell; tempcell=tempcell->next) { + cont++; + for (j=0; jdim; j++) + newcentroid[2][j] += elbg->points[tempcell->index*elbg->dim + j]; + } + + vect_division(newcentroid[2], newcentroid[2], cont, elbg->dim); + + get_new_centroids(elbg, idx[1], newcentroid[0], newcentroid[1]); + + newutility[2] = eval_error_cell(elbg, newcentroid[2], elbg->cells[idx[0]]); + newutility[2] += eval_error_cell(elbg, newcentroid[2], elbg->cells[idx[2]]); + + newerror = newutility[2]; + + newerror += simple_lbg(elbg->dim, newcentroid_ptrs, newutility, elbg->points, + elbg->cells[idx[1]]); + + if (olderror > newerror) { + shift_codebook(elbg, idx, newcentroid_ptrs); + + elbg->error += newerror - olderror; + + for (j=0; j<3; j++) + update_utility_and_n_cb(elbg, idx[j], newutility[j]); + + evaluate_utility_inc(elbg); + } + } + +/** + * Implementation of the ELBG block + */ +static void do_shiftings(elbg_data *elbg) +{ + int idx[3]; + + evaluate_utility_inc(elbg); + + for (idx[0]=0; idx[0] < elbg->numCB; idx[0]++) + if (elbg->numCB*elbg->utility[idx[0]] < elbg->error) { + if (elbg->utility_inc[elbg->numCB-1] == 0) + return; + + idx[1] = get_high_utility_cell(elbg); + idx[2] = get_closest_codebook(elbg, idx[0]); + + if (idx[1] != idx[0] && idx[1] != idx[2]) + try_shift_candidate(elbg, idx); + } +} + +#define BIG_PRIME 433494437LL + +void ff_init_elbg(int *points, int dim, int numpoints, int *codebook, + int numCB, int max_steps, int *closest_cb, + AVRandomState *rand_state) +{ + int i, k; + + if (numpoints > 24*numCB) { + /* ELBG is very costly for a big number of points. So if we have a lot + of them, get a good initial codebook to save on iterations */ + int *temp_points = av_malloc(dim*(numpoints/8)*sizeof(int)); + for (i=0; i Author: dlmcpaul Date: 2008-09-15 16:03:43 +0200 (Mon, 15 Sep 2008) New Revision: 27547 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27547&view=rev Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/faanidct.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/faanidct.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/fft-test.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/flac.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/flac.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/flacenc.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/flashsv.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/flashsvenc.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/fraps.c Modified: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/faandct.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/faandct.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/fdctref.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/fft.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/ffv1.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/flicvideo.c Log: Update avcodec to 20080825 Modified: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/faandct.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/faandct.c 2008-09-15 14:03:17 UTC (rev 27546) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/faandct.c 2008-09-15 14:03:43 UTC (rev 27547) @@ -2,32 +2,35 @@ * Floating point AAN DCT * Copyright (c) 2003 Michael Niedermayer * - * This library is free software; you can redistribute it and/or + * this implementation is based upon the IJG integer AAN DCT (see jfdctfst.c) + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. + * version 2.1 of the License, or (at your option) any later version. * - * This library is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * this implementation is based upon the IJG integer AAN DCT (see jfdctfst.c) + * The AAN DCT in this file except ff_faandct248() can also be used under the + * new (3 clause) BSD license. */ /** * @file faandct.c - * @brief + * @brief * Floating point AAN DCT * @author Michael Niedermayer */ -#include - #include "dsputil.h" #include "faandct.h" @@ -59,7 +62,7 @@ #define A5 0.38268343236508977170 // cos(pi*6/16) #define A4 1.30656296487637652774 // cos(pi*2/16)sqrt(2) -static FLOAT postscale[64]={ +static const FLOAT postscale[64]={ B0*B0, B0*B1, B0*B2, B0*B3, B0*B4, B0*B5, B0*B6, B0*B7, B1*B0, B1*B1, B1*B2, B1*B3, B1*B4, B1*B5, B1*B6, B1*B7, B2*B0, B2*B1, B2*B2, B2*B3, B2*B4, B2*B5, B2*B6, B2*B7, @@ -70,11 +73,12 @@ B7*B0, B7*B1, B7*B2, B7*B3, B7*B4, B7*B5, B7*B6, B7*B7, }; -static always_inline void row_fdct(FLOAT temp[64], DCTELEM * data) +static av_always_inline void row_fdct(FLOAT temp[64], DCTELEM * data) { FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; FLOAT tmp10, tmp11, tmp12, tmp13; - FLOAT z1, z2, z3, z4, z5, z11, z13; + FLOAT z2, z4, z11, z13; + FLOAT av_unused z5; int i; for (i=0; i<8*8; i+=8) { @@ -86,43 +90,50 @@ tmp5= data[2 + i] - data[5 + i]; tmp3= data[3 + i] + data[4 + i]; tmp4= data[3 + i] - data[4 + i]; - + tmp10= tmp0 + tmp3; tmp13= tmp0 - tmp3; tmp11= tmp1 + tmp2; tmp12= tmp1 - tmp2; - + temp[0 + i]= tmp10 + tmp11; temp[4 + i]= tmp10 - tmp11; - - z1= (tmp12 + tmp13)*A1; - temp[2 + i]= tmp13 + z1; - temp[6 + i]= tmp13 - z1; - - tmp10= tmp4 + tmp5; - tmp11= tmp5 + tmp6; - tmp12= tmp6 + tmp7; - z5= (tmp10 - tmp12) * A5; - z2= tmp10*A2 + z5; - z4= tmp12*A4 + z5; - z3= tmp11*A1; + tmp12 += tmp13; + tmp12 *= A1; + temp[2 + i]= tmp13 + tmp12; + temp[6 + i]= tmp13 - tmp12; - z11= tmp7 + z3; - z13= tmp7 - z3; + tmp4 += tmp5; + tmp5 += tmp6; + tmp6 += tmp7; +#if 0 + z5= (tmp4 - tmp6) * A5; + z2= tmp4*A2 + z5; + z4= tmp6*A4 + z5; +#else + z2= tmp4*(A2+A5) - tmp6*A5; + z4= tmp6*(A4-A5) + tmp4*A5; +#endif + tmp5*=A1; + + z11= tmp7 + tmp5; + z13= tmp7 - tmp5; + temp[5 + i]= z13 + z2; temp[3 + i]= z13 - z2; temp[1 + i]= z11 + z4; temp[7 + i]= z11 - z4; - } + } } void ff_faandct(DCTELEM * data) { FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; FLOAT tmp10, tmp11, tmp12, tmp13; - FLOAT z1, z2, z3, z4, z5, z11, z13; + FLOAT z2, z4, z11, z13; + FLOAT av_unused z5; FLOAT temp[64]; int i; @@ -139,31 +150,37 @@ tmp5= temp[8*2 + i] - temp[8*5 + i]; tmp3= temp[8*3 + i] + temp[8*4 + i]; tmp4= temp[8*3 + i] - temp[8*4 + i]; - + tmp10= tmp0 + tmp3; tmp13= tmp0 - tmp3; tmp11= tmp1 + tmp2; tmp12= tmp1 - tmp2; - + data[8*0 + i]= lrintf(SCALE(8*0 + i) * (tmp10 + tmp11)); data[8*4 + i]= lrintf(SCALE(8*4 + i) * (tmp10 - tmp11)); - - z1= (tmp12 + tmp13)* A1; - data[8*2 + i]= lrintf(SCALE(8*2 + i) * (tmp13 + z1)); - data[8*6 + i]= lrintf(SCALE(8*6 + i) * (tmp13 - z1)); - - tmp10= tmp4 + tmp5; - tmp11= tmp5 + tmp6; - tmp12= tmp6 + tmp7; - z5= (tmp10 - tmp12) * A5; - z2= tmp10*A2 + z5; - z4= tmp12*A4 + z5; - z3= tmp11*A1; + tmp12 += tmp13; + tmp12 *= A1; + data[8*2 + i]= lrintf(SCALE(8*2 + i) * (tmp13 + tmp12)); + data[8*6 + i]= lrintf(SCALE(8*6 + i) * (tmp13 - tmp12)); - z11= tmp7 + z3; - z13= tmp7 - z3; + tmp4 += tmp5; + tmp5 += tmp6; + tmp6 += tmp7; +#if 0 + z5= (tmp4 - tmp6) * A5; + z2= tmp4*A2 + z5; + z4= tmp6*A4 + z5; +#else + z2= tmp4*(A2+A5) - tmp6*A5; + z4= tmp6*(A4-A5) + tmp4*A5; +#endif + tmp5*=A1; + + z11= tmp7 + tmp5; + z13= tmp7 - tmp5; + data[8*5 + i]= lrintf(SCALE(8*5 + i) * (z13 + z2)); data[8*3 + i]= lrintf(SCALE(8*3 + i) * (z13 - z2)); data[8*1 + i]= lrintf(SCALE(8*1 + i) * (z11 + z4)); @@ -175,7 +192,6 @@ { FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; FLOAT tmp10, tmp11, tmp12, tmp13; - FLOAT z1; FLOAT temp[64]; int i; @@ -192,29 +208,31 @@ tmp5 = temp[8*2 + i] - temp[8*3 + i]; tmp6 = temp[8*4 + i] - temp[8*5 + i]; tmp7 = temp[8*6 + i] - temp[8*7 + i]; - + tmp10 = tmp0 + tmp3; tmp11 = tmp1 + tmp2; tmp12 = tmp1 - tmp2; tmp13 = tmp0 - tmp3; - + data[8*0 + i] = lrintf(SCALE(8*0 + i) * (tmp10 + tmp11)); data[8*4 + i] = lrintf(SCALE(8*4 + i) * (tmp10 - tmp11)); - - z1 = (tmp12 + tmp13)* A1; - data[8*2 + i] = lrintf(SCALE(8*2 + i) * (tmp13 + z1)); - data[8*6 + i] = lrintf(SCALE(8*6 + i) * (tmp13 - z1)); - + + tmp12 += tmp13; + tmp12 *= A1; + data[8*2 + i] = lrintf(SCALE(8*2 + i) * (tmp13 + tmp12)); + data[8*6 + i] = lrintf(SCALE(8*6 + i) * (tmp13 - tmp12)); + tmp10 = tmp4 + tmp7; - tmp11 = tmp5 + tmp6; - tmp12 = tmp5 - tmp6; - tmp13 = tmp4 - tmp7; + tmp11 = tmp5 + tmp6; + tmp12 = tmp5 - tmp6; + tmp13 = tmp4 - tmp7; - data[8*1 + i] = lrintf(SCALE(8*0 + i) * (tmp10 + tmp11)); - data[8*5 + i] = lrintf(SCALE(8*4 + i) * (tmp10 - tmp11)); + data[8*1 + i] = lrintf(SCALE(8*0 + i) * (tmp10 + tmp11)); + data[8*5 + i] = lrintf(SCALE(8*4 + i) * (tmp10 - tmp11)); - z1 = (tmp12 + tmp13)* A1; - data[8*3 + i] = lrintf(SCALE(8*2 + i) * (tmp13 + z1)); - data[8*7 + i] = lrintf(SCALE(8*6 + i) * (tmp13 - z1)); + tmp12 += tmp13; + tmp12 *= A1; + data[8*3 + i] = lrintf(SCALE(8*2 + i) * (tmp13 + tmp12)); + data[8*7 + i] = lrintf(SCALE(8*6 + i) * (tmp13 - tmp12)); } } Modified: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/faandct.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/faandct.h 2008-09-15 14:03:17 UTC (rev 27546) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/faandct.h 2008-09-15 14:03:43 UTC (rev 27547) @@ -2,30 +2,38 @@ * Floating point AAN DCT * Copyright (c) 2003 Michael Niedermayer * - * This library is free software; you can redistribute it and/or + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. + * version 2.1 of the License, or (at your option) any later version. * - * This library is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** * @file faandct.h - * @brief + * @brief * Floating point AAN DCT * @author Michael Niedermayer */ - + +#ifndef FFMPEG_FAANDCT_H +#define FFMPEG_FAANDCT_H + +#include "dsputil.h" + #define FAAN_POSTSCALE - + void ff_faandct(DCTELEM * data); void ff_faandct248(DCTELEM * data); + +#endif /* FFMPEG_FAANDCT_H */ Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/faanidct.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/faanidct.c 2008-09-15 14:03:17 UTC (rev 27546) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/faanidct.c 2008-09-15 14:03:43 UTC (rev 27547) @@ -0,0 +1,168 @@ +/* + * Floating point AAN IDCT + * Copyright (c) 2008 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "faanidct.h" + +/* To allow switching to double. */ +#define FLOAT float + +#define B0 1.0000000000000000000000 +#define B1 1.3870398453221474618216 // cos(pi*1/16)sqrt(2) +#define B2 1.3065629648763765278566 // cos(pi*2/16)sqrt(2) +#define B3 1.1758756024193587169745 // cos(pi*3/16)sqrt(2) +#define B4 1.0000000000000000000000 // cos(pi*4/16)sqrt(2) +#define B5 0.7856949583871021812779 // cos(pi*5/16)sqrt(2) +#define B6 0.5411961001461969843997 // cos(pi*6/16)sqrt(2) +#define B7 0.2758993792829430123360 // cos(pi*7/16)sqrt(2) + +#define A4 0.70710678118654752438 // cos(pi*4/16) +#define A2 0.92387953251128675613 // cos(pi*2/16) + +static const FLOAT prescale[64]={ +B0*B0/8, B0*B1/8, B0*B2/8, B0*B3/8, B0*B4/8, B0*B5/8, B0*B6/8, B0*B7/8, +B1*B0/8, B1*B1/8, B1*B2/8, B1*B3/8, B1*B4/8, B1*B5/8, B1*B6/8, B1*B7/8, +B2*B0/8, B2*B1/8, B2*B2/8, B2*B3/8, B2*B4/8, B2*B5/8, B2*B6/8, B2*B7/8, +B3*B0/8, B3*B1/8, B3*B2/8, B3*B3/8, B3*B4/8, B3*B5/8, B3*B6/8, B3*B7/8, +B4*B0/8, B4*B1/8, B4*B2/8, B4*B3/8, B4*B4/8, B4*B5/8, B4*B6/8, B4*B7/8, +B5*B0/8, B5*B1/8, B5*B2/8, B5*B3/8, B5*B4/8, B5*B5/8, B5*B6/8, B5*B7/8, +B6*B0/8, B6*B1/8, B6*B2/8, B6*B3/8, B6*B4/8, B6*B5/8, B6*B6/8, B6*B7/8, +B7*B0/8, B7*B1/8, B7*B2/8, B7*B3/8, B7*B4/8, B7*B5/8, B7*B6/8, B7*B7/8, +}; + +static inline void p8idct(DCTELEM data[64], FLOAT temp[64], uint8_t *dest, int stride, int x, int y, int type){ + int i; + FLOAT av_unused tmp0; + FLOAT s04, d04, s17, d17, s26, d26, s53, d53; + FLOAT os07, os16, os25, os34; + FLOAT od07, od16, od25, od34; + + for(i=0; i + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_FAANIDCT_H +#define FFMPEG_FAANIDCT_H + +#include +#include "dsputil.h" + +void ff_faanidct(DCTELEM block[64]); +void ff_faanidct_add(uint8_t *dest, int line_size, DCTELEM block[64]); +void ff_faanidct_put(uint8_t *dest, int line_size, DCTELEM block[64]); + +#endif /* FFMPEG_FAANIDCT_H */ Modified: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/fdctref.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/fdctref.c 2008-09-15 14:03:17 UTC (rev 27546) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/fdctref.c 2008-09-15 14:03:43 UTC (rev 27547) @@ -27,7 +27,6 @@ * are subject to royalty fees to patent holders. Many of these patents are * general enough such that they are unavoidable regardless of implementation * design. - * */ #include @@ -64,51 +63,51 @@ void fdct(block) short *block; { - register int i, j; - double s; - double tmp[64]; + register int i, j; + double s; + double tmp[64]; - for(i = 0; i < 8; i++) - for(j = 0; j < 8; j++) - { - s = 0.0; + for(i = 0; i < 8; i++) + for(j = 0; j < 8; j++) + { + s = 0.0; /* - * for(k = 0; k < 8; k++) - * s += c[j][k] * block[8 * i + k]; + * for(k = 0; k < 8; k++) + * s += c[j][k] * block[8 * i + k]; */ - s += c[j][0] * block[8 * i + 0]; - s += c[j][1] * block[8 * i + 1]; - s += c[j][2] * block[8 * i + 2]; - s += c[j][3] * block[8 * i + 3]; - s += c[j][4] * block[8 * i + 4]; - s += c[j][5] * block[8 * i + 5]; - s += c[j][6] * block[8 * i + 6]; - s += c[j][7] * block[8 * i + 7]; + s += c[j][0] * block[8 * i + 0]; + s += c[j][1] * block[8 * i + 1]; + s += c[j][2] * block[8 * i + 2]; + s += c[j][3] * block[8 * i + 3]; + s += c[j][4] * block[8 * i + 4]; + s += c[j][5] * block[8 * i + 5]; + s += c[j][6] * block[8 * i + 6]; + s += c[j][7] * block[8 * i + 7]; - tmp[8 * i + j] = s; - } + tmp[8 * i + j] = s; + } - for(j = 0; j < 8; j++) - for(i = 0; i < 8; i++) - { - s = 0.0; + for(j = 0; j < 8; j++) + for(i = 0; i < 8; i++) + { + s = 0.0; /* - * for(k = 0; k < 8; k++) - * s += c[i][k] * tmp[8 * k + j]; + * for(k = 0; k < 8; k++) + * s += c[i][k] * tmp[8 * k + j]; */ - s += c[i][0] * tmp[8 * 0 + j]; - s += c[i][1] * tmp[8 * 1 + j]; - s += c[i][2] * tmp[8 * 2 + j]; - s += c[i][3] * tmp[8 * 3 + j]; - s += c[i][4] * tmp[8 * 4 + j]; - s += c[i][5] * tmp[8 * 5 + j]; - s += c[i][6] * tmp[8 * 6 + j]; - s += c[i][7] * tmp[8 * 7 + j]; - s*=8.0; + s += c[i][0] * tmp[8 * 0 + j]; + s += c[i][1] * tmp[8 * 1 + j]; + s += c[i][2] * tmp[8 * 2 + j]; + s += c[i][3] * tmp[8 * 3 + j]; + s += c[i][4] * tmp[8 * 4 + j]; + s += c[i][5] * tmp[8 * 5 + j]; + s += c[i][6] * tmp[8 * 6 + j]; + s += c[i][7] * tmp[8 * 7 + j]; + s*=8.0; - block[8 * i + j] = (short)floor(s + 0.499999); + block[8 * i + j] = (short)floor(s + 0.499999); /* * reason for adding 0.499999 instead of 0.5: * s is quite often x.5 (at least for i and/or j = 0 or 4) @@ -141,7 +140,7 @@ tmp[8*i+j] = partial_product; } - /* Transpose operation is integrated into address mapping by switching + /* Transpose operation is integrated into address mapping by switching loop order of i and j */ for (j=0; j<8; j++) Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/fft-test.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/fft-test.c 2008-09-15 14:03:17 UTC (rev 27546) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/fft-test.c 2008-09-15 14:03:43 UTC (rev 27547) @@ -0,0 +1,306 @@ +/* + * (c) 2002 Fabrice Bellard + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file fft-test.c + * FFT and MDCT tests. + */ + +#include "dsputil.h" +#include +#include +#include +#include +#include + +#undef exit +#undef random + +/* reference fft */ + +#define MUL16(a,b) ((a) * (b)) + +#define CMAC(pre, pim, are, aim, bre, bim) \ +{\ + pre += (MUL16(are, bre) - MUL16(aim, bim));\ + pim += (MUL16(are, bim) + MUL16(bre, aim));\ +} + +FFTComplex *exptab; + +void fft_ref_init(int nbits, int inverse) +{ + int n, i; + double c1, s1, alpha; + + n = 1 << nbits; + exptab = av_malloc((n / 2) * sizeof(FFTComplex)); + + for(i=0;i<(n/2);i++) { + alpha = 2 * M_PI * (float)i / (float)n; + c1 = cos(alpha); + s1 = sin(alpha); + if (!inverse) + s1 = -s1; + exptab[i].re = c1; + exptab[i].im = s1; + } +} + +void fft_ref(FFTComplex *tabr, FFTComplex *tab, int nbits) +{ + int n, i, j, k, n2; + double tmp_re, tmp_im, s, c; + FFTComplex *q; + + n = 1 << nbits; + n2 = n >> 1; + for(i=0;i= n2) { + c = -exptab[k - n2].re; + s = -exptab[k - n2].im; + } else { + c = exptab[k].re; + s = exptab[k].im; + } + CMAC(tmp_re, tmp_im, c, s, q->re, q->im); + q++; + } + tabr[i].re = tmp_re; + tabr[i].im = tmp_im; + } +} + +void imdct_ref(float *out, float *in, int nbits) +{ + int n = 1<= 1e-3) { + av_log(NULL, AV_LOG_ERROR, "ERROR %d: %f %f\n", + i, tab1[i], tab2[i]); + } + error+= e*e; + if(e>max) max= e; + } + av_log(NULL, AV_LOG_INFO, "max:%f e:%g\n", max, sqrt(error)/n); +} + + +void help(void) +{ + av_log(NULL, AV_LOG_INFO,"usage: fft-test [-h] [-s] [-i] [-n b]\n" + "-h print this help\n" + "-s speed test\n" + "-m (I)MDCT test\n" + "-i inverse transform test\n" + "-n b set the transform size to 2^b\n" + ); + exit(1); +} + + + +int main(int argc, char **argv) +{ + FFTComplex *tab, *tab1, *tab_ref; + FFTSample *tab2; + int it, i, c; + int do_speed = 0; + int do_mdct = 0; + int do_inverse = 0; + FFTContext s1, *s = &s1; + MDCTContext m1, *m = &m1; + int fft_nbits, fft_size; + + fft_nbits = 9; + for(;;) { + c = getopt(argc, argv, "hsimn:"); + if (c == -1) + break; + switch(c) { + case 'h': + help(); + break; + case 's': + do_speed = 1; + break; + case 'i': + do_inverse = 1; + break; + case 'm': + do_mdct = 1; + break; + case 'n': + fft_nbits = atoi(optarg); + break; + } + } + + fft_size = 1 << fft_nbits; + tab = av_malloc(fft_size * sizeof(FFTComplex)); + tab1 = av_malloc(fft_size * sizeof(FFTComplex)); + tab_ref = av_malloc(fft_size * sizeof(FFTComplex)); + tab2 = av_malloc(fft_size * sizeof(FFTSample)); + + if (do_mdct) { + if (do_inverse) + av_log(NULL, AV_LOG_INFO,"IMDCT"); + else + av_log(NULL, AV_LOG_INFO,"MDCT"); + ff_mdct_init(m, fft_nbits, do_inverse); + } else { + if (do_inverse) + av_log(NULL, AV_LOG_INFO,"IFFT"); + else + av_log(NULL, AV_LOG_INFO,"FFT"); + ff_fft_init(s, fft_nbits, do_inverse); + fft_ref_init(fft_nbits, do_inverse); + } + av_log(NULL, AV_LOG_INFO," %d test\n", fft_size); + + /* generate random data */ + + for(i=0;i= 1000000) + break; + nb_its *= 2; + } + av_log(NULL, AV_LOG_INFO,"time: %0.1f us/transform [total time=%0.2f s its=%d]\n", + (double)duration / nb_its, + (double)duration / 1000000.0, + nb_its); + } + + if (do_mdct) { + ff_mdct_end(m); + } else { + ff_fft_end(s); + } + return 0; +} Modified: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/fft.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/fft.c 2008-09-15 14:03:17 UTC (rev 27546) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/fft.c 2008-09-15 14:03:43 UTC (rev 27547) @@ -1,20 +1,24 @@ /* * FFT/IFFT transforms + * Copyright (c) 2008 Loren Merritt * Copyright (c) 2002 Fabrice Bellard. + * Partly based on libdjbfft by D. J. Bernstein * - * This library is free software; you can redistribute it and/or + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. + * version 2.1 of the License, or (at your option) any later version. * - * This library is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** @@ -24,18 +28,53 @@ #include "dsputil.h" +/* cos(2*pi*x/n) for 0<=x<=n/4, followed by its reverse */ +DECLARE_ALIGNED_16(FFTSample, ff_cos_16[8]); +DECLARE_ALIGNED_16(FFTSample, ff_cos_32[16]); +DECLARE_ALIGNED_16(FFTSample, ff_cos_64[32]); +DECLARE_ALIGNED_16(FFTSample, ff_cos_128[64]); +DECLARE_ALIGNED_16(FFTSample, ff_cos_256[128]); +DECLARE_ALIGNED_16(FFTSample, ff_cos_512[256]); +DECLARE_ALIGNED_16(FFTSample, ff_cos_1024[512]); +DECLARE_ALIGNED_16(FFTSample, ff_cos_2048[1024]); +DECLARE_ALIGNED_16(FFTSample, ff_cos_4096[2048]); +DECLARE_ALIGNED_16(FFTSample, ff_cos_8192[4096]); +DECLARE_ALIGNED_16(FFTSample, ff_cos_16384[8192]); +DECLARE_ALIGNED_16(FFTSample, ff_cos_32768[16384]); +DECLARE_ALIGNED_16(FFTSample, ff_cos_65536[32768]); +static FFTSample *ff_cos_tabs[] = { + ff_cos_16, ff_cos_32, ff_cos_64, ff_cos_128, ff_cos_256, ff_cos_512, ff_cos_1024, + ff_cos_2048, ff_cos_4096, ff_cos_8192, ff_cos_16384, ff_cos_32768, ff_cos_65536, +}; + +static int split_radix_permutation(int i, int n, int inverse) +{ + int m; + if(n <= 2) return i&1; + m = n >> 1; [... truncated: 5347 lines follow ...] From dlmcpaul at mail.berlios.de Mon Sep 15 16:04:01 2008 From: dlmcpaul at mail.berlios.de (dlmcpaul at BerliOS) Date: Mon, 15 Sep 2008 16:04:01 +0200 Subject: [Haiku-commits] r27548 - haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec Message-ID: <200809151404.m8FE41VM000212@sheep.berlios.de> Author: dlmcpaul Date: 2008-09-15 16:04:00 +0200 (Mon, 15 Sep 2008) New Revision: 27548 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27548&view=rev Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/g726.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/g729.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/g729data.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/g729dec.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/gif.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/gifdec.c Modified: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/golomb.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/golomb.h Log: Update avcodec to 20080825 Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/g726.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/g726.c 2008-09-15 14:03:43 UTC (rev 27547) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/g726.c 2008-09-15 14:04:00 UTC (rev 27548) @@ -0,0 +1,402 @@ +/* + * G.726 ADPCM audio codec + * Copyright (c) 2004 Roman Shaposhnik. + * + * This is a very straightforward rendition of the G.726 + * Section 4 "Computational Details". + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include +#include "avcodec.h" +#include "bitstream.h" + +/** + * G.726 11bit float. + * G.726 Standard uses rather odd 11bit floating point arithmentic for + * numerous occasions. It's a mistery to me why they did it this way + * instead of simply using 32bit integer arithmetic. + */ +typedef struct Float11 { + uint8_t sign; /**< 1bit sign */ + uint8_t exp; /**< 4bit exponent */ + uint8_t mant; /**< 6bit mantissa */ +} Float11; + +static inline Float11* i2f(int i, Float11* f) +{ + f->sign = (i < 0); + if (f->sign) + i = -i; + f->exp = av_log2_16bit(i) + !!i; + f->mant = i? (i<<6) >> f->exp : 1<<5; + return f; +} + +static inline int16_t mult(Float11* f1, Float11* f2) +{ + int res, exp; + + exp = f1->exp + f2->exp; + res = (((f1->mant * f2->mant) + 0x30) >> 4); + res = exp > 19 ? res << (exp - 19) : res >> (19 - exp); + return (f1->sign ^ f2->sign) ? -res : res; +} + +static inline int sgn(int value) +{ + return (value < 0) ? -1 : 1; +} + +typedef struct G726Tables { + const int* quant; /**< quantization table */ + const int16_t* iquant; /**< inverse quantization table */ + const int16_t* W; /**< special table #1 ;-) */ + const uint8_t* F; /**< special table #2 */ +} G726Tables; + +typedef struct G726Context { + G726Tables tbls; /**< static tables needed for computation */ + + Float11 sr[2]; /**< prev. reconstructed samples */ + Float11 dq[6]; /**< prev. difference */ + int a[2]; /**< second order predictor coeffs */ + int b[6]; /**< sixth order predictor coeffs */ + int pk[2]; /**< signs of prev. 2 sez + dq */ + + int ap; /**< scale factor control */ + int yu; /**< fast scale factor */ + int yl; /**< slow scale factor */ + int dms; /**< short average magnitude of F[i] */ + int dml; /**< long average magnitude of F[i] */ + int td; /**< tone detect */ + + int se; /**< estimated signal for the next iteration */ + int sez; /**< estimated second order prediction */ + int y; /**< quantizer scaling factor for the next iteration */ + int code_size; +} G726Context; + +static const int quant_tbl16[] = /**< 16kbit/s 2bits per sample */ + { 260, INT_MAX }; +static const int16_t iquant_tbl16[] = + { 116, 365, 365, 116 }; +static const int16_t W_tbl16[] = + { -22, 439, 439, -22 }; +static const uint8_t F_tbl16[] = + { 0, 7, 7, 0 }; + +static const int quant_tbl24[] = /**< 24kbit/s 3bits per sample */ + { 7, 217, 330, INT_MAX }; +static const int16_t iquant_tbl24[] = + { INT16_MIN, 135, 273, 373, 373, 273, 135, INT16_MIN }; +static const int16_t W_tbl24[] = + { -4, 30, 137, 582, 582, 137, 30, -4 }; +static const uint8_t F_tbl24[] = + { 0, 1, 2, 7, 7, 2, 1, 0 }; + +static const int quant_tbl32[] = /**< 32kbit/s 4bits per sample */ + { -125, 79, 177, 245, 299, 348, 399, INT_MAX }; +static const int16_t iquant_tbl32[] = + { INT16_MIN, 4, 135, 213, 273, 323, 373, 425, + 425, 373, 323, 273, 213, 135, 4, INT16_MIN }; +static const int16_t W_tbl32[] = + { -12, 18, 41, 64, 112, 198, 355, 1122, + 1122, 355, 198, 112, 64, 41, 18, -12}; +static const uint8_t F_tbl32[] = + { 0, 0, 0, 1, 1, 1, 3, 7, 7, 3, 1, 1, 1, 0, 0, 0 }; + +static const int quant_tbl40[] = /**< 40kbit/s 5bits per sample */ + { -122, -16, 67, 138, 197, 249, 297, 338, + 377, 412, 444, 474, 501, 527, 552, INT_MAX }; +static const int16_t iquant_tbl40[] = + { INT16_MIN, -66, 28, 104, 169, 224, 274, 318, + 358, 395, 429, 459, 488, 514, 539, 566, + 566, 539, 514, 488, 459, 429, 395, 358, + 318, 274, 224, 169, 104, 28, -66, INT16_MIN }; +static const int16_t W_tbl40[] = + { 14, 14, 24, 39, 40, 41, 58, 100, + 141, 179, 219, 280, 358, 440, 529, 696, + 696, 529, 440, 358, 280, 219, 179, 141, + 100, 58, 41, 40, 39, 24, 14, 14 }; +static const uint8_t F_tbl40[] = + { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 6, + 6, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 }; + +static const G726Tables G726Tables_pool[] = + {{ quant_tbl16, iquant_tbl16, W_tbl16, F_tbl16 }, + { quant_tbl24, iquant_tbl24, W_tbl24, F_tbl24 }, + { quant_tbl32, iquant_tbl32, W_tbl32, F_tbl32 }, + { quant_tbl40, iquant_tbl40, W_tbl40, F_tbl40 }}; + + +/** + * Para 4.2.2 page 18: Adaptive quantizer. + */ +static inline uint8_t quant(G726Context* c, int d) +{ + int sign, exp, i, dln; + + sign = i = 0; + if (d < 0) { + sign = 1; + d = -d; + } + exp = av_log2_16bit(d); + dln = ((exp<<7) + (((d<<7)>>exp)&0x7f)) - (c->y>>2); + + while (c->tbls.quant[i] < INT_MAX && c->tbls.quant[i] < dln) + ++i; + + if (sign) + i = ~i; + if (c->code_size != 2 && i == 0) /* I'm not sure this is a good idea */ + i = 0xff; + + return i; +} + +/** + * Para 4.2.3 page 22: Inverse adaptive quantizer. + */ +static inline int16_t inverse_quant(G726Context* c, int i) +{ + int dql, dex, dqt; + + dql = c->tbls.iquant[i] + (c->y >> 2); + dex = (dql>>7) & 0xf; /* 4bit exponent */ + dqt = (1<<7) + (dql & 0x7f); /* log2 -> linear */ + return (dql < 0) ? 0 : ((dqt<> 7); +} + +static int16_t g726_decode(G726Context* c, int I) +{ + int dq, re_signal, pk0, fa1, i, tr, ylint, ylfrac, thr2, al, dq0; + Float11 f; + int I_sig= I >> (c->code_size - 1); + + dq = inverse_quant(c, I); + + /* Transition detect */ + ylint = (c->yl >> 15); + ylfrac = (c->yl >> 10) & 0x1f; + thr2 = (ylint > 9) ? 0x1f << 10 : (0x20 + ylfrac) << ylint; + tr= (c->td == 1 && dq > ((3*thr2)>>2)); + + if (I_sig) /* get the sign */ + dq = -dq; + re_signal = c->se + dq; + + /* Update second order predictor coefficient A2 and A1 */ + pk0 = (c->sez + dq) ? sgn(c->sez + dq) : 0; + dq0 = dq ? sgn(dq) : 0; + if (tr) { + c->a[0] = 0; + c->a[1] = 0; + for (i=0; i<6; i++) + c->b[i] = 0; + } else { + /* This is a bit crazy, but it really is +255 not +256 */ + fa1 = av_clip((-c->a[0]*c->pk[0]*pk0)>>5, -256, 255); + + c->a[1] += 128*pk0*c->pk[1] + fa1 - (c->a[1]>>7); + c->a[1] = av_clip(c->a[1], -12288, 12288); + c->a[0] += 64*3*pk0*c->pk[0] - (c->a[0] >> 8); + c->a[0] = av_clip(c->a[0], -(15360 - c->a[1]), 15360 - c->a[1]); + + for (i=0; i<6; i++) + c->b[i] += 128*dq0*sgn(-c->dq[i].sign) - (c->b[i]>>8); + } + + /* Update Dq and Sr and Pk */ + c->pk[1] = c->pk[0]; + c->pk[0] = pk0 ? pk0 : 1; + c->sr[1] = c->sr[0]; + i2f(re_signal, &c->sr[0]); + for (i=5; i>0; i--) + c->dq[i] = c->dq[i-1]; + i2f(dq, &c->dq[0]); + c->dq[0].sign = I_sig; /* Isn't it crazy ?!?! */ + + c->td = c->a[1] < -11776; + + /* Update Ap */ + c->dms += (c->tbls.F[I]<<4) + ((- c->dms) >> 5); + c->dml += (c->tbls.F[I]<<4) + ((- c->dml) >> 7); + if (tr) + c->ap = 256; + else { + c->ap += (-c->ap) >> 4; + if (c->y <= 1535 || c->td || abs((c->dms << 2) - c->dml) >= (c->dml >> 3)) + c->ap += 0x20; + } + + /* Update Yu and Yl */ + c->yu = av_clip(c->y + c->tbls.W[I] + ((-c->y)>>5), 544, 5120); + c->yl += c->yu + ((-c->yl)>>6); + + /* Next iteration for Y */ + al = (c->ap >= 256) ? 1<<6 : c->ap >> 2; + c->y = (c->yl + (c->yu - (c->yl>>6))*al) >> 6; + + /* Next iteration for SE and SEZ */ + c->se = 0; + for (i=0; i<6; i++) + c->se += mult(i2f(c->b[i] >> 2, &f), &c->dq[i]); + c->sez = c->se >> 1; + for (i=0; i<2; i++) + c->se += mult(i2f(c->a[i] >> 2, &f), &c->sr[i]); + c->se >>= 1; + + return av_clip(re_signal << 2, -0xffff, 0xffff); +} + +static av_cold int g726_reset(G726Context* c, int index) +{ + int i; + + c->tbls = G726Tables_pool[index]; + for (i=0; i<2; i++) { + c->sr[i].mant = 1<<5; + c->pk[i] = 1; + } + for (i=0; i<6; i++) { + c->dq[i].mant = 1<<5; + } + c->yu = 544; + c->yl = 34816; + + c->y = 544; + + return 0; +} + +#ifdef CONFIG_ENCODERS +static int16_t g726_encode(G726Context* c, int16_t sig) +{ + uint8_t i; + + i = quant(c, sig/4 - c->se) & ((1<code_size) - 1); + g726_decode(c, i); + return i; +} +#endif + +/* Interfacing to the libavcodec */ + +static av_cold int g726_init(AVCodecContext * avctx) +{ + G726Context* c = avctx->priv_data; + unsigned int index= (avctx->bit_rate + avctx->sample_rate/2) / avctx->sample_rate - 2; + + if (avctx->bit_rate % avctx->sample_rate && avctx->codec->encode) { + av_log(avctx, AV_LOG_ERROR, "Bitrate - Samplerate combination is invalid\n"); + return -1; + } + if(avctx->channels != 1){ + av_log(avctx, AV_LOG_ERROR, "Only mono is supported\n"); + return -1; + } + if(index>3){ + av_log(avctx, AV_LOG_ERROR, "Unsupported number of bits %d\n", index+2); + return -1; + } + g726_reset(c, index); + c->code_size = index+2; + + avctx->coded_frame = avcodec_alloc_frame(); + if (!avctx->coded_frame) + return AVERROR(ENOMEM); + avctx->coded_frame->key_frame = 1; + + if (avctx->codec->decode) + avctx->sample_fmt = SAMPLE_FMT_S16; + + return 0; +} + +static av_cold int g726_close(AVCodecContext *avctx) +{ + av_freep(&avctx->coded_frame); + return 0; +} + +#ifdef CONFIG_ENCODERS +static int g726_encode_frame(AVCodecContext *avctx, + uint8_t *dst, int buf_size, void *data) +{ + G726Context *c = avctx->priv_data; + short *samples = data; + PutBitContext pb; + + init_put_bits(&pb, dst, 1024*1024); + + for (; buf_size; buf_size--) + put_bits(&pb, c->code_size, g726_encode(c, *samples++)); + + flush_put_bits(&pb); + + return put_bits_count(&pb)>>3; +} +#endif + +static int g726_decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + const uint8_t *buf, int buf_size) +{ + G726Context *c = avctx->priv_data; + short *samples = data; + GetBitContext gb; + + init_get_bits(&gb, buf, buf_size * 8); + + while (get_bits_count(&gb) + c->code_size <= buf_size*8) + *samples++ = g726_decode(c, get_bits(&gb, c->code_size)); + + if(buf_size*8 != get_bits_count(&gb)) + av_log(avctx, AV_LOG_ERROR, "Frame invalidly split, missing parser?\n"); + + *data_size = (uint8_t*)samples - (uint8_t*)data; + return buf_size; +} + +#ifdef CONFIG_ENCODERS +AVCodec adpcm_g726_encoder = { + "g726", + CODEC_TYPE_AUDIO, + CODEC_ID_ADPCM_G726, + sizeof(G726Context), + g726_init, + g726_encode_frame, + g726_close, + NULL, + .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("G.726 ADPCM"), +}; +#endif //CONFIG_ENCODERS + +AVCodec adpcm_g726_decoder = { + "g726", + CODEC_TYPE_AUDIO, + CODEC_ID_ADPCM_G726, + sizeof(G726Context), + g726_init, + NULL, + g726_close, + g726_decode_frame, + .long_name = NULL_IF_CONFIG_SMALL("G.726 ADPCM"), +}; Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/g729.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/g729.h 2008-09-15 14:03:43 UTC (rev 27547) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/g729.h 2008-09-15 14:04:00 UTC (rev 27548) @@ -0,0 +1,29 @@ +/* + * G.729 decoder + * Copyright (c) 2008 Vladimir Voroshilov + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#ifndef FFMPEG_G729_H +#define FFMPEG_G729_H + +/** + * maximum possible subframe size + */ +#define MAX_SUBFRAME_SIZE 44 + +#endif // FFMPEG_G729_H Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/g729data.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/g729data.h 2008-09-15 14:03:43 UTC (rev 27547) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/g729data.h 2008-09-15 14:04:00 UTC (rev 27548) @@ -0,0 +1,206 @@ +/* + * data for G.729 decoder + * Copyright (c) 2007 Vladimir Voroshilov + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_G729DATA_H +#define FFMPEG_G729DATA_H + +#include + +/// Moving Average (MA) prediction order +#define MA_NP 4 + +/** + * first stage LSP codebook + * (10-dimensional, with 128 entries (3.24 of G.729) + */ +static const int16_t cb_lsp_1st[1< +#include +#include +#include +#include +#include +#include + +#include "avcodec.h" +#include "libavutil/avutil.h" +#include "bitstream.h" + +/** + * minimum quantized LSF value (3.2.4) + * 0.005 in Q13 + */ +#define LSFQ_MIN 40 + +/** + * maximum quantized LSF value (3.2.4) + * 3.135 in Q13 + */ +#define LSFQ_MAX 25681 + +/** + * minimum LSF distance (3.2.4) + * 0.0391 in Q13 + */ +#define LSFQ_DIFF_MIN 321 + +/** + * \brief pseudo random number generator + */ +static inline uint16_t g729_random(uint16_t value) +{ + return 31821 * value + 13849; +} + +AVCodec g729_decoder = +{ + "g729", + CODEC_TYPE_AUDIO, + CODEC_ID_G729, + sizeof(G729_Context), + ff_g729_decoder_init, + NULL, + NULL, + ff_g729_decode_frame, + .long_name = NULL_IF_CONFIG_SMALL("G.729"), +}; Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/gif.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/gif.c 2008-09-15 14:03:43 UTC (rev 27547) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/gif.c 2008-09-15 14:04:00 UTC (rev 27548) @@ -0,0 +1,345 @@ +/* + * GIF encoder. + * Copyright (c) 2000 Fabrice Bellard. + * Copyright (c) 2002 Francois Revol. + * Copyright (c) 2006 Baptiste Coudurier. + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* + * First version by Francois Revol revol at free.fr + * + * Features and limitations: + * - currently no compression is performed, + * in fact the size of the data is 9/8 the size of the image in 8bpp + * - uses only a global standard palette + * - tested with IE 5.0, Opera for BeOS, NetPositive (BeOS), and Mozilla (BeOS). + * + * Reference documents: + * http://www.goice.co.jp/member/mo/formats/gif.html + * http://astronomy.swin.edu.au/pbourke/dataformats/gif/ + * http://www.dcs.ed.ac.uk/home/mxr/gfx/2d/GIF89a.txt + * + * this url claims to have an LZW algorithm not covered by Unisys patent: + * http://www.msg.net/utility/whirlgif/gifencod.html + * could help reduce the size of the files _a lot_... + * some sites mentions an RLE type compression also. + */ + +#include "avcodec.h" +#include "bytestream.h" +#include "bitstream.h" + +/* bitstream minipacket size */ +#define GIF_CHUNKS 100 + +/* slows down the decoding (and some browsers don't like it) */ +/* update on the 'some browsers don't like it issue from above: this was probably due to missing 'Data Sub-block Terminator' (byte 19) in the app_header */ +#define GIF_ADD_APP_HEADER // required to enable looping of animated gif + +typedef struct { + unsigned char r; + unsigned char g; + unsigned char b; +} rgb_triplet; + +/* we use the standard 216 color palette */ + +/* this script was used to create the palette: + * for r in 00 33 66 99 cc ff; do for g in 00 33 66 99 cc ff; do echo -n " "; for b in 00 33 66 99 cc ff; do + * echo -n "{ 0x$r, 0x$g, 0x$b }, "; done; echo ""; done; done + */ + +static const rgb_triplet gif_clut[216] = { + { 0x00, 0x00, 0x00 }, { 0x00, 0x00, 0x33 }, { 0x00, 0x00, 0x66 }, { 0x00, 0x00, 0x99 }, { 0x00, 0x00, 0xcc }, { 0x00, 0x00, 0xff }, + { 0x00, 0x33, 0x00 }, { 0x00, 0x33, 0x33 }, { 0x00, 0x33, 0x66 }, { 0x00, 0x33, 0x99 }, { 0x00, 0x33, 0xcc }, { 0x00, 0x33, 0xff }, + { 0x00, 0x66, 0x00 }, { 0x00, 0x66, 0x33 }, { 0x00, 0x66, 0x66 }, { 0x00, 0x66, 0x99 }, { 0x00, 0x66, 0xcc }, { 0x00, 0x66, 0xff }, + { 0x00, 0x99, 0x00 }, { 0x00, 0x99, 0x33 }, { 0x00, 0x99, 0x66 }, { 0x00, 0x99, 0x99 }, { 0x00, 0x99, 0xcc }, { 0x00, 0x99, 0xff }, + { 0x00, 0xcc, 0x00 }, { 0x00, 0xcc, 0x33 }, { 0x00, 0xcc, 0x66 }, { 0x00, 0xcc, 0x99 }, { 0x00, 0xcc, 0xcc }, { 0x00, 0xcc, 0xff }, + { 0x00, 0xff, 0x00 }, { 0x00, 0xff, 0x33 }, { 0x00, 0xff, 0x66 }, { 0x00, 0xff, 0x99 }, { 0x00, 0xff, 0xcc }, { 0x00, 0xff, 0xff }, + { 0x33, 0x00, 0x00 }, { 0x33, 0x00, 0x33 }, { 0x33, 0x00, 0x66 }, { 0x33, 0x00, 0x99 }, { 0x33, 0x00, 0xcc }, { 0x33, 0x00, 0xff }, + { 0x33, 0x33, 0x00 }, { 0x33, 0x33, 0x33 }, { 0x33, 0x33, 0x66 }, { 0x33, 0x33, 0x99 }, { 0x33, 0x33, 0xcc }, { 0x33, 0x33, 0xff }, + { 0x33, 0x66, 0x00 }, { 0x33, 0x66, 0x33 }, { 0x33, 0x66, 0x66 }, { 0x33, 0x66, 0x99 }, { 0x33, 0x66, 0xcc }, { 0x33, 0x66, 0xff }, + { 0x33, 0x99, 0x00 }, { 0x33, 0x99, 0x33 }, { 0x33, 0x99, 0x66 }, { 0x33, 0x99, 0x99 }, { 0x33, 0x99, 0xcc }, { 0x33, 0x99, 0xff }, + { 0x33, 0xcc, 0x00 }, { 0x33, 0xcc, 0x33 }, { 0x33, 0xcc, 0x66 }, { 0x33, 0xcc, 0x99 }, { 0x33, 0xcc, 0xcc }, { 0x33, 0xcc, 0xff }, + { 0x33, 0xff, 0x00 }, { 0x33, 0xff, 0x33 }, { 0x33, 0xff, 0x66 }, { 0x33, 0xff, 0x99 }, { 0x33, 0xff, 0xcc }, { 0x33, 0xff, 0xff }, + { 0x66, 0x00, 0x00 }, { 0x66, 0x00, 0x33 }, { 0x66, 0x00, 0x66 }, { 0x66, 0x00, 0x99 }, { 0x66, 0x00, 0xcc }, { 0x66, 0x00, 0xff }, + { 0x66, 0x33, 0x00 }, { 0x66, 0x33, 0x33 }, { 0x66, 0x33, 0x66 }, { 0x66, 0x33, 0x99 }, { 0x66, 0x33, 0xcc }, { 0x66, 0x33, 0xff }, + { 0x66, 0x66, 0x00 }, { 0x66, 0x66, 0x33 }, { 0x66, 0x66, 0x66 }, { 0x66, 0x66, 0x99 }, { 0x66, 0x66, 0xcc }, { 0x66, 0x66, 0xff }, + { 0x66, 0x99, 0x00 }, { 0x66, 0x99, 0x33 }, { 0x66, 0x99, 0x66 }, { 0x66, 0x99, 0x99 }, { 0x66, 0x99, 0xcc }, { 0x66, 0x99, 0xff }, + { 0x66, 0xcc, 0x00 }, { 0x66, 0xcc, 0x33 }, { 0x66, 0xcc, 0x66 }, { 0x66, 0xcc, 0x99 }, { 0x66, 0xcc, 0xcc }, { 0x66, 0xcc, 0xff }, + { 0x66, 0xff, 0x00 }, { 0x66, 0xff, 0x33 }, { 0x66, 0xff, 0x66 }, { 0x66, 0xff, 0x99 }, { 0x66, 0xff, 0xcc }, { 0x66, 0xff, 0xff }, + { 0x99, 0x00, 0x00 }, { 0x99, 0x00, 0x33 }, { 0x99, 0x00, 0x66 }, { 0x99, 0x00, 0x99 }, { 0x99, 0x00, 0xcc }, { 0x99, 0x00, 0xff }, + { 0x99, 0x33, 0x00 }, { 0x99, 0x33, 0x33 }, { 0x99, 0x33, 0x66 }, { 0x99, 0x33, 0x99 }, { 0x99, 0x33, 0xcc }, { 0x99, 0x33, 0xff }, + { 0x99, 0x66, 0x00 }, { 0x99, 0x66, 0x33 }, { 0x99, 0x66, 0x66 }, { 0x99, 0x66, 0x99 }, { 0x99, 0x66, 0xcc }, { 0x99, 0x66, 0xff }, + { 0x99, 0x99, 0x00 }, { 0x99, 0x99, 0x33 }, { 0x99, 0x99, 0x66 }, { 0x99, 0x99, 0x99 }, { 0x99, 0x99, 0xcc }, { 0x99, 0x99, 0xff }, + { 0x99, 0xcc, 0x00 }, { 0x99, 0xcc, 0x33 }, { 0x99, 0xcc, 0x66 }, { 0x99, 0xcc, 0x99 }, { 0x99, 0xcc, 0xcc }, { 0x99, 0xcc, 0xff }, + { 0x99, 0xff, 0x00 }, { 0x99, 0xff, 0x33 }, { 0x99, 0xff, 0x66 }, { 0x99, 0xff, 0x99 }, { 0x99, 0xff, 0xcc }, { 0x99, 0xff, 0xff }, + { 0xcc, 0x00, 0x00 }, { 0xcc, 0x00, 0x33 }, { 0xcc, 0x00, 0x66 }, { 0xcc, 0x00, 0x99 }, { 0xcc, 0x00, 0xcc }, { 0xcc, 0x00, 0xff }, + { 0xcc, 0x33, 0x00 }, { 0xcc, 0x33, 0x33 }, { 0xcc, 0x33, 0x66 }, { 0xcc, 0x33, 0x99 }, { 0xcc, 0x33, 0xcc }, { 0xcc, 0x33, 0xff }, + { 0xcc, 0x66, 0x00 }, { 0xcc, 0x66, 0x33 }, { 0xcc, 0x66, 0x66 }, { 0xcc, 0x66, 0x99 }, { 0xcc, 0x66, 0xcc }, { 0xcc, 0x66, 0xff }, + { 0xcc, 0x99, 0x00 }, { 0xcc, 0x99, 0x33 }, { 0xcc, 0x99, 0x66 }, { 0xcc, 0x99, 0x99 }, { 0xcc, 0x99, 0xcc }, { 0xcc, 0x99, 0xff }, + { 0xcc, 0xcc, 0x00 }, { 0xcc, 0xcc, 0x33 }, { 0xcc, 0xcc, 0x66 }, { 0xcc, 0xcc, 0x99 }, { 0xcc, 0xcc, 0xcc }, { 0xcc, 0xcc, 0xff }, + { 0xcc, 0xff, 0x00 }, { 0xcc, 0xff, 0x33 }, { 0xcc, 0xff, 0x66 }, { 0xcc, 0xff, 0x99 }, { 0xcc, 0xff, 0xcc }, { 0xcc, 0xff, 0xff }, + { 0xff, 0x00, 0x00 }, { 0xff, 0x00, 0x33 }, { 0xff, 0x00, 0x66 }, { 0xff, 0x00, 0x99 }, { 0xff, 0x00, 0xcc }, { 0xff, 0x00, 0xff }, + { 0xff, 0x33, 0x00 }, { 0xff, 0x33, 0x33 }, { 0xff, 0x33, 0x66 }, { 0xff, 0x33, 0x99 }, { 0xff, 0x33, 0xcc }, { 0xff, 0x33, 0xff }, + { 0xff, 0x66, 0x00 }, { 0xff, 0x66, 0x33 }, { 0xff, 0x66, 0x66 }, { 0xff, 0x66, 0x99 }, { 0xff, 0x66, 0xcc }, { 0xff, 0x66, 0xff }, + { 0xff, 0x99, 0x00 }, { 0xff, 0x99, 0x33 }, { 0xff, 0x99, 0x66 }, { 0xff, 0x99, 0x99 }, { 0xff, 0x99, 0xcc }, { 0xff, 0x99, 0xff }, + { 0xff, 0xcc, 0x00 }, { 0xff, 0xcc, 0x33 }, { 0xff, 0xcc, 0x66 }, { 0xff, 0xcc, 0x99 }, { 0xff, 0xcc, 0xcc }, { 0xff, 0xcc, 0xff }, + { 0xff, 0xff, 0x00 }, { 0xff, 0xff, 0x33 }, { 0xff, 0xff, 0x66 }, { 0xff, 0xff, 0x99 }, { 0xff, 0xff, 0xcc }, { 0xff, 0xff, 0xff }, +}; + +/* The GIF format uses reversed order for bitstreams... */ +/* at least they don't use PDP_ENDIAN :) */ +/* so we 'extend' PutBitContext. hmmm, OOP :) */ +/* seems this thing changed slightly since I wrote it... */ + +#ifdef ALT_BITSTREAM_WRITER +# error no ALT_BITSTREAM_WRITER support for now +#endif + +static void gif_put_bits_rev(PutBitContext *s, int n, unsigned int value) +{ + unsigned int bit_buf; + int bit_cnt; + + // printf("put_bits=%d %x\n", n, value); + assert(n == 32 || value < (1U << n)); + + bit_buf = s->bit_buf; + bit_cnt = 32 - s->bit_left; /* XXX:lazyness... was = s->bit_cnt; */ + + // printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf); + /* XXX: optimize */ + if (n < (32-bit_cnt)) { + bit_buf |= value << (bit_cnt); + bit_cnt+=n; + } else { + bit_buf |= value << (bit_cnt); + + bytestream_put_le32(&s->buf_ptr, bit_buf); + + //printf("bitbuf = %08x\n", bit_buf); + if (s->buf_ptr >= s->buf_end) + abort(); +// flush_buffer_rev(s); + bit_cnt=bit_cnt + n - 32; + if (bit_cnt == 0) { + bit_buf = 0; + } else { + bit_buf = value >> (n - bit_cnt); + } + } + + s->bit_buf = bit_buf; + s->bit_left = 32 - bit_cnt; +} + +/* pad the end of the output stream with zeros */ +static void gif_flush_put_bits_rev(PutBitContext *s) +{ + while (s->bit_left < 32) { + /* XXX: should test end of buffer */ + *s->buf_ptr++=s->bit_buf & 0xff; + s->bit_buf>>=8; + s->bit_left+=8; + } +// flush_buffer_rev(s); + s->bit_left=32; + s->bit_buf=0; +} + +/* !RevPutBitContext */ + +/* GIF header */ +static int gif_image_write_header(uint8_t **bytestream, + int width, int height, int loop_count, + uint32_t *palette) +{ + int i; + unsigned int v; + + bytestream_put_buffer(bytestream, "GIF", 3); + bytestream_put_buffer(bytestream, "89a", 3); + bytestream_put_le16(bytestream, width); + bytestream_put_le16(bytestream, height); + + bytestream_put_byte(bytestream, 0xf7); /* flags: global clut, 256 entries */ + bytestream_put_byte(bytestream, 0x1f); /* background color index */ + bytestream_put_byte(bytestream, 0); /* aspect ratio */ + + /* the global palette */ + if (!palette) { + bytestream_put_buffer(bytestream, (const unsigned char *)gif_clut, 216*3); + for(i=0;i<((256-216)*3);i++) + bytestream_put_byte(bytestream, 0); + } else { + for(i=0;i<256;i++) { + v = palette[i]; + bytestream_put_be24(bytestream, v); + } + } + + /* update: this is the 'NETSCAPE EXTENSION' that allows for looped animated gif + see http://members.aol.com/royalef/gifabout.htm#net-extension + + byte 1 : 33 (hex 0x21) GIF Extension code + byte 2 : 255 (hex 0xFF) Application Extension Label + byte 3 : 11 (hex (0x0B) Length of Application Block + (eleven bytes of data to follow) + bytes 4 to 11 : "NETSCAPE" + bytes 12 to 14 : "2.0" + byte 15 : 3 (hex 0x03) Length of Data Sub-Block + (three bytes of data to follow) + byte 16 : 1 (hex 0x01) + bytes 17 to 18 : 0 to 65535, an unsigned integer in + lo-hi byte format. This indicate the + number of iterations the loop should + be executed. + bytes 19 : 0 (hex 0x00) a Data Sub-block Terminator + */ + + /* application extension header */ +#ifdef GIF_ADD_APP_HEADER + if (loop_count >= 0 && loop_count <= 65535) { + bytestream_put_byte(bytestream, 0x21); + bytestream_put_byte(bytestream, 0xff); + bytestream_put_byte(bytestream, 0x0b); + bytestream_put_buffer(bytestream, "NETSCAPE2.0", 11); // bytes 4 to 14 + bytestream_put_byte(bytestream, 0x03); // byte 15 + bytestream_put_byte(bytestream, 0x01); // byte 16 + bytestream_put_le16(bytestream, (uint16_t)loop_count); + bytestream_put_byte(bytestream, 0x00); // byte 19 + } +#endif + return 0; +} + +/* this is maybe slow, but allows for extensions */ +static inline unsigned char gif_clut_index(uint8_t r, uint8_t g, uint8_t b) +{ + return ((((r)/47)%6)*6*6+(((g)/47)%6)*6+(((b)/47)%6)); +} + + +static int gif_image_write_image(uint8_t **bytestream, + int x1, int y1, int width, int height, + const uint8_t *buf, int linesize, int pix_fmt) +{ + PutBitContext p; + uint8_t buffer[200]; /* 100 * 9 / 8 = 113 */ + int i, left, w, v; + const uint8_t *ptr; + /* image block */ + + bytestream_put_byte(bytestream, 0x2c); + bytestream_put_le16(bytestream, x1); + bytestream_put_le16(bytestream, y1); + bytestream_put_le16(bytestream, width); + bytestream_put_le16(bytestream, height); + bytestream_put_byte(bytestream, 0x00); /* flags */ + /* no local clut */ + + bytestream_put_byte(bytestream, 0x08); + + left= width * height; + + init_put_bits(&p, buffer, 130); + +/* [... truncated: 1042 lines follow ...] From dlmcpaul at mail.berlios.de Mon Sep 15 16:04:47 2008 From: dlmcpaul at mail.berlios.de (dlmcpaul at BerliOS) Date: Mon, 15 Sep 2008 16:04:47 +0200 Subject: [Haiku-commits] r27549 - haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec Message-ID: <200809151404.m8FE4lHS000295@sheep.berlios.de> Author: dlmcpaul Date: 2008-09-15 16:04:37 +0200 (Mon, 15 Sep 2008) New Revision: 27549 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27549&view=rev Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h261.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h261.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h261_parser.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h261data.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h261dec.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h261enc.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h263.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h263_parser.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h263_parser.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h264.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h264_mp4toannexb_bsf.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h264_parser.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h264_parser.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h264dspenc.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h264enc.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h264idct.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h264pred.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h264pred.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/huffman.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/huffman.h Modified: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h263.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h263data.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h263dec.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h264.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h264data.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/huffyuv.c Log: Update avcodec to 20080825 Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h261.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h261.c 2008-09-15 14:04:00 UTC (rev 27548) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h261.c 2008-09-15 14:04:37 UTC (rev 27549) @@ -0,0 +1,54 @@ +/* + * H261 common code + * Copyright (c) 2002-2004 Michael Niedermayer + * Copyright (c) 2004 Maarten Daniels + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file h261.c + * h261codec. + */ + +#include "dsputil.h" +#include "avcodec.h" +#include "h261.h" + +#define IS_FIL(a) ((a)&MB_TYPE_H261_FIL) + +uint8_t ff_h261_rl_table_store[2][2*MAX_RUN + MAX_LEVEL + 3]; + +void ff_h261_loop_filter(MpegEncContext *s){ + H261Context * h= (H261Context*)s; + const int linesize = s->linesize; + const int uvlinesize= s->uvlinesize; + uint8_t *dest_y = s->dest[0]; + uint8_t *dest_cb= s->dest[1]; + uint8_t *dest_cr= s->dest[2]; + + if(!(IS_FIL (h->mtype))) + return; + + s->dsp.h261_loop_filter(dest_y , linesize); + s->dsp.h261_loop_filter(dest_y + 8, linesize); + s->dsp.h261_loop_filter(dest_y + 8 * linesize , linesize); + s->dsp.h261_loop_filter(dest_y + 8 * linesize + 8, linesize); + s->dsp.h261_loop_filter(dest_cb, uvlinesize); + s->dsp.h261_loop_filter(dest_cr, uvlinesize); +} + Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h261.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h261.h 2008-09-15 14:04:00 UTC (rev 27548) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h261.h 2008-09-15 14:04:37 UTC (rev 27549) @@ -0,0 +1,51 @@ +/* + * H261 decoder + * Copyright (c) 2002-2004 Michael Niedermayer + * Copyright (c) 2004 Maarten Daniels + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file h261.c + * h261codec. + */ + +#ifndef FFMPEG_H261_H +#define FFMPEG_H261_H + +#include "mpegvideo.h" + +/** + * H261Context + */ +typedef struct H261Context{ + MpegEncContext s; + + int current_mba; + int previous_mba; + int mba_diff; + int mtype; + int current_mv_x; + int current_mv_y; + int gob_number; + int gob_start_code_skipped; // 1 if gob start code is already read before gob header is read +}H261Context; + +#define MB_TYPE_H261_FIL 0x800000 + +#endif /* FFMPEG_H261_H */ Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h261_parser.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h261_parser.c 2008-09-15 14:04:00 UTC (rev 27548) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h261_parser.c 2008-09-15 14:04:37 UTC (rev 27549) @@ -0,0 +1,90 @@ +/* + * H261 parser + * Copyright (c) 2002-2004 Michael Niedermayer + * Copyright (c) 2004 Maarten Daniels + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file h261_parser.c + * h261codec. + */ + +#include "parser.h" + + +static int h261_find_frame_end(ParseContext *pc, AVCodecContext* avctx, const uint8_t *buf, int buf_size){ + int vop_found, i, j; + uint32_t state; + + vop_found= pc->frame_start_found; + state= pc->state; + + for(i=0; i>j)&0xFFFFF0) == 0x000100){ + vop_found=1; + break; + } + } + } + if(vop_found){ + for(; i>j)&0xFFFFF0) == 0x000100){ + pc->frame_start_found=0; + pc->state= (state>>(3*8))+0xFF00; + return i-2; + } + } + } + } + + pc->frame_start_found= vop_found; + pc->state= state; + return END_NOT_FOUND; +} + +static int h261_parse(AVCodecParserContext *s, + AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + ParseContext *pc = s->priv_data; + int next; + + next= h261_find_frame_end(pc,avctx, buf, buf_size); + if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { + *poutbuf = NULL; + *poutbuf_size = 0; + return buf_size; + } + *poutbuf = buf; + *poutbuf_size = buf_size; + return next; +} + +AVCodecParser h261_parser = { + { CODEC_ID_H261 }, + sizeof(ParseContext), + NULL, + h261_parse, + ff_parse_close, +}; Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h261data.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h261data.h 2008-09-15 14:04:00 UTC (rev 27548) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h261data.h 2008-09-15 14:04:37 UTC (rev 27549) @@ -0,0 +1,164 @@ +/* + * copyright (c) 2002-2004 Michael Niedermayer + * copyright (c) 2004 Maarten Daniels + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file h261data.h + * H.261 tables. + */ + +#ifndef FFMPEG_H261DATA_H +#define FFMPEG_H261DATA_H + +#include +#include "h261.h" + +// H.261 VLC table for macroblock addressing +static const uint8_t h261_mba_code[35] = { + 1, 3, 2, 3, + 2, 3, 2, 7, + 6, 11, 10, 9, + 8, 7, 6, 23, + 22, 21, 20, 19, + 18, 35, 34, 33, + 32, 31, 30, 29, + 28, 27, 26, 25, + 24, + 15, //(MBA stuffing) + 1 //(start code) +}; + +static const uint8_t h261_mba_bits[35] = { + 1, 3, 3, 4, + 4, 5, 5, 7, + 7, 8, 8, 8, + 8, 8, 8, 10, + 10, 10, 10, 10, + 10, 11, 11, 11, + 11, 11, 11, 11, + 11, 11, 11, 11, + 11, + 11, //(MBA stuffing) + 16 //(start code) +}; + +//H.261 VLC table for macroblock type +static const uint8_t h261_mtype_code[10] = { + 1, 1, 1, 1, + 1, 1, 1, 1, + 1, 1 +}; + +static const uint8_t h261_mtype_bits[10] = { + 4, 7, 1, 5, + 9, 8, 10, 3, + 2, 6 +}; + +static const int h261_mtype_map[10]= { + MB_TYPE_INTRA4x4, + MB_TYPE_INTRA4x4 | MB_TYPE_QUANT, + MB_TYPE_CBP, + MB_TYPE_QUANT | MB_TYPE_CBP, + MB_TYPE_16x16, + MB_TYPE_CBP | MB_TYPE_16x16, + MB_TYPE_QUANT | MB_TYPE_CBP | MB_TYPE_16x16, + MB_TYPE_16x16 | MB_TYPE_H261_FIL, + MB_TYPE_CBP | MB_TYPE_16x16 | MB_TYPE_H261_FIL, + MB_TYPE_QUANT | MB_TYPE_CBP | MB_TYPE_16x16 | MB_TYPE_H261_FIL +}; + +//H.261 VLC table for motion vectors +static const uint8_t h261_mv_tab[17][2] = { + {1,1}, {1,2}, {1,3}, {1,4}, {3,6}, {5,7}, {4,7}, {3,7}, + {11,9}, {10,9}, {9,9}, {17,10}, {16,10}, {15,10}, {14,10}, {13,10}, {12,10} +}; + +static const int mvmap[17] = +{ + 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16 +}; + +//H.261 VLC table for coded block pattern +static const uint8_t h261_cbp_tab[63][2] = +{ + {11,5}, {9,5}, {13,6}, {13,4}, {23,7}, {19,7}, {31,8}, {12,4}, + {22,7}, {18,7}, {30,8}, {19,5}, {27,8}, {23,8}, {19,8}, {11,4}, + {21,7}, {17,7}, {29,8}, {17,5}, {25,8}, {21,8}, {17,8}, {15,6}, + {15,8}, {13,8}, {3,9}, {15,5}, {11,8}, {7,8}, {7,9}, {10,4}, + {20,7}, {16,7}, {28,8}, {14,6}, {14,8}, {12,8}, {2,9}, {16,5}, + {24,8}, {20,8}, {16,8}, {14,5}, {10,8}, {6,8}, {6,9}, {18,5}, + {26,8}, {22,8}, {18,8}, {13,5}, {9,8}, {5,8}, {5,9}, {12,5}, + {8,8}, {4,8}, {4,9}, {7,3}, {10,5}, {8,5}, {12,6} +}; + +//H.261 VLC table for transform coefficients +static const uint16_t h261_tcoeff_vlc[65][2] = { +{ 0x2, 2 }, { 0x3, 2 },{ 0x4, 4 },{ 0x5, 5 }, +{ 0x6, 7 },{ 0x26, 8 },{ 0x21, 8 },{ 0xa, 10 }, +{ 0x1d, 12 },{ 0x18, 12 },{ 0x13, 12 },{ 0x10 , 12 }, +{ 0x1a, 13},{ 0x19, 13 }, { 0x18, 13 }, { 0x17, 13 }, +{ 0x3, 3 }, { 0x6, 6 }, { 0x25 , 8 }, { 0xc, 10 }, +{ 0x1b, 12 }, { 0x16, 13 }, { 0x15, 13 }, { 0x5, 4}, +{ 0x4, 7}, { 0xb, 10 }, { 0x14, 12 }, { 0x14, 13 }, +{ 0x7, 5 }, { 0x24, 8 }, { 0x1c, 12 }, { 0x13, 13 }, +{ 0x6, 5 }, { 0xf, 10 }, { 0x12, 12}, { 0x7, 6}, +{ 0x9 , 10 }, { 0x12, 13 }, { 0x5, 6 }, { 0x1e, 12 }, +{ 0x4, 6 }, { 0x15, 12 }, { 0x7, 7 }, { 0x11, 12}, +{ 0x5, 7 }, { 0x11, 13 }, { 0x27, 8 }, { 0x10, 13 }, +{ 0x23, 8 }, { 0x22, 8 }, { 0x20, 8 }, { 0xe , 10 }, +{ 0xd, 10 }, { 0x8, 10 },{ 0x1f, 12 }, { 0x1a, 12 }, +{ 0x19, 12 }, { 0x17, 12 }, { 0x16, 12}, { 0x1f, 13}, +{ 0x1e, 13 }, { 0x1d, 13 }, { 0x1c, 13}, { 0x1b, 13}, +{ 0x1, 6 } //escape +}; + +static const int8_t h261_tcoeff_level[64] = { + 0, 1, 2, 3, 4, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15, + 1, 2, 3, 4, 5, 6, 7, 1, + 2, 3, 4, 5, 1, 2, 3, 4, + 1, 2, 3, 1, 2, 3, 1, 2, + 1, 2, 1, 2, 1, 2, 1, 2, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1 +}; + +static const int8_t h261_tcoeff_run[64] = { + 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1, + 1, 1, 1, 1, 1, 1, 2, 2, + 2, 2, 2, 3, 3, 3, 3, 4, + 4, 4, 5, 5, 5, 6, 6, 7, + 7, 8, 8, 9, 9, 10, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26 +}; + +static RLTable h261_rl_tcoeff = { + 64, + 64, + h261_tcoeff_vlc, + h261_tcoeff_run, + h261_tcoeff_level, +}; + +#endif /* FFMPEG_H261DATA_H */ Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h261dec.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h261dec.c 2008-09-15 14:04:00 UTC (rev 27548) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/h261dec.c 2008-09-15 14:04:37 UTC (rev 27549) @@ -0,0 +1,654 @@ +/* + * H261 decoder + * Copyright (c) 2002-2004 Michael Niedermayer + * Copyright (c) 2004 Maarten Daniels + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file h261dec.c + * H.261 decoder. + */ + +#include "dsputil.h" +#include "avcodec.h" +#include "mpegvideo.h" +#include "h261.h" +#include "h261data.h" + +#define H261_MBA_VLC_BITS 9 +#define H261_MTYPE_VLC_BITS 6 +#define H261_MV_VLC_BITS 7 +#define H261_CBP_VLC_BITS 9 +#define TCOEFF_VLC_BITS 9 +#define MBA_STUFFING 33 +#define MBA_STARTCODE 34 + +extern uint8_t ff_h261_rl_table_store[2][2*MAX_RUN + MAX_LEVEL + 3]; + +static VLC h261_mba_vlc; +static VLC h261_mtype_vlc; +static VLC h261_mv_vlc; +static VLC h261_cbp_vlc; + +static int h261_decode_block(H261Context * h, DCTELEM * block, int n, int coded); + +static av_cold void h261_decode_init_vlc(H261Context *h){ + static int done = 0; + + if(!done){ + done = 1; + init_vlc(&h261_mba_vlc, H261_MBA_VLC_BITS, 35, + h261_mba_bits, 1, 1, + h261_mba_code, 1, 1, 1); + init_vlc(&h261_mtype_vlc, H261_MTYPE_VLC_BITS, 10, + h261_mtype_bits, 1, 1, + h261_mtype_code, 1, 1, 1); + init_vlc(&h261_mv_vlc, H261_MV_VLC_BITS, 17, + &h261_mv_tab[0][1], 2, 1, + &h261_mv_tab[0][0], 2, 1, 1); + init_vlc(&h261_cbp_vlc, H261_CBP_VLC_BITS, 63, + &h261_cbp_tab[0][1], 2, 1, + &h261_cbp_tab[0][0], 2, 1, 1); + init_rl(&h261_rl_tcoeff, ff_h261_rl_table_store); + INIT_VLC_RL(h261_rl_tcoeff, 552); + } +} + +static av_cold int h261_decode_init(AVCodecContext *avctx){ + H261Context *h= avctx->priv_data; + MpegEncContext * const s = &h->s; + + // set defaults + MPV_decode_defaults(s); + s->avctx = avctx; + + s->width = s->avctx->coded_width; + s->height = s->avctx->coded_height; + s->codec_id = s->avctx->codec->id; + + s->out_format = FMT_H261; + s->low_delay= 1; + avctx->pix_fmt= PIX_FMT_YUV420P; + + s->codec_id= avctx->codec->id; + + h261_decode_init_vlc(h); + + h->gob_start_code_skipped = 0; + + return 0; +} + +/** + * decodes the group of blocks header or slice header. + * @return <0 if an error occurred + */ +static int h261_decode_gob_header(H261Context *h){ + unsigned int val; + MpegEncContext * const s = &h->s; + + if ( !h->gob_start_code_skipped ){ + /* Check for GOB Start Code */ + val = show_bits(&s->gb, 15); + if(val) + return -1; + + /* We have a GBSC */ + skip_bits(&s->gb, 16); + } + + h->gob_start_code_skipped = 0; + + h->gob_number = get_bits(&s->gb, 4); /* GN */ + s->qscale = get_bits(&s->gb, 5); /* GQUANT */ + + /* Check if gob_number is valid */ + if (s->mb_height==18){ //cif + if ((h->gob_number<=0) || (h->gob_number>12)) + return -1; + } + else{ //qcif + if ((h->gob_number!=1) && (h->gob_number!=3) && (h->gob_number!=5)) + return -1; + } + + /* GEI */ + while (get_bits1(&s->gb) != 0) { + skip_bits(&s->gb, 8); + } + + if(s->qscale==0) { + av_log(s->avctx, AV_LOG_ERROR, "qscale has forbidden 0 value\n"); + if (s->avctx->error_resilience >= FF_ER_COMPLIANT) + return -1; + } + + // For the first transmitted macroblock in a GOB, MBA is the absolute address. For + // subsequent macroblocks, MBA is the difference between the absolute addresses of + // the macroblock and the last transmitted macroblock. + h->current_mba = 0; + h->mba_diff = 0; + + return 0; +} + +/** + * decodes the group of blocks / video packet header. + * @return <0 if no resync found + */ +static int ff_h261_resync(H261Context *h){ + MpegEncContext * const s = &h->s; + int left, ret; + + if ( h->gob_start_code_skipped ){ + ret= h261_decode_gob_header(h); + if(ret>=0) + return 0; + } + else{ + if(show_bits(&s->gb, 15)==0){ + ret= h261_decode_gob_header(h); + if(ret>=0) + return 0; + } + //OK, it is not where it is supposed to be ... + s->gb= s->last_resync_gb; + align_get_bits(&s->gb); + left= s->gb.size_in_bits - get_bits_count(&s->gb); + + for(;left>15+1+4+5; left-=8){ + if(show_bits(&s->gb, 15)==0){ + GetBitContext bak= s->gb; + + ret= h261_decode_gob_header(h); + if(ret>=0) + return 0; + + s->gb= bak; + } + skip_bits(&s->gb, 8); + } + } + + return -1; +} + +/** + * decodes skipped macroblocks + * @return 0 + */ +static int h261_decode_mb_skipped(H261Context *h, int mba1, int mba2 ) +{ + MpegEncContext * const s = &h->s; + int i; + + s->mb_intra = 0; + + for(i=mba1; imb_x= ((h->gob_number-1) % 2) * 11 + i % 11; + s->mb_y= ((h->gob_number-1) / 2) * 3 + i / 11; + xy = s->mb_x + s->mb_y * s->mb_stride; + ff_init_block_index(s); + ff_update_block_index(s); + + for(j=0;j<6;j++) + s->block_last_index[j] = -1; + + s->mv_dir = MV_DIR_FORWARD; + s->mv_type = MV_TYPE_16X16; + s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; + s->mv[0][0][0] = 0; + s->mv[0][0][1] = 0; + s->mb_skipped = 1; + h->mtype &= ~MB_TYPE_H261_FIL; + + MPV_decode_mb(s, s->block); + } + + return 0; +} + +static int decode_mv_component(GetBitContext *gb, int v){ + int mv_diff = get_vlc2(gb, h261_mv_vlc.table, H261_MV_VLC_BITS, 2); + + /* check if mv_diff is valid */ + if ( mv_diff < 0 ) + return v; + + mv_diff = mvmap[mv_diff]; + + if(mv_diff && !get_bits1(gb)) + mv_diff= -mv_diff; + + v += mv_diff; + if (v <=-16) v+= 32; + else if(v >= 16) v-= 32; + + return v; +} + +static int h261_decode_mb(H261Context *h){ + MpegEncContext * const s = &h->s; + int i, cbp, xy; + + cbp = 63; + // Read mba + do{ + h->mba_diff = get_vlc2(&s->gb, h261_mba_vlc.table, H261_MBA_VLC_BITS, 2); + + /* Check for slice end */ + /* NOTE: GOB can be empty (no MB data) or exist only of MBA_stuffing */ + if (h->mba_diff == MBA_STARTCODE){ // start code + h->gob_start_code_skipped = 1; + return SLICE_END; + } + } + while( h->mba_diff == MBA_STUFFING ); // stuffing + + if ( h->mba_diff < 0 ){ + if ( get_bits_count(&s->gb) + 7 >= s->gb.size_in_bits ) + return SLICE_END; + + av_log(s->avctx, AV_LOG_ERROR, "illegal mba at %d %d\n", s->mb_x, s->mb_y); + return SLICE_ERROR; + } + + h->mba_diff += 1; + h->current_mba += h->mba_diff; + + if ( h->current_mba > MBA_STUFFING ) + return SLICE_ERROR; + + s->mb_x= ((h->gob_number-1) % 2) * 11 + ((h->current_mba-1) % 11); + s->mb_y= ((h->gob_number-1) / 2) * 3 + ((h->current_mba-1) / 11); + xy = s->mb_x + s->mb_y * s->mb_stride; + ff_init_block_index(s); + ff_update_block_index(s); + + // Read mtype + h->mtype = get_vlc2(&s->gb, h261_mtype_vlc.table, H261_MTYPE_VLC_BITS, 2); + h->mtype = h261_mtype_map[h->mtype]; + + // Read mquant + if ( IS_QUANT ( h->mtype ) ){ + ff_set_qscale(s, get_bits(&s->gb, 5)); + } + + s->mb_intra = IS_INTRA4x4(h->mtype); + + // Read mv + if ( IS_16X16 ( h->mtype ) ){ + // Motion vector data is included for all MC macroblocks. MVD is obtained from the macroblock vector by subtracting the + // vector of the preceding macroblock. For this calculation the vector of the preceding macroblock is regarded as zero in the + // following three situations: + // 1) evaluating MVD for macroblocks 1, 12 and 23; + // 2) evaluating MVD for macroblocks in which MBA does not represent a difference of 1; + // 3) MTYPE of the previous macroblock was not MC. + if ( ( h->current_mba == 1 ) || ( h->current_mba == 12 ) || ( h->current_mba == 23 ) || + ( h->mba_diff != 1)) + { + h->current_mv_x = 0; + h->current_mv_y = 0; + } + + h->current_mv_x= decode_mv_component(&s->gb, h->current_mv_x); + h->current_mv_y= decode_mv_component(&s->gb, h->current_mv_y); + }else{ + h->current_mv_x = 0; + h->current_mv_y = 0; + } + + // Read cbp + if ( HAS_CBP( h->mtype ) ){ + cbp = get_vlc2(&s->gb, h261_cbp_vlc.table, H261_CBP_VLC_BITS, 2) + 1; + } + + if(s->mb_intra){ + s->current_picture.mb_type[xy]= MB_TYPE_INTRA; + goto intra; + } + + //set motion vectors + s->mv_dir = MV_DIR_FORWARD; + s->mv_type = MV_TYPE_16X16; + s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0; + s->mv[0][0][0] = h->current_mv_x * 2;//gets divided by 2 in motion compensation + s->mv[0][0][1] = h->current_mv_y * 2; + +intra: + /* decode each block */ + if(s->mb_intra || HAS_CBP(h->mtype)){ + s->dsp.clear_blocks(s->block[0]); + for (i = 0; i < 6; i++) { + if (h261_decode_block(h, s->block[i], i, cbp&32) < 0){ + return SLICE_ERROR; + } + cbp+=cbp; + } + }else{ + for (i = 0; i < 6; i++) + s->block_last_index[i]= -1; + } + + MPV_decode_mb(s, s->block); + + return SLICE_OK; +} + +/** + * decodes a macroblock + * @return <0 if an error occurred + */ +static int h261_decode_block(H261Context * h, DCTELEM * block, + int n, int coded) +{ + MpegEncContext * const s = &h->s; + int code, level, i, j, run; + RLTable *rl = &h261_rl_tcoeff; + const uint8_t *scan_table; + + // For the variable length encoding there are two code tables, one being used for + // the first transmitted LEVEL in INTER, INTER+MC and INTER+MC+FIL blocks, the second + // for all other LEVELs except the first one in INTRA blocks which is fixed length + // coded with 8 bits. + // NOTE: the two code tables only differ in one VLC so we handle that manually. + scan_table = s->intra_scantable.permutated; + if (s->mb_intra){ + /* DC coef */ + level = get_bits(&s->gb, 8); + // 0 (00000000b) and -128 (10000000b) are FORBIDDEN + if((level&0x7F) == 0){ + av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n", level, s->mb_x, s->mb_y); + return -1; + } + // The code 1000 0000 is not used, the reconstruction level of 1024 being coded as 1111 1111. + if (level == 255) + level = 128; + block[0] = level; + i = 1; + }else if(coded){ + // Run Level Code + // EOB Not possible for first level when cbp is available (that's why the table is different) + // 0 1 1s + // * * 0* + int check = show_bits(&s->gb, 2); + i = 0; + if ( check & 0x2 ){ + skip_bits(&s->gb, 2); + block[0] = ( check & 0x1 ) ? -1 : 1; + i = 1; + } + }else{ + i = 0; + } + if(!coded){ + s->block_last_index[n] = i - 1; + return 0; + } + for(;;){ + code = get_vlc2(&s->gb, rl->vlc.table, TCOEFF_VLC_BITS, 2); + if (code < 0){ + av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n", s->mb_x, s->mb_y); + return -1; + } + if (code == rl->n) { + /* escape */ + // The remaining combinations of (run, level) are encoded with a 20-bit word consisting of 6 bits escape, 6 bits run and 8 bits level. + run = get_bits(&s->gb, 6); + level = get_sbits(&s->gb, 8); + }else if(code == 0){ + break; + }else{ + run = rl->table_run[code]; + level = rl->table_level[code]; + if (get_bits1(&s->gb)) + level = -level; + } + i += run; + if (i >= 64){ + av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d\n", s->mb_x, s->mb_y); + return -1; + } + j = scan_table[i]; + block[j] = level; + i++; + } + s->block_last_index[n] = i-1; + return 0; +} + +/** + * decodes the H261 picture header. + * @return <0 if no startcode found + */ +static int h261_decode_picture_header(H261Context *h){ + MpegEncContext * const s = &h->s; + int format, i; + uint32_t startcode= 0; + + for(i= s->gb.size_in_bits - get_bits_count(&s->gb); i>24; i-=1){ + startcode = ((startcode << 1) | get_bits(&s->gb, 1)) & 0x000FFFFF; + + if(startcode == 0x10) + break; + } + + if (startcode != 0x10){ + av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n"); + return -1; + } + + /* temporal reference */ + i= get_bits(&s->gb, 5); /* picture timestamp */ + if(i < (s->picture_number&31)) + i += 32; + s->picture_number = (s->picture_number&~31) + i; + + s->avctx->time_base= (AVRational){1001, 30000}; + s->current_picture.pts= s->picture_number; + + + /* PTYPE starts here */ + skip_bits1(&s->gb); /* split screen off */ + skip_bits1(&s->gb); /* camera off */ + skip_bits1(&s->gb); /* freeze picture release off */ + + format = get_bits1(&s->gb); + + //only 2 formats possible + if (format == 0){//QCIF + s->width = 176; + s->height = 144; + s->mb_width = 11; + s->mb_height = 9; + }else{//CIF + s->width = 352; + s->height = 288; + s->mb_width = 22; + s->mb_height = 18; + } + + s->mb_num = s->mb_width * s->mb_height; + + skip_bits1(&s->gb); /* still image mode off */ + skip_bits1(&s->gb); /* Reserved */ + + /* PEI */ + while (get_bits1(&s->gb) != 0){ + skip_bits(&s->gb, 8); + } + + // h261 has no I-FRAMES, but if we pass FF_I_TYPE for the first frame, the codec crashes if it does + // not contain all I-blocks (e.g. when a packet is lost) + s->pict_type = FF_P_TYPE; + + h->gob_number = 0; + return 0; +} + +static int h261_decode_gob(H261Context *h){ + MpegEncContext * const s = &h->s; + + ff_set_qscale(s, s->qscale); + + /* decode mb's */ + while(h->current_mba <= MBA_STUFFING) + { + int ret; + /* DCT & quantize */ + ret= h261_decode_mb(h); + if(ret<0){ + if(ret==SLICE_END){ + h261_decode_mb_skipped(h, h->current_mba, 33); + return 0; + } + av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n", s->mb_x + s->mb_y*s->mb_stride); + return -1; + } + + h261_decode_mb_skipped(h, h->current_mba-h->mba_diff, h->current_mba-1); + } + + return -1; +} + +/** + * returns the number of bytes consumed for building the current frame + */ +static int get_consumed_bytes(MpegEncContext *s, int buf_size){ + int pos= get_bits_count(&s->gb)>>3; + if(pos==0) pos=1; //avoid infinite loops (i doubt that is needed but ...) + if(pos+10>buf_size) pos=buf_size; // oops ;) + + return pos; +} + +static int h261_decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + const uint8_t *buf, int buf_size) +{ + H261Context *h= avctx->priv_data; + MpegEncContext *s = &h->s; + int ret; + AVFrame *pict = data; + +#ifdef DEBUG + av_log(avctx, AV_LOG_DEBUG, "*****frame %d size=%d\n", avctx->frame_number, buf_size); + av_log(avctx, AV_LOG_DEBUG, "bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]); +#endif + s->flags= avctx->flags; + s->flags2= avctx->flags2; + + h->gob_start_code_skipped=0; + +retry: + + init_get_bits(&s->gb, buf, buf_size*8); + + if(!s->context_initialized){ + if (MPV_common_init(s) < 0) //we need the idct permutaton for reading a custom matrix + return -1; + } + + //we need to set current_picture_ptr before reading the header, otherwise we cannot store anyting im there + if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){ + int i= ff_find_unused_picture(s, 0); + s->current_picture_ptr= &s->picture[i]; + } + + ret = h261_decode_picture_header(h); + + /* skip if the header was thrashed */ + if (ret < 0){ + av_log(s->avctx, AV_LOG_ERROR, "header damaged\n"); + return -1; + } + + if (s->width != avctx->coded_width || s->height != avctx->coded_height){ + ParseContext pc= s->parse_context; //FIXME move this demuxing hack to libavformat + s->parse_context.buffer=0; + MPV_common_end(s); + s->parse_context= pc; + } + if (!s->context_initialized) { + avcodec_set_dimensions(avctx, s->width, s->height); + + goto retry; + } + + // for hurry_up==5 + s->current_picture.pict_type= s->pict_type; + s->current_picture.key_frame= s->pict_type == FF_I_TYPE; + + /* skip everything if we are in a hurry>=5 */ + if(avctx->hurry_up>=5) return get_consumed_bytes(s, buf_size); + if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==FF_B_TYPE) + ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=FF_I_TYPE) + || avctx->skip_frame >= AVDISCARD_ALL) + return get_consumed_bytes(s, buf_size); + + if(MPV_frame_start(s, avctx) < 0) + return -1; + + ff_er_frame_start(s); + [... truncated: 22418 lines follow ...] From dlmcpaul at mail.berlios.de Mon Sep 15 16:05:16 2008 From: dlmcpaul at mail.berlios.de (dlmcpaul at BerliOS) Date: Mon, 15 Sep 2008 16:05:16 +0200 Subject: [Haiku-commits] r27550 - in haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec: . i386 Message-ID: <200809151405.m8FE5Gl8000387@sheep.berlios.de> Author: dlmcpaul Date: 2008-09-15 16:04:59 +0200 (Mon, 15 Sep 2008) New Revision: 27550 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27550&view=rev Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/cavsdsp_mmx.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/cpuid.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/dsputil_h264_template_mmx.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/dsputil_h264_template_ssse3.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/dsputil_mmx.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/dsputil_mmx.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/dsputil_mmx_avg.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/dsputil_mmx_qns.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/dsputil_mmx_rnd.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/dsputil_yasm.asm haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/dsputilenc_mmx.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/fdct_mmx.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/fft_3dn.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/fft_3dn2.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/fft_mmx.asm haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/fft_sse.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/flacdsp_mmx.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/h264_i386.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/h264dsp_mmx.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/idct_mmx.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/idct_mmx_xvid.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/idct_sse2_xvid.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/idct_xvid.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/mathops.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/mmx.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/motion_est_mmx.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/mpegvideo_mmx.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/mpegvideo_mmx_template.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/simple_idct_mmx.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/snowdsp_mmx.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/vc1dsp_mmx.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/vp3dsp_mmx.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/vp3dsp_mmx.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/vp3dsp_sse2.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/vp3dsp_sse2.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/x86inc.asm haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/imc.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/imcdata.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/imgconvert.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/imx_dump_header_bsf.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/indeo2.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/indeo2data.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/intrax8.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/intrax8.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/intrax8dsp.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/intrax8huf.h Modified: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/idcinvideo.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/imgconvert.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/imgconvert_template.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/imgresample.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/indeo3.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/indeo3data.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/interplayvideo.c Log: Update avcodec to 20080825 Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/cavsdsp_mmx.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/cavsdsp_mmx.c 2008-09-15 14:04:37 UTC (rev 27549) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/cavsdsp_mmx.c 2008-09-15 14:04:59 UTC (rev 27550) @@ -0,0 +1,497 @@ +/* + * Chinese AVS video (AVS1-P2, JiZhun profile) decoder. + * Copyright (c) 2006 Stefan Gehrer + * + * MMX-optimized DSP functions, based on H.264 optimizations by + * Michael Niedermayer and Loren Merritt + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/common.h" +#include "libavutil/x86_cpu.h" +#include "libavcodec/dsputil.h" +#include "dsputil_mmx.h" + +/***************************************************************************** + * + * inverse transform + * + ****************************************************************************/ + +static inline void cavs_idct8_1d(int16_t *block, uint64_t bias) +{ + asm volatile( + "movq 112(%0), %%mm4 \n\t" /* mm4 = src7 */ + "movq 16(%0), %%mm5 \n\t" /* mm5 = src1 */ + "movq 80(%0), %%mm2 \n\t" /* mm2 = src5 */ + "movq 48(%0), %%mm7 \n\t" /* mm7 = src3 */ + "movq %%mm4, %%mm0 \n\t" + "movq %%mm5, %%mm3 \n\t" + "movq %%mm2, %%mm6 \n\t" + "movq %%mm7, %%mm1 \n\t" + + "paddw %%mm4, %%mm4 \n\t" /* mm4 = 2*src7 */ + "paddw %%mm3, %%mm3 \n\t" /* mm3 = 2*src1 */ + "paddw %%mm6, %%mm6 \n\t" /* mm6 = 2*src5 */ + "paddw %%mm1, %%mm1 \n\t" /* mm1 = 2*src3 */ + "paddw %%mm4, %%mm0 \n\t" /* mm0 = 3*src7 */ + "paddw %%mm3, %%mm5 \n\t" /* mm5 = 3*src1 */ + "paddw %%mm6, %%mm2 \n\t" /* mm2 = 3*src5 */ + "paddw %%mm1, %%mm7 \n\t" /* mm7 = 3*src3 */ + "psubw %%mm4, %%mm5 \n\t" /* mm5 = 3*src1 - 2*src7 = a0 */ + "paddw %%mm6, %%mm7 \n\t" /* mm7 = 3*src3 + 2*src5 = a1 */ + "psubw %%mm2, %%mm1 \n\t" /* mm1 = 2*src3 - 3*src5 = a2 */ + "paddw %%mm0, %%mm3 \n\t" /* mm3 = 2*src1 + 3*src7 = a3 */ + + "movq %%mm5, %%mm4 \n\t" + "movq %%mm7, %%mm6 \n\t" + "movq %%mm3, %%mm0 \n\t" + "movq %%mm1, %%mm2 \n\t" + SUMSUB_BA( %%mm7, %%mm5 ) /* mm7 = a0 + a1 mm5 = a0 - a1 */ + "paddw %%mm3, %%mm7 \n\t" /* mm7 = a0 + a1 + a3 */ + "paddw %%mm1, %%mm5 \n\t" /* mm5 = a0 - a1 + a2 */ + "paddw %%mm7, %%mm7 \n\t" + "paddw %%mm5, %%mm5 \n\t" + "paddw %%mm6, %%mm7 \n\t" /* mm7 = b4 */ + "paddw %%mm4, %%mm5 \n\t" /* mm5 = b5 */ + + SUMSUB_BA( %%mm1, %%mm3 ) /* mm1 = a3 + a2 mm3 = a3 - a2 */ + "psubw %%mm1, %%mm4 \n\t" /* mm4 = a0 - a2 - a3 */ + "movq %%mm4, %%mm1 \n\t" /* mm1 = a0 - a2 - a3 */ + "psubw %%mm6, %%mm3 \n\t" /* mm3 = a3 - a2 - a1 */ + "paddw %%mm1, %%mm1 \n\t" + "paddw %%mm3, %%mm3 \n\t" + "psubw %%mm2, %%mm1 \n\t" /* mm1 = b7 */ + "paddw %%mm0, %%mm3 \n\t" /* mm3 = b6 */ + + "movq 32(%0), %%mm2 \n\t" /* mm2 = src2 */ + "movq 96(%0), %%mm6 \n\t" /* mm6 = src6 */ + "movq %%mm2, %%mm4 \n\t" + "movq %%mm6, %%mm0 \n\t" + "psllw $2, %%mm4 \n\t" /* mm4 = 4*src2 */ + "psllw $2, %%mm6 \n\t" /* mm6 = 4*src6 */ + "paddw %%mm4, %%mm2 \n\t" /* mm2 = 5*src2 */ + "paddw %%mm6, %%mm0 \n\t" /* mm0 = 5*src6 */ + "paddw %%mm2, %%mm2 \n\t" + "paddw %%mm0, %%mm0 \n\t" + "psubw %%mm0, %%mm4 \n\t" /* mm4 = 4*src2 - 10*src6 = a7 */ + "paddw %%mm2, %%mm6 \n\t" /* mm6 = 4*src6 + 10*src2 = a6 */ + + "movq (%0), %%mm2 \n\t" /* mm2 = src0 */ + "movq 64(%0), %%mm0 \n\t" /* mm0 = src4 */ + SUMSUB_BA( %%mm0, %%mm2 ) /* mm0 = src0+src4 mm2 = src0-src4 */ + "psllw $3, %%mm0 \n\t" + "psllw $3, %%mm2 \n\t" + "paddw %1, %%mm0 \n\t" /* add rounding bias */ + "paddw %1, %%mm2 \n\t" /* add rounding bias */ + + SUMSUB_BA( %%mm6, %%mm0 ) /* mm6 = a4 + a6 mm0 = a4 - a6 */ + SUMSUB_BA( %%mm4, %%mm2 ) /* mm4 = a5 + a7 mm2 = a5 - a7 */ + SUMSUB_BA( %%mm7, %%mm6 ) /* mm7 = dst0 mm6 = dst7 */ + SUMSUB_BA( %%mm5, %%mm4 ) /* mm5 = dst1 mm4 = dst6 */ + SUMSUB_BA( %%mm3, %%mm2 ) /* mm3 = dst2 mm2 = dst5 */ + SUMSUB_BA( %%mm1, %%mm0 ) /* mm1 = dst3 mm0 = dst4 */ + :: "r"(block), "m"(bias) + ); +} + +static void cavs_idct8_add_mmx(uint8_t *dst, int16_t *block, int stride) +{ + int i; + DECLARE_ALIGNED_8(int16_t, b2[64]); + + for(i=0; i<2; i++){ + DECLARE_ALIGNED_8(uint64_t, tmp); + + cavs_idct8_1d(block+4*i, ff_pw_4); + + asm volatile( + "psraw $3, %%mm7 \n\t" + "psraw $3, %%mm6 \n\t" + "psraw $3, %%mm5 \n\t" + "psraw $3, %%mm4 \n\t" + "psraw $3, %%mm3 \n\t" + "psraw $3, %%mm2 \n\t" + "psraw $3, %%mm1 \n\t" + "psraw $3, %%mm0 \n\t" + "movq %%mm7, %0 \n\t" + TRANSPOSE4( %%mm0, %%mm2, %%mm4, %%mm6, %%mm7 ) + "movq %%mm0, 8(%1) \n\t" + "movq %%mm6, 24(%1) \n\t" + "movq %%mm7, 40(%1) \n\t" + "movq %%mm4, 56(%1) \n\t" + "movq %0, %%mm7 \n\t" + TRANSPOSE4( %%mm7, %%mm5, %%mm3, %%mm1, %%mm0 ) + "movq %%mm7, (%1) \n\t" + "movq %%mm1, 16(%1) \n\t" + "movq %%mm0, 32(%1) \n\t" + "movq %%mm3, 48(%1) \n\t" + : "=m"(tmp) + : "r"(b2+32*i) + : "memory" + ); + } + + for(i=0; i<2; i++){ + cavs_idct8_1d(b2+4*i, ff_pw_64); + + asm volatile( + "psraw $7, %%mm7 \n\t" + "psraw $7, %%mm6 \n\t" + "psraw $7, %%mm5 \n\t" + "psraw $7, %%mm4 \n\t" + "psraw $7, %%mm3 \n\t" + "psraw $7, %%mm2 \n\t" + "psraw $7, %%mm1 \n\t" + "psraw $7, %%mm0 \n\t" + "movq %%mm7, (%0) \n\t" + "movq %%mm5, 16(%0) \n\t" + "movq %%mm3, 32(%0) \n\t" + "movq %%mm1, 48(%0) \n\t" + "movq %%mm0, 64(%0) \n\t" + "movq %%mm2, 80(%0) \n\t" + "movq %%mm4, 96(%0) \n\t" + "movq %%mm6, 112(%0) \n\t" + :: "r"(b2+4*i) + : "memory" + ); + } + + add_pixels_clamped_mmx(b2, dst, stride); + + /* clear block */ + asm volatile( + "pxor %%mm7, %%mm7 \n\t" + "movq %%mm7, (%0) \n\t" + "movq %%mm7, 8(%0) \n\t" + "movq %%mm7, 16(%0) \n\t" + "movq %%mm7, 24(%0) \n\t" + "movq %%mm7, 32(%0) \n\t" + "movq %%mm7, 40(%0) \n\t" + "movq %%mm7, 48(%0) \n\t" + "movq %%mm7, 56(%0) \n\t" + "movq %%mm7, 64(%0) \n\t" + "movq %%mm7, 72(%0) \n\t" + "movq %%mm7, 80(%0) \n\t" + "movq %%mm7, 88(%0) \n\t" + "movq %%mm7, 96(%0) \n\t" + "movq %%mm7, 104(%0) \n\t" + "movq %%mm7, 112(%0) \n\t" + "movq %%mm7, 120(%0) \n\t" + :: "r" (block) + ); +} + +/***************************************************************************** + * + * motion compensation + * + ****************************************************************************/ + +/* vertical filter [-1 -2 96 42 -7 0] */ +#define QPEL_CAVSV1(A,B,C,D,E,F,OP) \ + "movd (%0), "#F" \n\t"\ + "movq "#C", %%mm6 \n\t"\ + "pmullw %5, %%mm6 \n\t"\ + "movq "#D", %%mm7 \n\t"\ + "pmullw %6, %%mm7 \n\t"\ + "psllw $3, "#E" \n\t"\ + "psubw "#E", %%mm6 \n\t"\ + "psraw $3, "#E" \n\t"\ + "paddw %%mm7, %%mm6 \n\t"\ + "paddw "#E", %%mm6 \n\t"\ + "paddw "#B", "#B" \n\t"\ + "pxor %%mm7, %%mm7 \n\t"\ + "add %2, %0 \n\t"\ + "punpcklbw %%mm7, "#F" \n\t"\ + "psubw "#B", %%mm6 \n\t"\ + "psraw $1, "#B" \n\t"\ + "psubw "#A", %%mm6 \n\t"\ + "paddw %4, %%mm6 \n\t"\ + "psraw $7, %%mm6 \n\t"\ + "packuswb %%mm6, %%mm6 \n\t"\ + OP(%%mm6, (%1), A, d) \ + "add %3, %1 \n\t" + +/* vertical filter [ 0 -1 5 5 -1 0] */ +#define QPEL_CAVSV2(A,B,C,D,E,F,OP) \ + "movd (%0), "#F" \n\t"\ + "movq "#C", %%mm6 \n\t"\ + "paddw "#D", %%mm6 \n\t"\ + "pmullw %5, %%mm6 \n\t"\ + "add %2, %0 \n\t"\ + "punpcklbw %%mm7, "#F" \n\t"\ + "psubw "#B", %%mm6 \n\t"\ + "psubw "#E", %%mm6 \n\t"\ + "paddw %4, %%mm6 \n\t"\ + "psraw $3, %%mm6 \n\t"\ + "packuswb %%mm6, %%mm6 \n\t"\ + OP(%%mm6, (%1), A, d) \ + "add %3, %1 \n\t" + +/* vertical filter [ 0 -7 42 96 -2 -1] */ +#define QPEL_CAVSV3(A,B,C,D,E,F,OP) \ + "movd (%0), "#F" \n\t"\ + "movq "#C", %%mm6 \n\t"\ + "pmullw %6, %%mm6 \n\t"\ + "movq "#D", %%mm7 \n\t"\ + "pmullw %5, %%mm7 \n\t"\ + "psllw $3, "#B" \n\t"\ + "psubw "#B", %%mm6 \n\t"\ + "psraw $3, "#B" \n\t"\ + "paddw %%mm7, %%mm6 \n\t"\ + "paddw "#B", %%mm6 \n\t"\ + "paddw "#E", "#E" \n\t"\ + "pxor %%mm7, %%mm7 \n\t"\ + "add %2, %0 \n\t"\ + "punpcklbw %%mm7, "#F" \n\t"\ + "psubw "#E", %%mm6 \n\t"\ + "psraw $1, "#E" \n\t"\ + "psubw "#F", %%mm6 \n\t"\ + "paddw %4, %%mm6 \n\t"\ + "psraw $7, %%mm6 \n\t"\ + "packuswb %%mm6, %%mm6 \n\t"\ + OP(%%mm6, (%1), A, d) \ + "add %3, %1 \n\t" + + +#define QPEL_CAVSVNUM(VOP,OP,ADD,MUL1,MUL2)\ + int w= 2;\ + src -= 2*srcStride;\ + \ + while(w--){\ + asm volatile(\ + "pxor %%mm7, %%mm7 \n\t"\ + "movd (%0), %%mm0 \n\t"\ + "add %2, %0 \n\t"\ + "movd (%0), %%mm1 \n\t"\ + "add %2, %0 \n\t"\ + "movd (%0), %%mm2 \n\t"\ + "add %2, %0 \n\t"\ + "movd (%0), %%mm3 \n\t"\ + "add %2, %0 \n\t"\ + "movd (%0), %%mm4 \n\t"\ + "add %2, %0 \n\t"\ + "punpcklbw %%mm7, %%mm0 \n\t"\ + "punpcklbw %%mm7, %%mm1 \n\t"\ + "punpcklbw %%mm7, %%mm2 \n\t"\ + "punpcklbw %%mm7, %%mm3 \n\t"\ + "punpcklbw %%mm7, %%mm4 \n\t"\ + VOP(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\ + VOP(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\ + VOP(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\ + VOP(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\ + VOP(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, OP)\ + VOP(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, OP)\ + VOP(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\ + VOP(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\ + \ + : "+a"(src), "+c"(dst)\ + : "S"((x86_reg)srcStride), "D"((x86_reg)dstStride), "m"(ADD), "m"(MUL1), "m"(MUL2)\ + : "memory"\ + );\ + if(h==16){\ + asm volatile(\ + VOP(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\ + VOP(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\ + VOP(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, OP)\ + VOP(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, OP)\ + VOP(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\ + VOP(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\ + VOP(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\ + VOP(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\ + \ + : "+a"(src), "+c"(dst)\ + : "S"((x86_reg)srcStride), "D"((x86_reg)dstStride), "m"(ADD), "m"(MUL1), "m"(MUL2)\ + : "memory"\ + );\ + }\ + src += 4-(h+5)*srcStride;\ + dst += 4-h*dstStride;\ + } + +#define QPEL_CAVS(OPNAME, OP, MMX)\ +static void OPNAME ## cavs_qpel8_h_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ + int h=8;\ + asm volatile(\ + "pxor %%mm7, %%mm7 \n\t"\ + "movq %5, %%mm6 \n\t"\ + "1: \n\t"\ + "movq (%0), %%mm0 \n\t"\ + "movq 1(%0), %%mm2 \n\t"\ + "movq %%mm0, %%mm1 \n\t"\ + "movq %%mm2, %%mm3 \n\t"\ + "punpcklbw %%mm7, %%mm0 \n\t"\ + "punpckhbw %%mm7, %%mm1 \n\t"\ + "punpcklbw %%mm7, %%mm2 \n\t"\ + "punpckhbw %%mm7, %%mm3 \n\t"\ + "paddw %%mm2, %%mm0 \n\t"\ + "paddw %%mm3, %%mm1 \n\t"\ + "pmullw %%mm6, %%mm0 \n\t"\ + "pmullw %%mm6, %%mm1 \n\t"\ + "movq -1(%0), %%mm2 \n\t"\ + "movq 2(%0), %%mm4 \n\t"\ + "movq %%mm2, %%mm3 \n\t"\ + "movq %%mm4, %%mm5 \n\t"\ + "punpcklbw %%mm7, %%mm2 \n\t"\ + "punpckhbw %%mm7, %%mm3 \n\t"\ + "punpcklbw %%mm7, %%mm4 \n\t"\ + "punpckhbw %%mm7, %%mm5 \n\t"\ + "paddw %%mm4, %%mm2 \n\t"\ + "paddw %%mm3, %%mm5 \n\t"\ + "psubw %%mm2, %%mm0 \n\t"\ + "psubw %%mm5, %%mm1 \n\t"\ + "movq %6, %%mm5 \n\t"\ + "paddw %%mm5, %%mm0 \n\t"\ + "paddw %%mm5, %%mm1 \n\t"\ + "psraw $3, %%mm0 \n\t"\ + "psraw $3, %%mm1 \n\t"\ + "packuswb %%mm1, %%mm0 \n\t"\ + OP(%%mm0, (%1),%%mm5, q) \ + "add %3, %0 \n\t"\ + "add %4, %1 \n\t"\ + "decl %2 \n\t"\ + " jnz 1b \n\t"\ + : "+a"(src), "+c"(dst), "+m"(h)\ + : "d"((x86_reg)srcStride), "S"((x86_reg)dstStride), "m"(ff_pw_5), "m"(ff_pw_4)\ + : "memory"\ + );\ +}\ +\ +static inline void OPNAME ## cavs_qpel8or16_v1_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\ + QPEL_CAVSVNUM(QPEL_CAVSV1,OP,ff_pw_64,ff_pw_96,ff_pw_42) \ +}\ +\ +static inline void OPNAME ## cavs_qpel8or16_v2_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\ + QPEL_CAVSVNUM(QPEL_CAVSV2,OP,ff_pw_4,ff_pw_5,ff_pw_5) \ +}\ +\ +static inline void OPNAME ## cavs_qpel8or16_v3_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\ + QPEL_CAVSVNUM(QPEL_CAVSV3,OP,ff_pw_64,ff_pw_96,ff_pw_42) \ +}\ +\ +static void OPNAME ## cavs_qpel8_v1_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ + OPNAME ## cavs_qpel8or16_v1_ ## MMX(dst , src , dstStride, srcStride, 8);\ +}\ +static void OPNAME ## cavs_qpel16_v1_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ + OPNAME ## cavs_qpel8or16_v1_ ## MMX(dst , src , dstStride, srcStride, 16);\ + OPNAME ## cavs_qpel8or16_v1_ ## MMX(dst+8, src+8, dstStride, srcStride, 16);\ +}\ +\ +static void OPNAME ## cavs_qpel8_v2_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ + OPNAME ## cavs_qpel8or16_v2_ ## MMX(dst , src , dstStride, srcStride, 8);\ +}\ +static void OPNAME ## cavs_qpel16_v2_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ + OPNAME ## cavs_qpel8or16_v2_ ## MMX(dst , src , dstStride, srcStride, 16);\ + OPNAME ## cavs_qpel8or16_v2_ ## MMX(dst+8, src+8, dstStride, srcStride, 16);\ +}\ +\ +static void OPNAME ## cavs_qpel8_v3_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ + OPNAME ## cavs_qpel8or16_v3_ ## MMX(dst , src , dstStride, srcStride, 8);\ +}\ +static void OPNAME ## cavs_qpel16_v3_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ + OPNAME ## cavs_qpel8or16_v3_ ## MMX(dst , src , dstStride, srcStride, 16);\ + OPNAME ## cavs_qpel8or16_v3_ ## MMX(dst+8, src+8, dstStride, srcStride, 16);\ +}\ +\ +static void OPNAME ## cavs_qpel16_h_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ + OPNAME ## cavs_qpel8_h_ ## MMX(dst , src , dstStride, srcStride);\ + OPNAME ## cavs_qpel8_h_ ## MMX(dst+8, src+8, dstStride, srcStride);\ + src += 8*srcStride;\ + dst += 8*dstStride;\ + OPNAME ## cavs_qpel8_h_ ## MMX(dst , src , dstStride, srcStride);\ + OPNAME ## cavs_qpel8_h_ ## MMX(dst+8, src+8, dstStride, srcStride);\ +}\ + +#define CAVS_MC(OPNAME, SIZE, MMX) \ +static void ff_ ## OPNAME ## cavs_qpel ## SIZE ## _mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ + OPNAME ## cavs_qpel ## SIZE ## _h_ ## MMX(dst, src, stride, stride);\ +}\ +\ +static void ff_ ## OPNAME ## cavs_qpel ## SIZE ## _mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ + OPNAME ## cavs_qpel ## SIZE ## _v1_ ## MMX(dst, src, stride, stride);\ +}\ +\ +static void ff_ ## OPNAME ## cavs_qpel ## SIZE ## _mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ + OPNAME ## cavs_qpel ## SIZE ## _v2_ ## MMX(dst, src, stride, stride);\ +}\ +\ +static void ff_ ## OPNAME ## cavs_qpel ## SIZE ## _mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ + OPNAME ## cavs_qpel ## SIZE ## _v3_ ## MMX(dst, src, stride, stride);\ +}\ + +#define PUT_OP(a,b,temp, size) "mov" #size " " #a ", " #b " \n\t" +#define AVG_3DNOW_OP(a,b,temp, size) \ +"mov" #size " " #b ", " #temp " \n\t"\ +"pavgusb " #temp ", " #a " \n\t"\ +"mov" #size " " #a ", " #b " \n\t" +#define AVG_MMX2_OP(a,b,temp, size) \ +"mov" #size " " #b ", " #temp " \n\t"\ +"pavgb " #temp ", " #a " \n\t"\ +"mov" #size " " #a ", " #b " \n\t" + +QPEL_CAVS(put_, PUT_OP, 3dnow) +QPEL_CAVS(avg_, AVG_3DNOW_OP, 3dnow) +QPEL_CAVS(put_, PUT_OP, mmx2) +QPEL_CAVS(avg_, AVG_MMX2_OP, mmx2) + +CAVS_MC(put_, 8, 3dnow) +CAVS_MC(put_, 16,3dnow) +CAVS_MC(avg_, 8, 3dnow) +CAVS_MC(avg_, 16,3dnow) +CAVS_MC(put_, 8, mmx2) +CAVS_MC(put_, 16,mmx2) +CAVS_MC(avg_, 8, mmx2) +CAVS_MC(avg_, 16,mmx2) + +void ff_put_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride); +void ff_avg_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride); +void ff_put_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride); +void ff_avg_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride); + +void ff_cavsdsp_init_mmx2(DSPContext* c, AVCodecContext *avctx) { +#define dspfunc(PFX, IDX, NUM) \ + c->PFX ## _pixels_tab[IDX][ 0] = ff_ ## PFX ## NUM ## _mc00_mmx2; \ + c->PFX ## _pixels_tab[IDX][ 2] = ff_ ## PFX ## NUM ## _mc20_mmx2; \ + c->PFX ## _pixels_tab[IDX][ 4] = ff_ ## PFX ## NUM ## _mc01_mmx2; \ + c->PFX ## _pixels_tab[IDX][ 8] = ff_ ## PFX ## NUM ## _mc02_mmx2; \ + c->PFX ## _pixels_tab[IDX][12] = ff_ ## PFX ## NUM ## _mc03_mmx2; \ + + dspfunc(put_cavs_qpel, 0, 16); + dspfunc(put_cavs_qpel, 1, 8); + dspfunc(avg_cavs_qpel, 0, 16); + dspfunc(avg_cavs_qpel, 1, 8); +#undef dspfunc + c->cavs_idct8_add = cavs_idct8_add_mmx; +} + +void ff_cavsdsp_init_3dnow(DSPContext* c, AVCodecContext *avctx) { +#define dspfunc(PFX, IDX, NUM) \ + c->PFX ## _pixels_tab[IDX][ 0] = ff_ ## PFX ## NUM ## _mc00_mmx2; \ + c->PFX ## _pixels_tab[IDX][ 2] = ff_ ## PFX ## NUM ## _mc20_3dnow; \ + c->PFX ## _pixels_tab[IDX][ 4] = ff_ ## PFX ## NUM ## _mc01_3dnow; \ + c->PFX ## _pixels_tab[IDX][ 8] = ff_ ## PFX ## NUM ## _mc02_3dnow; \ + c->PFX ## _pixels_tab[IDX][12] = ff_ ## PFX ## NUM ## _mc03_3dnow; \ + + dspfunc(put_cavs_qpel, 0, 16); + dspfunc(put_cavs_qpel, 1, 8); + dspfunc(avg_cavs_qpel, 0, 16); + dspfunc(avg_cavs_qpel, 1, 8); +#undef dspfunc + c->cavs_idct8_add = cavs_idct8_add_mmx; +} Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/cpuid.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/cpuid.c 2008-09-15 14:04:37 UTC (rev 27549) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/cpuid.c 2008-09-15 14:04:59 UTC (rev 27550) @@ -0,0 +1,127 @@ +/* + * CPU detection code, extracted from mmx.h + * (c)1997-99 by H. Dietz and R. Fisher + * Converted to C and improved by Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include "libavutil/x86_cpu.h" +#include "libavcodec/dsputil.h" + +#undef printf + +/* ebx saving is necessary for PIC. gcc seems unable to see it alone */ +#define cpuid(index,eax,ebx,ecx,edx)\ + asm volatile\ + ("mov %%"REG_b", %%"REG_S"\n\t"\ + "cpuid\n\t"\ + "xchg %%"REG_b", %%"REG_S\ + : "=a" (eax), "=S" (ebx),\ + "=c" (ecx), "=d" (edx)\ + : "0" (index)); + +/* Function to test if multimedia instructions are supported... */ +int mm_support(void) +{ + int rval = 0; + int eax, ebx, ecx, edx; + int max_std_level, max_ext_level, std_caps=0, ext_caps=0; + x86_reg a, c; + + asm volatile ( + /* See if CPUID instruction is supported ... */ + /* ... Get copies of EFLAGS into eax and ecx */ + "pushf\n\t" + "pop %0\n\t" + "mov %0, %1\n\t" + + /* ... Toggle the ID bit in one copy and store */ + /* to the EFLAGS reg */ + "xor $0x200000, %0\n\t" + "push %0\n\t" + "popf\n\t" + + /* ... Get the (hopefully modified) EFLAGS */ + "pushf\n\t" + "pop %0\n\t" + : "=a" (a), "=c" (c) + : + : "cc" + ); + + if (a == c) + return 0; /* CPUID not supported */ + + cpuid(0, max_std_level, ebx, ecx, edx); + + if(max_std_level >= 1){ + cpuid(1, eax, ebx, ecx, std_caps); + if (std_caps & (1<<23)) + rval |= FF_MM_MMX; + if (std_caps & (1<<25)) + rval |= FF_MM_MMXEXT +#if !defined(__GNUC__) || __GNUC__ > 2 + | FF_MM_SSE; + if (std_caps & (1<<26)) + rval |= FF_MM_SSE2; + if (ecx & 1) + rval |= FF_MM_SSE3; + if (ecx & 0x00000200 ) + rval |= FF_MM_SSSE3 +#endif + ; + } + + cpuid(0x80000000, max_ext_level, ebx, ecx, edx); + + if(max_ext_level >= 0x80000001){ + cpuid(0x80000001, eax, ebx, ecx, ext_caps); + if (ext_caps & (1<<31)) + rval |= FF_MM_3DNOW; + if (ext_caps & (1<<30)) + rval |= FF_MM_3DNOWEXT; + if (ext_caps & (1<<23)) + rval |= FF_MM_MMX; + if (ext_caps & (1<<22)) + rval |= FF_MM_MMXEXT; + } + +#if 0 + av_log(NULL, AV_LOG_DEBUG, "%s%s%s%s%s%s%s%s\n", + (rval&FF_MM_MMX) ? "MMX ":"", + (rval&FF_MM_MMXEXT) ? "MMX2 ":"", + (rval&FF_MM_SSE) ? "SSE ":"", + (rval&FF_MM_SSE2) ? "SSE2 ":"", + (rval&FF_MM_SSE3) ? "SSE3 ":"", + (rval&FF_MM_SSSE3) ? "SSSE3 ":"", + (rval&FF_MM_3DNOW) ? "3DNow ":"", + (rval&FF_MM_3DNOWEXT) ? "3DNowExt ":""); +#endif + return rval; +} + +#ifdef TEST +int main ( void ) +{ + int mm_flags; + mm_flags = mm_support(); + printf("mm_support = 0x%08X\n",mm_flags); + return 0; +} +#endif Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/dsputil_h264_template_mmx.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/dsputil_h264_template_mmx.c 2008-09-15 14:04:37 UTC (rev 27549) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/dsputil_h264_template_mmx.c 2008-09-15 14:04:59 UTC (rev 27550) @@ -0,0 +1,308 @@ +/* + * Copyright (c) 2005 Zoltan Hidvegi , + * Loren Merritt + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * MMX optimized version of (put|avg)_h264_chroma_mc8. + * H264_CHROMA_MC8_TMPL must be defined to the desired function name + * H264_CHROMA_OP must be defined to empty for put and pavgb/pavgusb for avg + * H264_CHROMA_MC8_MV0 must be defined to a (put|avg)_pixels8 function + */ +static void H264_CHROMA_MC8_TMPL(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y, int rnd) +{ + const uint64_t *rnd_reg; + DECLARE_ALIGNED_8(uint64_t, AA); + DECLARE_ALIGNED_8(uint64_t, DD); + int i; + + if(y==0 && x==0) { + /* no filter needed */ + H264_CHROMA_MC8_MV0(dst, src, stride, h); + return; + } + + assert(x<8 && y<8 && x>=0 && y>=0); + + if(y==0 || x==0) + { + /* 1 dimensional filter only */ + const int dxy = x ? 1 : stride; + + rnd_reg = rnd ? &ff_pw_4 : &ff_pw_3; + + asm volatile( + "movd %0, %%mm5\n\t" + "movq %1, %%mm4\n\t" + "movq %2, %%mm6\n\t" /* mm6 = rnd */ + "punpcklwd %%mm5, %%mm5\n\t" + "punpckldq %%mm5, %%mm5\n\t" /* mm5 = B = x */ + "pxor %%mm7, %%mm7\n\t" + "psubw %%mm5, %%mm4\n\t" /* mm4 = A = 8-x */ + :: "rm"(x+y), "m"(ff_pw_8), "m"(*rnd_reg)); + + for(i=0; i> 3 */ + "paddw %%mm6, %%mm0\n\t" + "paddw %%mm6, %%mm1\n\t" + "paddw %%mm2, %%mm0\n\t" + "paddw %%mm3, %%mm1\n\t" + "psrlw $3, %%mm0\n\t" + "psrlw $3, %%mm1\n\t" + "packuswb %%mm1, %%mm0\n\t" + H264_CHROMA_OP(%0, %%mm0) + "movq %%mm0, %0\n\t" + : "=m" (dst[0])); + + src += stride; + dst += stride; + } + return; + } + + /* general case, bilinear */ + rnd_reg = rnd ? &ff_pw_32.a : &ff_pw_28.a; + asm volatile("movd %2, %%mm4\n\t" + "movd %3, %%mm6\n\t" + "punpcklwd %%mm4, %%mm4\n\t" + "punpcklwd %%mm6, %%mm6\n\t" + "punpckldq %%mm4, %%mm4\n\t" /* mm4 = x words */ + "punpckldq %%mm6, %%mm6\n\t" /* mm6 = y words */ + "movq %%mm4, %%mm5\n\t" + "pmullw %%mm6, %%mm4\n\t" /* mm4 = x * y */ + "psllw $3, %%mm5\n\t" + "psllw $3, %%mm6\n\t" + "movq %%mm5, %%mm7\n\t" + "paddw %%mm6, %%mm7\n\t" + "movq %%mm4, %1\n\t" /* DD = x * y */ + "psubw %%mm4, %%mm5\n\t" /* mm5 = B = 8x - xy */ + "psubw %%mm4, %%mm6\n\t" /* mm6 = C = 8y - xy */ + "paddw %4, %%mm4\n\t" + "psubw %%mm7, %%mm4\n\t" /* mm4 = A = xy - (8x+8y) + 64 */ + "pxor %%mm7, %%mm7\n\t" + "movq %%mm4, %0\n\t" + : "=m" (AA), "=m" (DD) : "rm" (x), "rm" (y), "m" (ff_pw_64)); + + asm volatile( + /* mm0 = src[0..7], mm1 = src[1..8] */ + "movq %0, %%mm0\n\t" + "movq %1, %%mm1\n\t" + : : "m" (src[0]), "m" (src[1])); + + for(i=0; i> 6 */ + "paddw %1, %%mm2\n\t" + "paddw %1, %%mm3\n\t" + "psrlw $6, %%mm2\n\t" + "psrlw $6, %%mm3\n\t" + "packuswb %%mm3, %%mm2\n\t" + H264_CHROMA_OP(%0, %%mm2) + "movq %%mm2, %0\n\t" + : "=m" (dst[0]) : "m" (*rnd_reg)); + dst+= stride; + } +} + +static void H264_CHROMA_MC4_TMPL(uint8_t *dst/*align 4*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y) +{ + asm volatile( + "pxor %%mm7, %%mm7 \n\t" + "movd %5, %%mm2 \n\t" + "movd %6, %%mm3 \n\t" + "movq "MANGLE(ff_pw_8)", %%mm4\n\t" + "movq "MANGLE(ff_pw_8)", %%mm5\n\t" + "punpcklwd %%mm2, %%mm2 \n\t" + "punpcklwd %%mm3, %%mm3 \n\t" + "punpcklwd %%mm2, %%mm2 \n\t" + "punpcklwd %%mm3, %%mm3 \n\t" + "psubw %%mm2, %%mm4 \n\t" + "psubw %%mm3, %%mm5 \n\t" + + "movd (%1), %%mm0 \n\t" + "movd 1(%1), %%mm6 \n\t" + "add %3, %1 \n\t" + "punpcklbw %%mm7, %%mm0 \n\t" + "punpcklbw %%mm7, %%mm6 \n\t" + "pmullw %%mm4, %%mm0 \n\t" + "pmullw %%mm2, %%mm6 \n\t" + "paddw %%mm0, %%mm6 \n\t" + + "1: \n\t" + "movd (%1), %%mm0 \n\t" + "movd 1(%1), %%mm1 \n\t" + "add %3, %1 \n\t" + "punpcklbw %%mm7, %%mm0 \n\t" + "punpcklbw %%mm7, %%mm1 \n\t" + "pmullw %%mm4, %%mm0 \n\t" + "pmullw %%mm2, %%mm1 \n\t" + "paddw %%mm0, %%mm1 \n\t" + "movq %%mm1, %%mm0 \n\t" + "pmullw %%mm5, %%mm6 \n\t" + "pmullw %%mm3, %%mm1 \n\t" + "paddw %4, %%mm6 \n\t" + "paddw %%mm6, %%mm1 \n\t" + "psrlw $6, %%mm1 \n\t" + "packuswb %%mm1, %%mm1 \n\t" + H264_CHROMA_OP4((%0), %%mm1, %%mm6) + "movd %%mm1, (%0) \n\t" + "add %3, %0 \n\t" + "movd (%1), %%mm6 \n\t" + "movd 1(%1), %%mm1 \n\t" + "add %3, %1 \n\t" + "punpcklbw %%mm7, %%mm6 \n\t" + "punpcklbw %%mm7, %%mm1 \n\t" + "pmullw %%mm4, %%mm6 \n\t" + "pmullw %%mm2, %%mm1 \n\t" + "paddw %%mm6, %%mm1 \n\t" + "movq %%mm1, %%mm6 \n\t" + "pmullw %%mm5, %%mm0 \n\t" + "pmullw %%mm3, %%mm1 \n\t" + "paddw %4, %%mm0 \n\t" + "paddw %%mm0, %%mm1 \n\t" + "psrlw $6, %%mm1 \n\t" + "packuswb %%mm1, %%mm1 \n\t" + H264_CHROMA_OP4((%0), %%mm1, %%mm0) + "movd %%mm1, (%0) \n\t" + "add %3, %0 \n\t" + "sub $2, %2 \n\t" + "jnz 1b \n\t" + : "+r"(dst), "+r"(src), "+r"(h) + : "r"((x86_reg)stride), "m"(ff_pw_32), "m"(x), "m"(y) + ); +} + +#ifdef H264_CHROMA_MC2_TMPL +static void H264_CHROMA_MC2_TMPL(uint8_t *dst/*align 2*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y) +{ + int tmp = ((1<<16)-1)*x + 8; + int CD= tmp*y; + int AB= (tmp<<3) - CD; + asm volatile( + /* mm5 = {A,B,A,B} */ + /* mm6 = {C,D,C,D} */ + "movd %0, %%mm5\n\t" + "movd %1, %%mm6\n\t" + "punpckldq %%mm5, %%mm5\n\t" + "punpckldq %%mm6, %%mm6\n\t" + "pxor %%mm7, %%mm7\n\t" + /* mm0 = src[0,1,1,2] */ + "movd %2, %%mm2\n\t" + "punpcklbw %%mm7, %%mm2\n\t" + "pshufw $0x94, %%mm2, %%mm2\n\t" + :: "r"(AB), "r"(CD), "m"(src[0])); + + + asm volatile( + "1:\n\t" + "add %4, %1\n\t" + /* mm1 = A * src[0,1] + B * src[1,2] */ + "movq %%mm2, %%mm1\n\t" + "pmaddwd %%mm5, %%mm1\n\t" + /* mm0 = src[0,1,1,2] */ + "movd (%1), %%mm0\n\t" + "punpcklbw %%mm7, %%mm0\n\t" + "pshufw $0x94, %%mm0, %%mm0\n\t" + /* mm1 += C * src[0,1] + D * src[1,2] */ + "movq %%mm0, %%mm2\n\t" + "pmaddwd %%mm6, %%mm0\n\t" + "paddw %3, %%mm1\n\t" + "paddw %%mm0, %%mm1\n\t" + /* dst[0,1] = pack((mm1 + 32) >> 6) */ + "psrlw $6, %%mm1\n\t" + "packssdw %%mm7, %%mm1\n\t" + "packuswb %%mm7, %%mm1\n\t" + H264_CHROMA_OP4((%0), %%mm1, %%mm3) + "movd %%mm1, %%esi\n\t" + "movw %%si, (%0)\n\t" + "add %4, %0\n\t" + "sub $1, %2\n\t" + "jnz 1b\n\t" + : "+r" (dst), "+r"(src), "+r"(h) + : "m" (ff_pw_32), "r"((x86_reg)stride) + : "%esi"); + +} +#endif + Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/dsputil_h264_template_ssse3.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/dsputil_h264_template_ssse3.c 2008-09-15 14:04:37 UTC (rev 27549) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/i386/dsputil_h264_template_ssse3.c 2008-09-15 14:04:59 UTC (rev 27550) @@ -0,0 +1,208 @@ +/* + * Copyright (c) 2008 Loren Merritt + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * SSSE3 optimized version of (put|avg)_h264_chroma_mc8. + * H264_CHROMA_MC8_TMPL must be defined to the desired function name + * H264_CHROMA_MC8_MV0 must be defined to a (put|avg)_pixels8 function + * AVG_OP must be defined to empty for put and the identify for avg + */ +static void H264_CHROMA_MC8_TMPL(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y, int rnd) +{ + if(y==0 && x==0) { + /* no filter needed */ + H264_CHROMA_MC8_MV0(dst, src, stride, h); + return; + } + + assert(x<8 && y<8 && x>=0 && y>=0); + + if(y==0 || x==0) + { + /* 1 dimensional filter only */ + asm volatile( + "movd %0, %%xmm7 \n\t" + "movq %1, %%xmm6 \n\t" + "pshuflw $0, %%xmm7, %%xmm7 \n\t" + "movlhps %%xmm6, %%xmm6 \n\t" + "movlhps %%xmm7, %%xmm7 \n\t" [... truncated: 31269 lines follow ...] From dlmcpaul at mail.berlios.de Mon Sep 15 16:05:41 2008 From: dlmcpaul at mail.berlios.de (dlmcpaul at BerliOS) Date: Mon, 15 Sep 2008 16:05:41 +0200 Subject: [Haiku-commits] r27551 - haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec Message-ID: <200809151405.m8FE5fFf000445@sheep.berlios.de> Author: dlmcpaul Date: 2008-09-15 16:05:40 +0200 (Mon, 15 Sep 2008) New Revision: 27551 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27551&view=rev Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/jpegls.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/jpegls.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/jpeglsdec.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/jpeglsdec.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/jpeglsenc.c Modified: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/jfdctfst.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/jfdctint.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/jrevdct.c Log: Update avcodec to 20080825 Modified: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/jfdctfst.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/jfdctfst.c 2008-09-15 14:04:59 UTC (rev 27550) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/jfdctfst.c 2008-09-15 14:05:40 UTC (rev 27551) @@ -1,10 +1,43 @@ /* * jfdctfst.c * - * Copyright (C) 1994-1996, Thomas G. Lane. * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. * + * The authors make NO WARRANTY or representation, either express or implied, + * with respect to this software, its quality, accuracy, merchantability, or + * fitness for a particular purpose. This software is provided "AS IS", and + * you, its user, assume the entire risk as to its quality and accuracy. + * + * This software is copyright (C) 1994-1996, Thomas G. Lane. + * All Rights Reserved except as specified below. + * + * Permission is hereby granted to use, copy, modify, and distribute this + * software (or portions thereof) for any purpose, without fee, subject to + * these conditions: + * (1) If any part of the source code for this software is distributed, then + * this README file must be included, with this copyright and no-warranty + * notice unaltered; and any additions, deletions, or changes to the original + * files must be clearly indicated in accompanying documentation. + * (2) If only executable code is distributed, then the accompanying + * documentation must state that "this software is based in part on the work + * of the Independent JPEG Group". + * (3) Permission for use of this software is granted only if the user accepts + * full responsibility for any undesirable consequences; the authors accept + * NO LIABILITY for damages of any kind. + * + * These conditions apply to any software derived from or based on the IJG + * code, not just to the unmodified library. If you use our work, you ought + * to acknowledge us. + * + * Permission is NOT granted for the use of any IJG author's name or company + * name in advertising or publicity relating to this software or products + * derived from it. This software may be referred to only as "the Independent + * JPEG Group's software". + * + * We specifically permit and encourage the use of this software as the basis + * of commercial products, provided that all warranty or liability claims are + * assumed by the product vendor. + * * This file contains a fast, not so accurate integer implementation of the * forward DCT (Discrete Cosine Transform). * @@ -34,7 +67,7 @@ * @file jfdctfst.c * Independent JPEG Group's fast AAN dct. */ - + #include #include #include "common.h" @@ -83,10 +116,10 @@ */ #if CONST_BITS == 8 -#define FIX_0_382683433 ((int32_t) 98) /* FIX(0.382683433) */ -#define FIX_0_541196100 ((int32_t) 139) /* FIX(0.541196100) */ -#define FIX_0_707106781 ((int32_t) 181) /* FIX(0.707106781) */ -#define FIX_1_306562965 ((int32_t) 334) /* FIX(1.306562965) */ +#define FIX_0_382683433 ((int32_t) 98) /* FIX(0.382683433) */ +#define FIX_0_541196100 ((int32_t) 139) /* FIX(0.541196100) */ +#define FIX_0_707106781 ((int32_t) 181) /* FIX(0.707106781) */ +#define FIX_1_306562965 ((int32_t) 334) /* FIX(1.306562965) */ #else #define FIX_0_382683433 FIX(0.382683433) #define FIX_0_541196100 FIX(0.541196100) @@ -112,7 +145,7 @@ #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS)) -static always_inline void row_fdct(DCTELEM * data){ +static av_always_inline void row_fdct(DCTELEM * data){ int_fast16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; int_fast16_t tmp10, tmp11, tmp12, tmp13; int_fast16_t z1, z2, z3, z4, z5, z11, z13; @@ -132,42 +165,42 @@ tmp5 = dataptr[2] - dataptr[5]; tmp3 = dataptr[3] + dataptr[4]; tmp4 = dataptr[3] - dataptr[4]; - + /* Even part */ - - tmp10 = tmp0 + tmp3; /* phase 2 */ + + tmp10 = tmp0 + tmp3; /* phase 2 */ tmp13 = tmp0 - tmp3; tmp11 = tmp1 + tmp2; tmp12 = tmp1 - tmp2; - + dataptr[0] = tmp10 + tmp11; /* phase 3 */ dataptr[4] = tmp10 - tmp11; - + z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */ - dataptr[2] = tmp13 + z1; /* phase 5 */ + dataptr[2] = tmp13 + z1; /* phase 5 */ dataptr[6] = tmp13 - z1; - + /* Odd part */ - tmp10 = tmp4 + tmp5; /* phase 2 */ + tmp10 = tmp4 + tmp5; /* phase 2 */ tmp11 = tmp5 + tmp6; tmp12 = tmp6 + tmp7; /* The rotator is modified from fig 4-8 to avoid extra negations. */ z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */ - z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */ - z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */ - z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */ + z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */ + z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */ + z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */ - z11 = tmp7 + z3; /* phase 5 */ + z11 = tmp7 + z3; /* phase 5 */ z13 = tmp7 - z3; - dataptr[5] = z13 + z2; /* phase 6 */ + dataptr[5] = z13 + z2; /* phase 6 */ dataptr[3] = z13 - z2; dataptr[1] = z11 + z4; dataptr[7] = z11 - z4; - dataptr += DCTSIZE; /* advance pointer to next row */ + dataptr += DCTSIZE; /* advance pointer to next row */ } } @@ -186,7 +219,7 @@ SHIFT_TEMPS row_fdct(data); - + /* Pass 2: process columns. */ dataptr = data; @@ -199,24 +232,24 @@ tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5]; tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4]; tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4]; - + /* Even part */ - - tmp10 = tmp0 + tmp3; /* phase 2 */ + + tmp10 = tmp0 + tmp3; /* phase 2 */ tmp13 = tmp0 - tmp3; tmp11 = tmp1 + tmp2; tmp12 = tmp1 - tmp2; - + dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */ dataptr[DCTSIZE*4] = tmp10 - tmp11; - + z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */ dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */ dataptr[DCTSIZE*6] = tmp13 - z1; - + /* Odd part */ - tmp10 = tmp4 + tmp5; /* phase 2 */ + tmp10 = tmp4 + tmp5; /* phase 2 */ tmp11 = tmp5 + tmp6; tmp12 = tmp6 + tmp7; @@ -226,7 +259,7 @@ z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */ z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */ - z11 = tmp7 + z3; /* phase 5 */ + z11 = tmp7 + z3; /* phase 5 */ z13 = tmp7 - z3; dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */ @@ -234,7 +267,7 @@ dataptr[DCTSIZE*1] = z11 + z4; dataptr[DCTSIZE*7] = z11 - z4; - dataptr++; /* advance pointer to next column */ + dataptr++; /* advance pointer to next column */ } } @@ -253,7 +286,7 @@ SHIFT_TEMPS row_fdct(data); - + /* Pass 2: process columns. */ dataptr = data; @@ -268,15 +301,15 @@ tmp7 = dataptr[DCTSIZE*6] - dataptr[DCTSIZE*7]; /* Even part */ - + tmp10 = tmp0 + tmp3; tmp11 = tmp1 + tmp2; tmp12 = tmp1 - tmp2; tmp13 = tmp0 - tmp3; - + dataptr[DCTSIZE*0] = tmp10 + tmp11; dataptr[DCTSIZE*4] = tmp10 - tmp11; - + z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); dataptr[DCTSIZE*2] = tmp13 + z1; dataptr[DCTSIZE*6] = tmp13 - z1; @@ -285,15 +318,15 @@ tmp11 = tmp5 + tmp6; tmp12 = tmp5 - tmp6; tmp13 = tmp4 - tmp7; - + dataptr[DCTSIZE*1] = tmp10 + tmp11; dataptr[DCTSIZE*5] = tmp10 - tmp11; - + z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); dataptr[DCTSIZE*3] = tmp13 + z1; dataptr[DCTSIZE*7] = tmp13 - z1; - - dataptr++; /* advance pointer to next column */ + + dataptr++; /* advance pointer to next column */ } } Modified: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/jfdctint.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/jfdctint.c 2008-09-15 14:04:59 UTC (rev 27550) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/jfdctint.c 2008-09-15 14:05:40 UTC (rev 27551) @@ -1,10 +1,43 @@ /* * jfdctint.c * - * Copyright (C) 1991-1996, Thomas G. Lane. * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. * + * The authors make NO WARRANTY or representation, either express or implied, + * with respect to this software, its quality, accuracy, merchantability, or + * fitness for a particular purpose. This software is provided "AS IS", and + * you, its user, assume the entire risk as to its quality and accuracy. + * + * This software is copyright (C) 1991-1996, Thomas G. Lane. + * All Rights Reserved except as specified below. + * + * Permission is hereby granted to use, copy, modify, and distribute this + * software (or portions thereof) for any purpose, without fee, subject to + * these conditions: + * (1) If any part of the source code for this software is distributed, then + * this README file must be included, with this copyright and no-warranty + * notice unaltered; and any additions, deletions, or changes to the original + * files must be clearly indicated in accompanying documentation. + * (2) If only executable code is distributed, then the accompanying + * documentation must state that "this software is based in part on the work + * of the Independent JPEG Group". + * (3) Permission for use of this software is granted only if the user accepts + * full responsibility for any undesirable consequences; the authors accept + * NO LIABILITY for damages of any kind. + * + * These conditions apply to any software derived from or based on the IJG + * code, not just to the unmodified library. If you use our work, you ought + * to acknowledge us. + * + * Permission is NOT granted for the use of any IJG author's name or company + * name in advertising or publicity relating to this software or products + * derived from it. This software may be referred to only as "the Independent + * JPEG Group's software". + * + * We specifically permit and encourage the use of this software as the basis + * of commercial products, provided that all warranty or liability claims are + * assumed by the product vendor. + * * This file contains a slow-but-accurate integer implementation of the * forward DCT (Discrete Cosine Transform). * @@ -27,7 +60,7 @@ * @file jfdctint.c * Independent JPEG Group's slow & accurate dct. */ - + #include #include #include "common.h" @@ -92,10 +125,10 @@ #if BITS_IN_JSAMPLE == 8 #define CONST_BITS 13 -#define PASS1_BITS 4 /* set this to 2 if 16x16 multiplies are faster */ +#define PASS1_BITS 4 /* set this to 2 if 16x16 multiplies are faster */ #else #define CONST_BITS 13 -#define PASS1_BITS 1 /* lose a little precision to avoid overflow */ +#define PASS1_BITS 1 /* lose a little precision to avoid overflow */ #endif /* Some C compilers fail to reduce "FIX(constant)" at compile time, thus @@ -106,18 +139,18 @@ */ #if CONST_BITS == 13 -#define FIX_0_298631336 ((int32_t) 2446) /* FIX(0.298631336) */ -#define FIX_0_390180644 ((int32_t) 3196) /* FIX(0.390180644) */ -#define FIX_0_541196100 ((int32_t) 4433) /* FIX(0.541196100) */ -#define FIX_0_765366865 ((int32_t) 6270) /* FIX(0.765366865) */ -#define FIX_0_899976223 ((int32_t) 7373) /* FIX(0.899976223) */ -#define FIX_1_175875602 ((int32_t) 9633) /* FIX(1.175875602) */ -#define FIX_1_501321110 ((int32_t) 12299) /* FIX(1.501321110) */ -#define FIX_1_847759065 ((int32_t) 15137) /* FIX(1.847759065) */ -#define FIX_1_961570560 ((int32_t) 16069) /* FIX(1.961570560) */ -#define FIX_2_053119869 ((int32_t) 16819) /* FIX(2.053119869) */ -#define FIX_2_562915447 ((int32_t) 20995) /* FIX(2.562915447) */ -#define FIX_3_072711026 ((int32_t) 25172) /* FIX(3.072711026) */ +#define FIX_0_298631336 ((int32_t) 2446) /* FIX(0.298631336) */ +#define FIX_0_390180644 ((int32_t) 3196) /* FIX(0.390180644) */ +#define FIX_0_541196100 ((int32_t) 4433) /* FIX(0.541196100) */ +#define FIX_0_765366865 ((int32_t) 6270) /* FIX(0.765366865) */ +#define FIX_0_899976223 ((int32_t) 7373) /* FIX(0.899976223) */ +#define FIX_1_175875602 ((int32_t) 9633) /* FIX(1.175875602) */ +#define FIX_1_501321110 ((int32_t) 12299) /* FIX(1.501321110) */ +#define FIX_1_847759065 ((int32_t) 15137) /* FIX(1.847759065) */ +#define FIX_1_961570560 ((int32_t) 16069) /* FIX(1.961570560) */ +#define FIX_2_053119869 ((int32_t) 16819) /* FIX(2.053119869) */ +#define FIX_2_562915447 ((int32_t) 20995) /* FIX(2.562915447) */ +#define FIX_3_072711026 ((int32_t) 25172) /* FIX(3.072711026) */ #else #define FIX_0_298631336 FIX(0.298631336) #define FIX_0_390180644 FIX(0.390180644) @@ -148,7 +181,7 @@ #endif -static always_inline void row_fdct(DCTELEM * data){ +static av_always_inline void row_fdct(DCTELEM * data){ int_fast32_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; int_fast32_t tmp10, tmp11, tmp12, tmp13; int_fast32_t z1, z2, z3, z4, z5; @@ -170,36 +203,36 @@ tmp5 = dataptr[2] - dataptr[5]; tmp3 = dataptr[3] + dataptr[4]; tmp4 = dataptr[3] - dataptr[4]; - + /* Even part per LL&M figure 1 --- note that published figure is faulty; * rotator "sqrt(2)*c1" should be "sqrt(2)*c6". */ - + tmp10 = tmp0 + tmp3; tmp13 = tmp0 - tmp3; tmp11 = tmp1 + tmp2; tmp12 = tmp1 - tmp2; - + dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS); dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS); - + z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865), - CONST_BITS-PASS1_BITS); + CONST_BITS-PASS1_BITS); dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065), - CONST_BITS-PASS1_BITS); - + CONST_BITS-PASS1_BITS); + /* Odd part per figure 8 --- note paper omits factor of sqrt(2). * cK represents cos(K*pi/16). * i0..i3 in the paper are tmp4..tmp7 here. */ - + z1 = tmp4 + tmp7; z2 = tmp5 + tmp6; z3 = tmp4 + tmp6; z4 = tmp5 + tmp7; z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */ - + tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */ tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ @@ -208,16 +241,16 @@ z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */ - + z3 += z5; z4 += z5; - + dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS); dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS); dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS); dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS); - - dataptr += DCTSIZE; /* advance pointer to next row */ + + dataptr += DCTSIZE; /* advance pointer to next row */ } } @@ -252,36 +285,36 @@ tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5]; tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4]; tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4]; - + /* Even part per LL&M figure 1 --- note that published figure is faulty; * rotator "sqrt(2)*c1" should be "sqrt(2)*c6". */ - + tmp10 = tmp0 + tmp3; tmp13 = tmp0 - tmp3; tmp11 = tmp1 + tmp2; tmp12 = tmp1 - tmp2; - + dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS); dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS); - + z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865), - CONST_BITS+PASS1_BITS); + CONST_BITS+PASS1_BITS); dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065), - CONST_BITS+PASS1_BITS); - + CONST_BITS+PASS1_BITS); + /* Odd part per figure 8 --- note paper omits factor of sqrt(2). * cK represents cos(K*pi/16). * i0..i3 in the paper are tmp4..tmp7 here. */ - + z1 = tmp4 + tmp7; z2 = tmp5 + tmp6; z3 = tmp4 + tmp6; z4 = tmp5 + tmp7; z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */ - + tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */ tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ @@ -290,20 +323,20 @@ z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */ - + z3 += z5; z4 += z5; - + dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, - CONST_BITS+PASS1_BITS); + CONST_BITS+PASS1_BITS); dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, - CONST_BITS+PASS1_BITS); + CONST_BITS+PASS1_BITS); dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, - CONST_BITS+PASS1_BITS); + CONST_BITS+PASS1_BITS); dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, - CONST_BITS+PASS1_BITS); - - dataptr++; /* advance pointer to next column */ + CONST_BITS+PASS1_BITS); + + dataptr++; /* advance pointer to next column */ } } @@ -339,20 +372,20 @@ tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*3]; tmp6 = dataptr[DCTSIZE*4] - dataptr[DCTSIZE*5]; tmp7 = dataptr[DCTSIZE*6] - dataptr[DCTSIZE*7]; - + tmp10 = tmp0 + tmp3; tmp11 = tmp1 + tmp2; tmp12 = tmp1 - tmp2; tmp13 = tmp0 - tmp3; - + dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS); dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS); - + z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865), - CONST_BITS+PASS1_BITS); + CONST_BITS+PASS1_BITS); dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065), - CONST_BITS+PASS1_BITS); + CONST_BITS+PASS1_BITS); tmp10 = tmp4 + tmp7; tmp11 = tmp5 + tmp6; @@ -361,13 +394,13 @@ dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS); dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS); - + z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865), - CONST_BITS+PASS1_BITS); + CONST_BITS+PASS1_BITS); dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065), - CONST_BITS+PASS1_BITS); - - dataptr++; /* advance pointer to next column */ + CONST_BITS+PASS1_BITS); + + dataptr++; /* advance pointer to next column */ } } Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/jpegls.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/jpegls.c 2008-09-15 14:04:59 UTC (rev 27550) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/jpegls.c 2008-09-15 14:05:40 UTC (rev 27551) @@ -0,0 +1,89 @@ +/* + * JPEG-LS common code + * Copyright (c) 2003 Michael Niedermayer + * Copyright (c) 2006 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file jpegls.c + * JPEG-LS common code. + */ + +#include "jpegls.h" + +void ff_jpegls_init_state(JLSState *state){ + int i; + + state->twonear = state->near * 2 + 1; + state->range = ((state->maxval + state->twonear - 1) / state->twonear) + 1; + + // QBPP = ceil(log2(RANGE)) + for(state->qbpp = 0; (1 << state->qbpp) < state->range; state->qbpp++); + + if(state->bpp < 8) + state->limit = 16 + 2 * state->bpp - state->qbpp; + else + state->limit = (4 * state->bpp) - state->qbpp; + + for(i = 0; i < 367; i++) { + state->A[i] = FFMAX((state->range + 32) >> 6, 2); + state->N[i] = 1; + } + +} + +/** + * Custom value clipping function used in T1, T2, T3 calculation + */ +static inline int iso_clip(int v, int vmin, int vmax){ + if(v > vmax || v < vmin) return vmin; + else return v; +} + +void ff_jpegls_reset_coding_parameters(JLSState *s, int reset_all){ + const int basic_t1= 3; + const int basic_t2= 7; + const int basic_t3= 21; + int factor; + + if(s->maxval==0 || reset_all) s->maxval= (1 << s->bpp) - 1; + + if(s->maxval >=128){ + factor= (FFMIN(s->maxval, 4095) + 128)>>8; + + if(s->T1==0 || reset_all) + s->T1= iso_clip(factor*(basic_t1-2) + 2 + 3*s->near, s->near+1, s->maxval); + if(s->T2==0 || reset_all) + s->T2= iso_clip(factor*(basic_t2-3) + 3 + 5*s->near, s->T1, s->maxval); + if(s->T3==0 || reset_all) + s->T3= iso_clip(factor*(basic_t3-4) + 4 + 7*s->near, s->T2, s->maxval); + }else{ + factor= 256 / (s->maxval + 1); + + if(s->T1==0 || reset_all) + s->T1= iso_clip(FFMAX(2, basic_t1/factor + 3*s->near), s->near+1, s->maxval); + if(s->T2==0 || reset_all) + s->T2= iso_clip(FFMAX(3, basic_t2/factor + 5*s->near), s->T1, s->maxval); + if(s->T3==0 || reset_all) + s->T3= iso_clip(FFMAX(4, basic_t3/factor + 7*s->near), s->T2, s->maxval); + } + + if(s->reset==0 || reset_all) s->reset= 64; +// av_log(NULL, AV_LOG_DEBUG, "[JPEG-LS RESET] T=%i,%i,%i\n", s->T1, s->T2, s->T3); +} Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/jpegls.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/jpegls.h 2008-09-15 14:04:59 UTC (rev 27550) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/jpegls.h 2008-09-15 14:05:40 UTC (rev 27551) @@ -0,0 +1,111 @@ +/* + * JPEG-LS common code + * Copyright (c) 2003 Michael Niedermayer + * Copyright (c) 2006 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file jpegls.h + * JPEG-LS common code. + */ + +#ifndef FFMPEG_JPEGLS_H +#define FFMPEG_JPEGLS_H + +#include "avcodec.h" + +typedef struct JpeglsContext{ + AVCodecContext *avctx; + AVFrame picture; +}JpeglsContext; + +typedef struct JLSState{ + int T1, T2, T3; + int A[367], B[367], C[365], N[367]; + int limit, reset, bpp, qbpp, maxval, range; + int near, twonear; + int run_index[3]; +}JLSState; + +extern const uint8_t ff_log2_run[32]; + +/** + * Calculate initial JPEG-LS parameters + */ +void ff_jpegls_init_state(JLSState *state); + +/** + * Calculate quantized gradient value, used for context determination + */ +static inline int ff_jpegls_quantize(JLSState *s, int v){ //FIXME optimize + if(v==0) return 0; + if(v < 0){ + if(v <= -s->T3) return -4; + if(v <= -s->T2) return -3; + if(v <= -s->T1) return -2; + if(v < -s->near) return -1; + return 0; + }else{ + if(v <= s->near) return 0; + if(v < s->T1) return 1; + if(v < s->T2) return 2; + if(v < s->T3) return 3; + return 4; + } +} + +/** + * Calculate JPEG-LS codec values + */ +void ff_jpegls_reset_coding_parameters(JLSState *s, int reset_all); + + +static inline void ff_jpegls_downscale_state(JLSState *state, int Q){ + if(state->N[Q] == state->reset){ + state->A[Q] >>=1; + state->B[Q] >>=1; + state->N[Q] >>=1; + } + state->N[Q]++; +} + +static inline int ff_jpegls_update_state_regular(JLSState *state, int Q, int err){ + state->A[Q] += FFABS(err); + err *= state->twonear; + state->B[Q] += err; + + ff_jpegls_downscale_state(state, Q); + + if(state->B[Q] <= -state->N[Q]) { + state->B[Q]= FFMAX(state->B[Q] + state->N[Q], 1-state->N[Q]); + if(state->C[Q] > -128) + state->C[Q]--; + }else if(state->B[Q] > 0){ + state->B[Q]= FFMIN(state->B[Q] - state->N[Q], 0); + if(state->C[Q] < 127) + state->C[Q]++; + } + + return err; +} + +#define R(a, i ) (bits == 8 ? ((uint8_t*)(a))[i] : ((uint16_t*)(a))[i] ) +#define W(a, i, v) (bits == 8 ? (((uint8_t*)(a))[i]=v) : (((uint16_t*)(a))[i]=v)) + +#endif /* FFMPEG_JPEGLS_H */ Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/jpeglsdec.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/jpeglsdec.c 2008-09-15 14:04:59 UTC (rev 27550) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/jpeglsdec.c 2008-09-15 14:05:40 UTC (rev 27551) @@ -0,0 +1,376 @@ +/* + * JPEG-LS decoder + * Copyright (c) 2003 Michael Niedermayer + * Copyright (c) 2006 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file jpeglsdec.c + * JPEG-LS decoder. + */ + +#include "avcodec.h" +#include "bitstream.h" +#include "golomb.h" +#include "mjpeg.h" +#include "mjpegdec.h" +#include "jpegls.h" +#include "jpeglsdec.h" + + +/* +* Uncomment this to significantly speed up decoding of broken JPEG-LS +* (or test broken JPEG-LS decoder) and slow down ordinary decoding a bit. +* +* There is no Golomb code with length >= 32 bits possible, so check and +* avoid situation of 32 zeros, FFmpeg Golomb decoder is painfully slow +* on this errors. +*/ +//#define JLS_BROKEN + + +/** + * Decode LSE block with initialization parameters + */ +int ff_jpegls_decode_lse(MJpegDecodeContext *s) +{ + int len, id; + + /* XXX: verify len field validity */ + len = get_bits(&s->gb, 16); + id = get_bits(&s->gb, 8); + + switch(id){ + case 1: + s->maxval= get_bits(&s->gb, 16); + s->t1= get_bits(&s->gb, 16); + s->t2= get_bits(&s->gb, 16); + s->t3= get_bits(&s->gb, 16); + s->reset= get_bits(&s->gb, 16); + +// ff_jpegls_reset_coding_parameters(s, 0); + //FIXME quant table? + break; + case 2: + case 3: + av_log(s->avctx, AV_LOG_ERROR, "palette not supported\n"); + return -1; + case 4: + av_log(s->avctx, AV_LOG_ERROR, "oversize image not supported\n"); + return -1; + default: + av_log(s->avctx, AV_LOG_ERROR, "invalid id %d\n", id); + return -1; + } +// av_log(s->avctx, AV_LOG_DEBUG, "ID=%i, T=%i,%i,%i\n", id, s->t1, s->t2, s->t3); + + return 0; +} + +/** + * Get context-dependent Golomb code, decode it and update context + */ +static inline int ls_get_code_regular(GetBitContext *gb, JLSState *state, int Q){ + int k, ret; + + for(k = 0; (state->N[Q] << k) < state->A[Q]; k++); + +#ifdef JLS_BROKEN + if(!show_bits_long(gb, 32))return -1; +#endif + ret = get_ur_golomb_jpegls(gb, k, state->limit, state->qbpp); + + /* decode mapped error */ + if(ret & 1) + ret = -((ret + 1) >> 1); + else + ret >>= 1; + + /* for NEAR=0, k=0 and 2*B[Q] <= - N[Q] mapping is reversed */ + if(!state->near && !k && (2 * state->B[Q] <= -state->N[Q])) + ret = -(ret + 1); + + ret= ff_jpegls_update_state_regular(state, Q, ret); + + return ret; +} + +/** + * Get Golomb code, decode it and update state for run termination + */ +static inline int ls_get_code_runterm(GetBitContext *gb, JLSState *state, int RItype, int limit_add){ + int k, ret, temp, map; + int Q = 365 + RItype; + + temp= state->A[Q]; + if(RItype) + temp += state->N[Q] >> 1; + + for(k = 0; (state->N[Q] << k) < temp; k++); + +#ifdef JLS_BROKEN + if(!show_bits_long(gb, 32))return -1; +#endif + ret = get_ur_golomb_jpegls(gb, k, state->limit - limit_add - 1, state->qbpp); + + /* decode mapped error */ + map = 0; + if(!k && (RItype || ret) && (2 * state->B[Q] < state->N[Q])) + map = 1; + ret += RItype + map; + + if(ret & 1){ + ret = map - ((ret + 1) >> 1); + state->B[Q]++; + } else { + ret = ret >> 1; + } + + /* update state */ + state->A[Q] += FFABS(ret) - RItype; + ret *= state->twonear; + ff_jpegls_downscale_state(state, Q); + + return ret; +} + +/** + * Decode one line of image + */ +static inline void ls_decode_line(JLSState *state, MJpegDecodeContext *s, void *last, void *dst, int last2, int w, int stride, int comp, int bits){ + int i, x = 0; + int Ra, Rb, Rc, Rd; + int D0, D1, D2; + + while(x < w) { + int err, pred; + + /* compute gradients */ + Ra = x ? R(dst, x - stride) : R(last, x); + Rb = R(last, x); + Rc = x ? R(last, x - stride) : last2; + Rd = (x >= w - stride) ? R(last, x) : R(last, x + stride); + D0 = Rd - Rb; + D1 = Rb - Rc; + D2 = Rc - Ra; + /* run mode */ + if((FFABS(D0) <= state->near) && (FFABS(D1) <= state->near) && (FFABS(D2) <= state->near)) { + int r; + int RItype; + + /* decode full runs while available */ + while(get_bits1(&s->gb)) { + int r; + r = 1 << ff_log2_run[state->run_index[comp]]; + if(x + r * stride > w) { + r = (w - x) / stride; + } + for(i = 0; i < r; i++) { + W(dst, x, Ra); + x += stride; + } + /* if EOL reached, we stop decoding */ + if(r != (1 << ff_log2_run[state->run_index[comp]])) + return; + if(state->run_index[comp] < 31) + state->run_index[comp]++; + if(x + stride > w) + return; + } + /* decode aborted run */ + r = ff_log2_run[state->run_index[comp]]; + if(r) + r = get_bits_long(&s->gb, r); + for(i = 0; i < r; i++) { + W(dst, x, Ra); + x += stride; + } + + /* decode run termination value */ + Rb = R(last, x); + RItype = (FFABS(Ra - Rb) <= state->near) ? 1 : 0; + err = ls_get_code_runterm(&s->gb, state, RItype, ff_log2_run[state->run_index[comp]]); + if(state->run_index[comp]) + state->run_index[comp]--; + + if(state->near && RItype){ + pred = Ra + err; + } else { + if(Rb < Ra) + pred = Rb - err; + else + pred = Rb + err; + } + } else { /* regular mode */ + int context, sign; + + context = ff_jpegls_quantize(state, D0) * 81 + ff_jpegls_quantize(state, D1) * 9 + ff_jpegls_quantize(state, D2); + pred = mid_pred(Ra, Ra + Rb - Rc, Rb); + + if(context < 0){ + context = -context; + sign = 1; + }else{ + sign = 0; + } + + if(sign){ + pred = av_clip(pred - state->C[context], 0, state->maxval); + err = -ls_get_code_regular(&s->gb, state, context); [... truncated: 2447 lines follow ...] From dlmcpaul at mail.berlios.de Mon Sep 15 16:07:07 2008 From: dlmcpaul at mail.berlios.de (dlmcpaul at BerliOS) Date: Mon, 15 Sep 2008 16:07:07 +0200 Subject: [Haiku-commits] r27552 - haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec Message-ID: <200809151407.m8FE77qS000556@sheep.berlios.de> Author: dlmcpaul Date: 2008-09-15 16:07:05 +0200 (Mon, 15 Sep 2008) New Revision: 27552 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=27552&view=rev Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/w32thread.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/wavpack.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/wma.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/wma.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/wmaenc.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/wmv2.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/wmv2dec.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/wmv2enc.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/wnv1.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/ws-snd1.c Modified: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/wmadata.h haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/wmadec.c haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/wmv2.c Log: Update avcodec to 20080825 Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/w32thread.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/w32thread.c 2008-09-15 14:05:40 UTC (rev 27551) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/w32thread.c 2008-09-15 14:07:05 UTC (rev 27552) @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2004 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +//#define DEBUG + +#include "avcodec.h" + +#define WIN32_LEAN_AND_MEAN +#include +#include + +typedef struct ThreadContext{ + AVCodecContext *avctx; + HANDLE thread; + HANDLE work_sem; + HANDLE done_sem; + int (*func)(AVCodecContext *c, void *arg); + void *arg; + int ret; +}ThreadContext; + + +static unsigned WINAPI attribute_align_arg thread_func(void *v){ + ThreadContext *c= v; + + for(;;){ +//printf("thread_func %X enter wait\n", (int)v); fflush(stdout); + WaitForSingleObject(c->work_sem, INFINITE); +//printf("thread_func %X after wait (func=%X)\n", (int)v, (int)c->func); fflush(stdout); + if(c->func) + c->ret= c->func(c->avctx, c->arg); + else + return 0; +//printf("thread_func %X signal complete\n", (int)v); fflush(stdout); + ReleaseSemaphore(c->done_sem, 1, 0); + } + + return 0; +} + +/** + * Free what has been allocated by avcodec_thread_init(). + * Must be called after decoding has finished, especially do not call while avcodec_thread_execute() is running. + */ +void avcodec_thread_free(AVCodecContext *s){ + ThreadContext *c= s->thread_opaque; + int i; + + for(i=0; ithread_count; i++){ + + c[i].func= NULL; + ReleaseSemaphore(c[i].work_sem, 1, 0); + WaitForSingleObject(c[i].thread, INFINITE); + if(c[i].work_sem) CloseHandle(c[i].work_sem); + if(c[i].done_sem) CloseHandle(c[i].done_sem); + } + + av_freep(&s->thread_opaque); +} + +int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count){ + ThreadContext *c= s->thread_opaque; + int i; + + assert(s == c->avctx); + assert(count <= s->thread_count); + + /* note, we can be certain that this is not called with the same AVCodecContext by different threads at the same time */ + + for(i=0; ithread_count= thread_count; + + assert(!s->thread_opaque); + c= av_mallocz(sizeof(ThreadContext)*thread_count); + s->thread_opaque= c; + + for(i=0; ithread_count, NULL))) + goto fail; + if(!(c[i].done_sem = CreateSemaphore(NULL, 0, s->thread_count, NULL))) + goto fail; + +//printf("create thread %d\n", i); fflush(stdout); + c[i].thread = (HANDLE)_beginthreadex(NULL, 0, thread_func, &c[i], 0, &threadid ); + if( !c[i].thread ) goto fail; + } +//printf("init done\n"); fflush(stdout); + + s->execute= avcodec_thread_execute; + + return 0; +fail: + avcodec_thread_free(s); + return -1; +} Added: haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/wavpack.c =================================================================== --- haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/wavpack.c 2008-09-15 14:05:40 UTC (rev 27551) +++ haiku/trunk/src/add-ons/media/plugins/avcodec/libavcodec/wavpack.c 2008-09-15 14:07:05 UTC (rev 27552) @@ -0,0 +1,587 @@ +/* + * WavPack lossless audio decoder + * Copyright (c) 2006 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#define ALT_BITSTREAM_READER_LE +#include "avcodec.h" +#include "bitstream.h" +#include "unary.h" + +/** + * @file wavpack.c + * WavPack lossless audio decoder + */ + +#define WV_JOINT_STEREO 0x00000010 +#define WV_FALSE_STEREO 0x40000000 + +enum WP_ID_Flags{ + WP_IDF_MASK = 0x1F, + WP_IDF_IGNORE = 0x20, + WP_IDF_ODD = 0x40, + WP_IDF_LONG = 0x80 +}; + +enum WP_ID{ + WP_ID_DUMMY = 0, + WP_ID_ENCINFO, + WP_ID_DECTERMS, + WP_ID_DECWEIGHTS, + WP_ID_DECSAMPLES, + WP_ID_ENTROPY, + WP_ID_HYBRID, + WP_ID_SHAPING, + WP_ID_FLOATINFO, + WP_ID_INT32INFO, + WP_ID_DATA, + WP_ID_CORR, + WP_ID_FLT, + WP_ID_CHANINFO +}; + +#define MAX_TERMS 16 + +typedef struct Decorr { + int delta; + int value; + int weightA; + int weightB; + int samplesA[8]; + int samplesB[8]; +} Decorr; + +typedef struct WavpackContext { + AVCodecContext *avctx; + int stereo, stereo_in; + int joint; + uint32_t CRC; + GetBitContext gb; + int data_size; // in bits + int samples; + int median[6]; + int terms; + Decorr decorr[MAX_TERMS]; + int zero, one, zeroes; + int and, or, shift; +} WavpackContext; + +// exponent table copied from WavPack source +static const uint8_t wp_exp2_table [256] = { + 0x00, 0x01, 0x01, 0x02, 0x03, 0x03, 0x04, 0x05, 0x06, 0x06, 0x07, 0x08, 0x08, 0x09, 0x0a, 0x0b, + 0x0b, 0x0c, 0x0d, 0x0e, 0x0e, 0x0f, 0x10, 0x10, 0x11, 0x12, 0x13, 0x13, 0x14, 0x15, 0x16, 0x16, + 0x17, 0x18, 0x19, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1d, 0x1e, 0x1f, 0x20, 0x20, 0x21, 0x22, 0x23, + 0x24, 0x24, 0x25, 0x26, 0x27, 0x28, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3a, 0x3b, 0x3c, 0x3d, + 0x3e, 0x3f, 0x40, 0x41, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x48, 0x49, 0x4a, 0x4b, + 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, + 0x5b, 0x5c, 0x5d, 0x5e, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, + 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, + 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x87, 0x88, 0x89, 0x8a, + 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, + 0x9c, 0x9d, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, + 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, + 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc8, 0xc9, 0xca, 0xcb, 0xcd, 0xce, 0xcf, 0xd0, 0xd2, 0xd3, 0xd4, + 0xd6, 0xd7, 0xd8, 0xd9, 0xdb, 0xdc, 0xdd, 0xde, 0xe0, 0xe1, 0xe2, 0xe4, 0xe5, 0xe6, 0xe8, 0xe9, + 0xea, 0xec, 0xed, 0xee, 0xf0, 0xf1, 0xf2, 0xf4, 0xf5, 0xf6, 0xf8, 0xf9, 0xfa, 0xfc, 0xfd, 0xff +}; + +static av_always_inline int wp_exp2(int16_t val) +{ + int res, neg = 0; + + if(val < 0){ + val = -val; + neg = 1; + } + + res = wp_exp2_table[val & 0xFF] | 0x100; + val >>= 8; + res = (val > 9) ? (res << (val - 9)) : (res >> (9 - val)); + return neg ? -res : res; +} + +// macros for manipulating median values +#define GET_MED(n) ((median[n] >> 4) + 1) +#define DEC_MED(n) median[n] -= ((median[n] + (128>>n) - 2) / (128>>n)) * 2 +#define INC_MED(n) median[n] += ((median[n] + (128>>n)) / (128>>n)) * 5 + +// macros for applying weight +#define UPDATE_WEIGHT_CLIP(weight, delta, samples, in) \ + if(samples && in){ \ + if((samples ^ in) < 0){ \ + weight -= delta; \ + if(weight < -1024) weight = -1024; \ + }else{ \ + weight += delta; \ + if(weight > 1024) weight = 1024; \ + } \ + }