Ardour  9.8-22-gfea9c25b88
ffmpegfileimportable.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Marijn Kruisselbrink <mek@google.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #ifndef _ardour_ffmpegfile_importable_source_h_
20 #define _ardour_ffmpegfile_importable_source_h_
21 
22 #include <atomic>
23 
24 #include "pbd/ringbuffer.h"
25 
28 #include "ardour/system_exec.h"
29 #include "ardour/types.h"
30 
31 namespace ARDOUR {
32 
34 {
35 public:
36  enum {
37  ALL_CHANNELS = -1,
38  };
39 
40  FFMPEGFileImportableSource (const std::string& path, int channel = ALL_CHANNELS, bool for_recovery = false);
41 
43 
44  /* ImportableSource API */
46  uint32_t channels () const { return _channels; }
47  samplecnt_t length () const { return _length; }
48  samplecnt_t samplerate () const { return _samplerate; }
49  void seek (samplepos_t pos);
50  samplepos_t natural_position () const { return _natural_position; }
51  bool clamped_at_unity () const { return false; }
52 
53  std::string format_name () const { return _format_name; }
54 
55 private:
56  void start_ffmpeg ();
57  void reset ();
58 
59  void did_read_data (std::string data, size_t size);
60  void terminated ();
61 
62  std::string _path;
63  int _channel;
64 
65  uint32_t _channels;
69  std::string _format_name;
70 
72  /* Set to 1 to indicate that ffmpeg should be terminating. */
73  std::atomic<bool> _ffmpeg_should_terminate;
74  std::atomic<bool> _read_complete;
75 
76  /* To make sure we don't try to parse partial floats, we might have a couple of bytes
77  * of leftover unparsable data after any `did_read_data` call. Those couple of bytes are
78  * stored here until the next `did_read_data` call.
79  */
80  std::string _leftover_data;
81 
83 
86 };
87 
88 } // namespace ARDOUR
89 
90 #endif /* _ardour_ffmpegfile_importable_source_h_ */
FFMPEGFileImportableSource(const std::string &path, int channel=ALL_CHANNELS, bool for_recovery=false)
PBD::ScopedConnectionList _ffmpeg_conn
void did_read_data(std::string data, size_t size)
samplecnt_t read(Sample *, samplecnt_t nframes)
#define LIBARDOUR_API
Temporal::samplecnt_t samplecnt_t
Temporal::samplepos_t samplepos_t