FileManager.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*******************************************************************************
  2. * Copyright 2009-2016 Jörg Müller
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. ******************************************************************************/
  16. #pragma once
  17. /**
  18. * @file FileManager.h
  19. * @ingroup file
  20. * The FileManager class.
  21. */
  22. #include "respec/Specification.h"
  23. #include "IWriter.h"
  24. #include <list>
  25. #include <memory>
  26. #include <string>
  27. AUD_NAMESPACE_BEGIN
  28. class IFileInput;
  29. class IFileOutput;
  30. class IReader;
  31. class Buffer;
  32. /**
  33. * The FileManager manages all file input and output plugins.
  34. */
  35. class AUD_API FileManager
  36. {
  37. private:
  38. static std::list<std::shared_ptr<IFileInput>>& inputs();
  39. static std::list<std::shared_ptr<IFileOutput>>& outputs();
  40. // delete copy constructor and operator=
  41. FileManager(const FileManager&) = delete;
  42. FileManager& operator=(const FileManager&) = delete;
  43. FileManager() = delete;
  44. public:
  45. /**
  46. * Registers a file input used to create an IReader to read from a file.
  47. * @param input The IFileInput to register.
  48. */
  49. static void registerInput(std::shared_ptr<IFileInput> input);
  50. /**
  51. * Registers a file output used to create an IWriter to write to a file.
  52. * @param output The IFileOutput to register.
  53. */
  54. static void registerOutput(std::shared_ptr<IFileOutput> output);
  55. /**
  56. * Creates a file reader for the given filename if a registed IFileInput is able to read it.
  57. * @param filename The path to the file.
  58. * @return The reader created.
  59. * @exception Exception If no file input can read the file an exception is thrown.
  60. */
  61. static std::shared_ptr<IReader> createReader(std::string filename);
  62. /**
  63. * Creates a file reader for the given buffer if a registed IFileInput is able to read it.
  64. * @param buffer The buffer to read the file from.
  65. * @return The reader created.
  66. * @exception Exception If no file input can read the file an exception is thrown.
  67. */
  68. static std::shared_ptr<IReader> createReader(std::shared_ptr<Buffer> buffer);
  69. /**
  70. * Creates a file writer that writes a sound to the given file path.
  71. * Existing files will be overwritten.
  72. * @param filename The file path to write to.
  73. * @param specs The output specification.
  74. * @param format The container format for the file.
  75. * @param codec The codec used inside the container.
  76. * @param bitrate The bitrate to write with.
  77. * @return A writer that creates the file.
  78. * @exception Exception If no file output can write the file with the given specification an exception is thrown.
  79. */
  80. static std::shared_ptr<IWriter> createWriter(std::string filename, DeviceSpecs specs, Container format, Codec codec, unsigned int bitrate);
  81. };
  82. AUD_NAMESPACE_END