c_encoder.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #include <windows.h>
  2. #include "c_encoder.h"
  3. C_ENCODER::C_ENCODER(int ExtInfoSize) {
  4. SetName("Untyped Encoder");
  5. ExtendedInfoPtr = (T_EncoderIOVals *)malloc(ExtInfoSize);
  6. ExtendedInfoSize = ExtInfoSize;
  7. }
  8. C_ENCODER::~C_ENCODER() {
  9. Close();
  10. if(ExtendedInfoPtr && ExtendedInfoSize) free(ExtendedInfoPtr);
  11. ExtendedInfoSize = 0;
  12. }
  13. void C_ENCODER::Close() {
  14. ClearAttribs();
  15. }
  16. void C_ENCODER::SetName(const char *name) {
  17. if (name) lstrcpyn(Name, name, C_ENCODER_NameLen);
  18. }
  19. char *C_ENCODER::GetName() {
  20. return Name;
  21. }
  22. void C_ENCODER::Reset() {
  23. }
  24. void C_ENCODER::ChangeSettings(const void *Settings) {
  25. if(ExtendedInfoPtr && ExtendedInfoSize && Settings && Settings != ExtendedInfoPtr) {
  26. memcpy(ExtendedInfoPtr,Settings,ExtendedInfoSize);
  27. Reset();
  28. }
  29. }
  30. void C_ENCODER::Create(const T_EncoderIOVals *Settings, const char *name) {
  31. if(name) SetName(name);
  32. ChangeSettings(Settings);
  33. }
  34. void C_ENCODER::ClearAttribs() {
  35. for(int i = AttribList.size()-1; i >= 0; i--) {
  36. T_ATTRIB *myAttrib = AttribList[i];
  37. if(myAttrib->OutputVals) delete[] myAttrib->OutputVals;
  38. }
  39. //AttribList.deleteAll();
  40. for (auto attrib : AttribList)
  41. {
  42. delete attrib;
  43. }
  44. AttribList.clear();
  45. }
  46. void C_ENCODER::AddAttrib(const char *Text, const void *Attributes) {
  47. T_ATTRIB *myAttrib = new T_ATTRIB;
  48. if(Text!=NULL) {
  49. ::strncpy((char *)&myAttrib->Text,Text,sizeof(myAttrib->Text));
  50. } else {
  51. ::strncpy((char *)&myAttrib->Text,"<This should never appear here...>",sizeof(myAttrib->Text));
  52. }
  53. myAttrib->OutputVals = (T_EncoderIOVals *)Attributes;
  54. AttribList.push_back(myAttrib);
  55. }
  56. int C_ENCODER::Encode(const void *inputbuf, const unsigned int inputbufsize, void *outputbuf, const unsigned int outputbufsize, int *inputamtused) {
  57. if((inputbuf != NULL) && (outputbuf != NULL) && (inputbufsize != 0) && (outputbufsize != 0) && (inputamtused != NULL)) {
  58. int numitems = (inputbufsize > outputbufsize) ? outputbufsize : inputbufsize;
  59. memcpy(outputbuf,inputbuf,numitems);
  60. *inputamtused = numitems;
  61. return numitems;
  62. }
  63. return 0;
  64. }
  65. int C_ENCODER::GetNumAttribs() {
  66. return AttribList.size();
  67. }
  68. int C_ENCODER::EnumAttrib(const int val, T_ATTRIB *buf) {
  69. if((val < 0)||(val >= AttribList.size())||(buf==NULL)) return 0;
  70. T_ATTRIB *myattrib = AttribList[val];
  71. if(myattrib==NULL) return 0;
  72. ::memcpy(buf,myattrib,sizeof(T_ATTRIB));
  73. return 1;
  74. }
  75. char * C_ENCODER::GetContentType() {
  76. //if(strcmp(this->GetName(), "MP3 Encoder") == 0)
  77. return "audio/mpeg";
  78. }