netmd++ 1.0.4
C++ API to access NetMD devices
Loading...
Searching...
No Matches
netmd++.h
Go to the documentation of this file.
1/*
2 * netmd++.h
3 *
4 * This file is part of netmd++, a library for accessing NetMD devices.
5 *
6 * It makes use of knowledge / code collected by Marc Britten and
7 * Alexander Sulfrian for the Linux Minidisc project.
8 *
9 * Asivery helped to make this possible!
10 * Sir68k discovered the Sony FW exploit!
11 *
12 * Copyright (C) 2023 Jo2003 (olenka.joerg@gmail.com)
13 *
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 *
28 */
29
242#pragma once
243#include <cstdint>
244#include <sstream>
245#include <vector>
246#include <ctime>
247#include <functional>
248#include <mutex>
249
250namespace netmd {
251
261
277
280{
284};
285
287enum class TrackProtection : uint8_t
288{
289 UNPROTECTED = 0x00,
290 PROTECTED = 0x03,
291 UNKNOWN = 0xFF
292};
293
295enum class AudioEncoding : uint8_t
296{
297 SP = 0x90,
298 LP2 = 0x92,
299 LP4 = 0x93,
300 UNKNOWN = 0xff
301};
302
312
323
326{
327 uint16_t hour;
328 uint8_t minute;
329 uint8_t second;
330 uint8_t frame;
331};
332
347
348//-----------------------------------------------------------------------------
350//-----------------------------------------------------------------------------
351struct Group
352{
353 int mGid;
354 int16_t mFirst;
355 int16_t mLast;
356 std::string mName;
357};
358
359//-----------------------------------------------------------------------------
361//-----------------------------------------------------------------------------
362enum HomebrewFeatures : uint32_t
363{
364 NOTHING = 0x00,
365 SP_UPLOAD = 0x01,
366 PCM_2_MONO = 0x02,
367 PCM_SPEEDUP = 0x04,
368 USB_EXEC = 0x08,
369};
370
372using Groups = std::vector<Group>;
373
375using NetMDByteVector = std::vector<uint8_t>;
376
377//--------------------------------------------------------------------------
379//
381//--------------------------------------------------------------------------
382using EvtCallback = std::function<void(bool)>;
383
384//--------------------------------------------------------------------------
391//--------------------------------------------------------------------------
392std::ostream& operator<<(std::ostream& o, const TrackTime& tt);
393
394//--------------------------------------------------------------------------
401//--------------------------------------------------------------------------
402std::ostream& operator<<(std::ostream& o, const AudioEncoding& ae);
403
404//--------------------------------------------------------------------------
411//--------------------------------------------------------------------------
412std::ostream& operator<<(std::ostream& o, const TrackProtection& tp);
413
414//------------------------------------------------------------------------------
421//------------------------------------------------------------------------------
423
425class CMDiscHeader;
426
428class CNetMdDev;
429
431class CNetMdSecure;
432
434class CNetMdApi;
435
438
439//------------------------------------------------------------------------------
441//------------------------------------------------------------------------------
443{
444public:
445 //--------------------------------------------------------------------------
447 //--------------------------------------------------------------------------
449
450 //--------------------------------------------------------------------------
452 //--------------------------------------------------------------------------
454
455 //--------------------------------------------------------------------------
457 //
459 //--------------------------------------------------------------------------
461
462 //--------------------------------------------------------------------------
466 //--------------------------------------------------------------------------
468
469 //--------------------------------------------------------------------------
473 //--------------------------------------------------------------------------
474 std::string getDeviceName() const;
475
476 //--------------------------------------------------------------------------
480 //--------------------------------------------------------------------------
481 static void setLogLevel(int severity);
482
483 //--------------------------------------------------------------------------
487 //--------------------------------------------------------------------------
488 static void setLogStream(std::ostream& os);
489
490 //--------------------------------------------------------------------------
494 //--------------------------------------------------------------------------
496
497 //--------------------------------------------------------------------------
501 //--------------------------------------------------------------------------
503
504 //--------------------------------------------------------------------------
508 //--------------------------------------------------------------------------
510
511 //--------------------------------------------------------------------------
518 //--------------------------------------------------------------------------
519 int trackTime(int trackNo, TrackTime& trackTime);
520
521 //--------------------------------------------------------------------------
527 //--------------------------------------------------------------------------
528 int discTitle(std::string& title);
529
530 //--------------------------------------------------------------------------
536 //--------------------------------------------------------------------------
537 int setDiscTitle(const std::string& title);
538
539 //--------------------------------------------------------------------------
546 //--------------------------------------------------------------------------
547 int moveTrack(uint16_t from, uint16_t to);
548
549 //--------------------------------------------------------------------------
556 //--------------------------------------------------------------------------
557 int setGroupTitle(uint16_t group, const std::string& title);
558
559 //--------------------------------------------------------------------------
567 //--------------------------------------------------------------------------
568 int createGroup(const std::string& title, int first, int last);
569
570 //--------------------------------------------------------------------------
577 //--------------------------------------------------------------------------
578 int addTrackToGroup(int track, int group);
579
580 //--------------------------------------------------------------------------
587 //--------------------------------------------------------------------------
588 int delTrackFromGroup(int track, int group);
589
590 //--------------------------------------------------------------------------
596 //--------------------------------------------------------------------------
597 int deleteGroup(int group);
598
599 //--------------------------------------------------------------------------
605 //--------------------------------------------------------------------------
606 int deleteTrack(uint16_t track);
607
608 //--------------------------------------------------------------------------
616 //--------------------------------------------------------------------------
617 int trackBitRate(uint16_t track, AudioEncoding& encoding, uint8_t& channel);
618
619 //--------------------------------------------------------------------------
626 //--------------------------------------------------------------------------
627 int trackFlags(uint16_t track, TrackProtection& flags);
628
629 //--------------------------------------------------------------------------
636 //--------------------------------------------------------------------------
637 int trackTitle(uint16_t track, std::string& title);
638
639 //--------------------------------------------------------------------------
643 //--------------------------------------------------------------------------
645
646 //--------------------------------------------------------------------------
650 //--------------------------------------------------------------------------
652
653 //--------------------------------------------------------------------------
657 //--------------------------------------------------------------------------
659
660 //--------------------------------------------------------------------------
664 //--------------------------------------------------------------------------
666
667 //--------------------------------------------------------------------------
671 //--------------------------------------------------------------------------
673
674 //--------------------------------------------------------------------------
678 //--------------------------------------------------------------------------
680
681 //--------------------------------------------------------------------------
699 //--------------------------------------------------------------------------
700 int sendAudioFile(const std::string& filename, const std::string& title, DiskFormat otf);
701
702 //--------------------------------------------------------------------------
709 //--------------------------------------------------------------------------
710 int setTrackTitle(uint16_t trackNo, const std::string& title);
711
712 //--------------------------------------------------------------------------
718 //--------------------------------------------------------------------------
720
721 //--------------------------------------------------------------------------
725 //--------------------------------------------------------------------------
727
728 //--------------------------------------------------------------------------
732 //--------------------------------------------------------------------------
734
735 //--------------------------------------------------------------------------
741 //--------------------------------------------------------------------------
743
744 //--------------------------------------------------------------------------
751 //--------------------------------------------------------------------------
753
754 //--------------------------------------------------------------------------
763 //--------------------------------------------------------------------------
764 int finalizeTOC(bool reset = false, uint8_t resetWait = 15);
765
766 //--------------------------------------------------------------------------
768 //
770 //
773 //--------------------------------------------------------------------------
774 int startHBSession(uint32_t features);
775
776 //--------------------------------------------------------------------------
778 //
780 //
783 //--------------------------------------------------------------------------
784 void endHBSession(uint32_t features);
785
786 //--------------------------------------------------------------------------
788 //
791 //--------------------------------------------------------------------------
793
794private:
796 CMDiscHeader* mpDiscHeader;
797
799 CNetMdDev* mpNetMd;
800
802 CNetMdSecure* mpSecure;
803
805 EvtCallback mHotplugCallback;
806
808 std::mutex mMutexHotplug;
809};
810
811namespace toc
812{
814 struct TOC;
815}
816
817//------------------------------------------------------------------------------
819//------------------------------------------------------------------------------
821{
822public:
825 {
826 uint32_t mStart;
827 uint32_t mEnd;
828 };
829
831 using DAOFragments = std::vector<DAOFragment>;
832
833 //--------------------------------------------------------------------------
839 //--------------------------------------------------------------------------
840 CNetMdTOC(int trackCount = 0, uint32_t lenInMs = 0, uint8_t* data = nullptr);
841
842 //--------------------------------------------------------------------------
844 //--------------------------------------------------------------------------
846
847 //--------------------------------------------------------------------------
853 //--------------------------------------------------------------------------
854 void import(int trackCount = 0, uint32_t lenInMs = 0, uint8_t* data = nullptr);
855
856 //--------------------------------------------------------------------------
871 //--------------------------------------------------------------------------
872 int addTrack(uint8_t no, uint32_t lengthMs, const std::string& title, const std::time_t& tstamp, bool mono = false);
873
874 //--------------------------------------------------------------------------
880 //--------------------------------------------------------------------------
881 int setDiscTitle(const std::string& title);
882
883 //--------------------------------------------------------------------------
887 //--------------------------------------------------------------------------
888 int trackCount() const;
889
890 //--------------------------------------------------------------------------
894 //--------------------------------------------------------------------------
895 std::string discTitle() const;
896
897 //--------------------------------------------------------------------------
903 //--------------------------------------------------------------------------
904 std::string trackTitle(int trackNo) const;
905
906 //--------------------------------------------------------------------------
912 //--------------------------------------------------------------------------
913 std::string trackInfo(int trackNo) const;
914
915 //--------------------------------------------------------------------------
919 //--------------------------------------------------------------------------
920 std::string discInfo() const;
921
922private:
924 toc::TOC* mpToc;
925
927 int mTracksCount;
928
930 uint32_t mLengthInMs;
931
933 uint32_t mCurPos;
934
936 int mDAOTrack;
937
939 uint32_t mDAOGroups;
940
942 DAOFragments mDAOFragments;
943};
944
945
946} // ~namespace
This class describes a C++ NetMD access library.
Definition netmd++.h:443
int initHotPlug()
init libusb hotplug (native or emulation)
void registerForHotplugEvents(EvtCallback cb)
register hotplug callback function
int discFlags()
request disc flags
int setGroupTitle(uint16_t group, const std::string &title)
Sets the group title.
int discCapacity(DiscCapacity &dcap)
get disc capacity
int trackBitRate(uint16_t track, AudioEncoding &encoding, uint8_t &channel)
get track bitrate data
static void setLogStream(std::ostream &os)
Sets the log stream.
int trackTitle(uint16_t track, std::string &title)
get track title
int writeUTOCSector(UTOCSector s, const NetMDByteVector &data)
Writes an utoc sector.
void endHBSession(uint32_t features)
stop homebrew session
int trackCount()
request track count
int eraseDisc()
erase MD
int setTrackTitle(uint16_t trackNo, const std::string &title)
Sets the track title.
bool spUploadSupported()
is SP upload supported?
~CNetMdApi()
Destroys the object.
bool tocManipSupported()
is TOC manipulation supported?
CNetMdApi()
Constructs a new instance.
int createGroup(const std::string &title, int first, int last)
Creates a group.
bool otfEncodeSupported()
is on the fly encoding supported by device
Groups groups()
get MD track groups
int moveTrack(uint16_t from, uint16_t to)
move a track (number)
int setDiscTitle(const std::string &title)
Sets the disc title.
int trackFlags(uint16_t track, TrackProtection &flags)
get track flags
int addTrackToGroup(int track, int group)
Adds a track to group.
int discTitle(std::string &title)
get disc title
int delTrackFromGroup(int track, int group)
remove track from group
bool pcmSpeedupSupported()
is PCM speedup supportd
static void setLogLevel(int severity)
Sets the log level.
int trackTime(int trackNo, TrackTime &trackTime)
get track time
int finalizeTOC(bool reset=false, uint8_t resetWait=15)
finalize TOC through exploit
int initDevice()
Initializes the device.
int startHBSession(uint32_t features)
start homebrew
int deleteTrack(uint16_t track)
delete track
bool nativeMonoUploadSupported()
is native mono upload supported?
std::string getDeviceName() const
Gets the device name.
NetMDByteVector readUTOCSector(UTOCSector s)
Reads an utoc sector.
int deleteGroup(int group)
delete a group
int sendAudioFile(const std::string &filename, const std::string &title, DiskFormat otf)
Sends an audio track.
bool pcm2MonoSupported()
is PCM to mono supported?
int prepareTOCManip()
prepare TOC manipulation
CNetMdTOC(int trackCount=0, uint32_t lenInMs=0, uint8_t *data=nullptr)
Constructs a new instance.
int trackCount() const
get track count
~CNetMdTOC()
Destroys the object.
std::string trackTitle(int trackNo) const
get track title
std::string trackInfo(int trackNo) const
get track info
std::vector< DAOFragment > DAOFragments
type to store all DAO track fragments (for fragmented, non empty discs)
Definition netmd++.h:831
std::string discInfo() const
get disc info
int addTrack(uint8_t no, uint32_t lengthMs, const std::string &title, const std::time_t &tstamp, bool mono=false)
Adds a track.
std::string discTitle() const
get MD title
int setDiscTitle(const std::string &title)
Sets the disc title.
TrackProtection
type safe protection flags
Definition netmd++.h:288
@ PROTECTED
track is protected
Definition netmd++.h:290
@ UNKNOWN
unknown track state
Definition netmd++.h:291
@ UNPROTECTED
track is unprotected
Definition netmd++.h:289
AudioEncoding
type safe encoding flags
Definition netmd++.h:296
@ LP2
LP2 encoding.
Definition netmd++.h:298
@ SP
SP encoding.
Definition netmd++.h:297
@ LP4
LP4 encoding.
Definition netmd++.h:299
HomebrewFeatures
NetMD homebrew features.
Definition netmd++.h:363
@ SP_UPLOAD
SP upload.
Definition netmd++.h:365
@ PCM_SPEEDUP
PCM speedup.
Definition netmd++.h:367
@ PCM_2_MONO
PCM to mono.
Definition netmd++.h:366
@ USB_EXEC
USB execution.
Definition netmd++.h:368
@ NOTHING
no features
Definition netmd++.h:364
std::vector< Group > Groups
netmd groups
Definition netmd++.h:372
NetMDByteVector & operator+=(NetMDByteVector &a, const NetMDByteVector &b)
Addition assignment operator for NetMDByteVector.
std::vector< uint8_t > NetMDByteVector
byte vector
Definition netmd++.h:375
typelog
log severity
Definition netmd++.h:305
@ CAPTURE
needed for log parcing!
Definition netmd++.h:310
@ WARN
more serious
Definition netmd++.h:308
@ CRITICAL
critical information
Definition netmd++.h:309
@ INFO
information
Definition netmd++.h:307
@ DEBUG
debug information
Definition netmd++.h:306
NetMdErr
NetMD errors.
Definition netmd++.h:264
@ NETMDERR_USB
general USB error
Definition netmd++.h:266
@ NETMDERR_NOT_SUPPORTED
not supported
Definition netmd++.h:273
@ NETMDERR_NOTREADY
player not ready for command
Definition netmd++.h:267
@ NETMDERR_AGAIN
try again
Definition netmd++.h:275
@ NETMDERR_TIMEOUT
timeout while waiting for response
Definition netmd++.h:268
@ NETMDERR_CMD_INVALID
minidisc responded with 0A response
Definition netmd++.h:270
@ NETMDERR_PARAM
parameter error
Definition netmd++.h:271
@ NETMDERR_NO_ERROR
success
Definition netmd++.h:265
@ NETMDERR_INTERIM
interim
Definition netmd++.h:274
@ NETMDERR_CMD_FAILED
minidisc responded with 08 response
Definition netmd++.h:269
@ NETMDERR_OTHER
any other error
Definition netmd++.h:272
CNetMdApi netmd_pp
use netmd_pp instead of CNetMdApi
Definition netmd++.h:437
DiskFormat
disk format
Definition netmd++.h:254
@ NETMD_DISKFORMAT_SP_STEREO
SP stereo.
Definition netmd++.h:258
@ NETMD_DISKFORMAT_LP4
LP4.
Definition netmd++.h:255
@ NETMD_DISKFORMAT_LP2
LP2.
Definition netmd++.h:256
@ NO_ONTHEFLY_CONVERSION
dont do on-the-fly encoding
Definition netmd++.h:259
@ NETMD_DISKFORMAT_SP_MONO
SP mono.
Definition netmd++.h:257
std::function< void(bool)> EvtCallback
hotplug callback function signature
Definition netmd++.h:382
UTOCSector
TOC sector names.
Definition netmd++.h:315
@ FW_TITLES
full width titles
Definition netmd++.h:319
@ POS_ADDR
position and addresses of audio data
Definition netmd++.h:316
@ UNKNWN_1
some unidentified TOC sector #1
Definition netmd++.h:320
@ TSTAMPS
time stamps
Definition netmd++.h:318
@ UNKNON_2
some unidentified TOC sector #2
Definition netmd++.h:321
@ HW_TITLES
half width titles
Definition netmd++.h:317
std::ostream & operator<<(std::ostream &o, const TrackTime &tt)
format helper for TrackTime
a fragment used in DAO track
Definition netmd++.h:825
uint32_t mEnd
end group
Definition netmd++.h:827
uint32_t mStart
start group
Definition netmd++.h:826
Structure to hold the capacity information of a disc.
Definition netmd++.h:335
NetMdTime total
Definition netmd++.h:341
NetMdTime recorded
Time allready recorded on the disc.
Definition netmd++.h:337
NetMdTime available
Definition netmd++.h:345
track group
Definition netmd++.h:352
int16_t mFirst
first track
Definition netmd++.h:354
int mGid
group id
Definition netmd++.h:353
int16_t mLast
last track
Definition netmd++.h:355
std::string mName
group name
Definition netmd++.h:356
NetMD time.
Definition netmd++.h:326
uint8_t minute
minute
Definition netmd++.h:328
uint8_t second
second
Definition netmd++.h:329
uint16_t hour
hour
Definition netmd++.h:327
uint8_t frame
frame
Definition netmd++.h:330
track times
Definition netmd++.h:280
int mTenthSecs
time in 10ms
Definition netmd++.h:283
int mSeconds
time in seconds
Definition netmd++.h:282
int mMinutes
time in minutes
Definition netmd++.h:281