Discman
Loading...
Searching...
No Matches
cd_ripper.h
Go to the documentation of this file.
1
6
7#ifndef CD_RIPPER_H
8#define CD_RIPPER_H
9
10#include <thread>
11#include <filesystem>
12#include <iomanip>
13
14#include <unistd.h>
15#include <glibmm.h>
16
17extern "C" {
18 #include <libavformat/avformat.h>
19 #include <libavformat/avio.h>
20 #include <libavcodec/avcodec.h>
21 #include <libavutil/opt.h>
22 #include <libswresample/swresample.h>
23}
24
25#include <sigc++/signal.h>
26
27#include <curlpp/Easy.hpp>
28#include <curlpp/Infos.hpp>
29#include <curlpp/Options.hpp>
30#include <curlpp/cURLpp.hpp>
31
32#include <stb/stb_image.h>
33
34#include <discdb/disc.h>
35
36#include "cd/cd_drive.h"
38
41class CDRipper : public Consumer<int16_t> {
42 public:
44 struct NoMedia : public std::exception {
45 const char* what() const throw() {
46 return "No removable volumes are currently mounted.";
47 }
48 };
49
51 struct RipperErrorException : public std::exception {
52 RipperErrorException(const std::string& what)
53 : _what(what) { }
54
55 const char* what() const throw() {
56 return _what.c_str();
57 }
58
59 private:
60 std::string _what;
61 };
62
64 typedef sigc::signal<void(unsigned int, unsigned int)> sig_track_progress;
65
67 typedef sigc::signal<void(void)> sig_done;
68
71
77 CDRipper(CDDrive& drive, const DiscDB::Disc& disc, const std::string& albumArtURL, const std::string& mediaRoot);
78
80 ~CDRipper();
81
83 void rip();
84
87 void rip(const int track);
88
89 private:
90
92 struct RipContext {
93 AVFormatContext* fmt_ctx;
94 AVStream* st;
95 AVStream* sta;
96 const AVCodec* codec;
97 AVCodecContext* c;
98 AVFrame* frame;
99 AVPacket* packet;
100 SwrContext* swr_ctx;
101 };
102
105
107 const DiscDB::Disc& _disc;
108 std::thread* _thread;
109 Glib::Dispatcher _dispatcher;
110 Glib::Dispatcher _dispatcher_done;
111 unsigned int _track;
112 unsigned int _progress;
113 std::string _media_root;
114 std::string _output_dir;
115 std::string _output_filename;
116 std::string _album_art_url;
120 std::pair<int, int> _album_art_image_dims;
121
125 std::string make_safe(const std::string& str) const;
126
127 void on_notification();
128 void on_done_notification();
129
130 void rip_helper();
131 void rip_helper(const int track);
132
133 void ensure_output_dir();
134
137 void start_rip(RipContext* rip_ctx);
138
142 void do_rip(RipContext* rip_ctx, bool continuous=true);
143
146 void end_rip(RipContext* rip_ctx);
147
150 void start_file(RipContext* rip_ctx);
151
154 void end_file(RipContext* rip_ctx);
155
158 void tag_file(RipContext* rip_ctx);
159
162 void add_file_art(RipContext* rip_ctx);
163};
164
165
166#endif // CD_RIPPER_H
Abstracts the host's disc drive.
Definition cd_drive.h:39
Glib::Dispatcher _dispatcher
Used by _thread to safely emit _sig_track_progress.
Definition cd_ripper.h:109
int _album_art_image_size
The size of _album_art_image.
Definition cd_ripper.h:118
const DiscDB::Disc & _disc
The fully populated DiscDB::Disc describing the album.
Definition cd_ripper.h:107
std::string _output_filename
The output filename.
Definition cd_ripper.h:115
std::string _output_dir
The path to the album folder on the removable volume.
Definition cd_ripper.h:114
~CDRipper()
CDRipper destructor.
Definition cd_ripper.cc:26
sig_done _sig_done
Emiited when the rip (whole disc or single track) is done.
Definition cd_ripper.h:104
std::string _album_art_url
The URL of the album art currently shown.
Definition cd_ripper.h:116
void rip()
Rip the entire disc.
Definition cd_ripper.cc:311
Glib::Dispatcher _dispatcher_done
Used by _thread to safely emit _sig_done.
Definition cd_ripper.h:110
void end_rip(RipContext *rip_ctx)
Ends the ripping process.
Definition cd_ripper.cc:233
CDRipper(CDDrive &drive, const DiscDB::Disc &disc, const std::string &albumArtURL, const std::string &mediaRoot)
CDRipper constructor.
Definition cd_ripper.cc:10
std::string make_safe(const std::string &str) const
Used to sanitize folder and file names.
Definition cd_ripper.cc:36
unsigned int _progress
The current percentage completion ripping the current track.
Definition cd_ripper.h:112
void add_file_art(RipContext *rip_ctx)
Adds _album_art_image to the output file.
Definition cd_ripper.cc:387
void on_done_notification()
Called when _dispatcher_done is notified.
Definition cd_ripper.cc:50
void on_notification()
Called when _dispatcher is notified.
Definition cd_ripper.cc:46
CDDrive & _drive
The parent CDDrive.
Definition cd_ripper.h:106
void start_file(RipContext *rip_ctx)
Creates the ouput file, tags it and writes the M4A header.
Definition cd_ripper.cc:238
sigc::signal< void(void)> sig_done
"Rip done" signal type.
Definition cd_ripper.h:67
unsigned int _track
The 1-based index of the track currently being ripped.
Definition cd_ripper.h:111
sigc::signal< void(unsigned int, unsigned int)> sig_track_progress
"Track progress made" signal type.
Definition cd_ripper.h:64
void ensure_output_dir()
Verifies _media_root exists and sets _output_dir.
Definition cd_ripper.cc:54
AVCodecID _album_art_image_codec
Reflects whether the _album_art_image is JPEG or PNG.
Definition cd_ripper.h:119
uint8_t * _album_art_image
Raw bytes received from the _album_art_url.
Definition cd_ripper.h:117
void do_rip(RipContext *rip_ctx, bool continuous=true)
The core ripping method interacting directly with ffmpeg.
Definition cd_ripper.cc:143
sig_done signal_done()
Getter for ::_signal_done.
Definition cd_ripper.cc:371
sig_track_progress _sig_track_progress
Emitted when the percentage progress ripping a track has increased.
Definition cd_ripper.h:103
void rip_helper()
Private helper for rip().
Definition cd_ripper.cc:322
std::thread * _thread
Used to execute the ripping process.
Definition cd_ripper.h:108
void end_file(RipContext *rip_ctx)
Frees resources in the ripping context specific to the output file.
Definition cd_ripper.cc:303
void start_rip(RipContext *rip_ctx)
Begins the ripping process.
Definition cd_ripper.cc:68
sig_track_progress signal_track_progress()
Getter for ::_signal_track_progress.
Definition cd_ripper.cc:367
std::string _media_root
The path to the root of the removable volume.
Definition cd_ripper.h:113
std::pair< int, int > _album_art_image_dims
The dimensions of _album_art_image in pixels.
Definition cd_ripper.h:120
void tag_file(RipContext *rip_ctx)
Adds textual metadata (album and track information) to the output file.
Definition cd_ripper.cc:375
Thrown when there is no removable volume to rip to.
Definition cd_ripper.h:44
const char * what() const
Definition cd_ripper.h:45
Contains resources that are shared by private helper functions.
Definition cd_ripper.h:92
AVFrame * frame
The unit of input to ffmpeg.
Definition cd_ripper.h:98
AVStream * sta
Video stream for album art.
Definition cd_ripper.h:95
AVFormatContext * fmt_ctx
Format (file) context.
Definition cd_ripper.h:93
const AVCodec * codec
The M4A codec.
Definition cd_ripper.h:96
AVPacket * packet
The unit of output from ffmpeg.
Definition cd_ripper.h:99
AVCodecContext * c
The codec context.
Definition cd_ripper.h:97
AVStream * st
Audio stream.
Definition cd_ripper.h:94
SwrContext * swr_ctx
Context for resampling from int16_t to float.
Definition cd_ripper.h:100
RipperErrorException(const std::string &what)
Definition cd_ripper.h:52
const char * what() const
Definition cd_ripper.h:55