/*---------------------------------------------------------------------- | CrossFader_Activate +---------------------------------------------------------------------*/ BLT_METHOD CrossFader_Activate(BLT_MediaNodeInstance* instance, BLT_Stream* stream) { ATX_Properties settings; CrossFader* fader = (CrossFader*)instance; /* stop listening for settings on the current stream, if any */ if (!ATX_OBJECT_IS_NULL(&fader->context) && fader->listener_handle != NULL) { if (BLT_SUCCEEDED(BLT_Core_GetSettings(&fader->base.core, &settings))) { ATX_Properties_RemoveListener(&settings, fader->listener_handle); } fader->listener_handle = NULL; } /* keep a reference to the stream */ fader->context = *stream; /* listen to settings on the new stream */ if (BLT_SUCCEEDED(BLT_Core_GetSettings(&fader->base.core, &settings))) { ATX_PropertyListener me; ATX_INSTANCE(&me) = (ATX_PropertyListenerInstance*)fader; ATX_INTERFACE(&me) = &CrossFader_ATX_PropertyListenerInterface; ATX_Properties_AddListener(&settings, "SomeSetting", &me, &fader->listener_handle); } return BLT_SUCCESS; }
/*---------------------------------------------------------------------- | CrossFader_GetPortByName +---------------------------------------------------------------------*/ BLT_METHOD CrossFader_GetPortByName(BLT_MediaNodeInstance* instance, BLT_CString name, BLT_MediaPort* port) { CrossFader* fader = (CrossFader*)instance; if (ATX_StringsEqual(name, "input")) { ATX_INSTANCE(port) = (BLT_MediaPortInstance*)fader; ATX_INTERFACE(port) = &CrossFaderInputPort_BLT_MediaPortInterface; return BLT_SUCCESS; } else if (ATX_StringsEqual(name, "output")) { ATX_INSTANCE(port) = (BLT_MediaPortInstance*)fader; ATX_INTERFACE(port) = &CrossFaderOutputPort_BLT_MediaPortInterface; return BLT_SUCCESS; } else { ATX_CLEAR_OBJECT(port); return BLT_ERROR_NO_SUCH_PORT; } }
/*---------------------------------------------------------------------- | CrossFader_Create +---------------------------------------------------------------------*/ static BLT_Result CrossFader_Create(BLT_Module* module, BLT_Core* core, BLT_ModuleParametersType parameters_type, BLT_CString parameters, ATX_Object* object) { CrossFader* fader; BLT_Result result; ATX_LOG_FINE("CrossFader::Create"); /* check parameters */ if (parameters == NULL || parameters_type != BLT_MODULE_PARAMETERS_TYPE_MEDIA_NODE_CONSTRUCTOR) { return BLT_ERROR_INVALID_PARAMETERS; } /* allocate memory for the object */ fader = ATX_AllocateZeroMemory(sizeof(CrossFader)); if (fader == NULL) { ATX_CLEAR_OBJECT(object); return BLT_ERROR_OUT_OF_MEMORY; } /* construct the inherited object */ BLT_BaseMediaNode_Construct(&fader->base, module, core); /* construct the object */ fader->state = CROSS_FADER_STATE_IN_START; /* setup the input and output ports */ result = CrossFader_SetupPorts(fader); if (BLT_FAILED(result)) { BLT_BaseMediaNode_Destruct(&fader->base); ATX_FreeMemory(fader); ATX_CLEAR_OBJECT(object); return result; } /* construct reference */ ATX_INSTANCE(object) = (ATX_Instance*)fader; ATX_INTERFACE(object) = (ATX_Interface*)&CrossFader_BLT_MediaNodeInterface; return BLT_SUCCESS; }
/*---------------------------------------------------------------------- | ATX_FileByteStream_Create +---------------------------------------------------------------------*/ ATX_Result ATX_FileByteStream_Create(const char* filename, ATX_Flags mode, ATX_ByteStream* object) { FileByteStream* stream; int fd; /* decide wheter this is a file or stdin/stdout/stderr */ if (!strcmp(filename, "-stdin")) { fd = 0; } else if (!strcmp(filename, "-stdout")) { fd = 1; } else if (!strcmp(filename, "-stderr")) { fd = 2; } else { int flags = 0; /* compute mode */ if (mode & ATX_FILE_BYTE_STREAM_MODE_READ) { if (mode & ATX_FILE_BYTE_STREAM_MODE_WRITE) { flags |= O_RDWR; } else { flags |= O_RDONLY; } } else { if (mode & ATX_FILE_BYTE_STREAM_MODE_WRITE) { flags |= O_WRONLY; } } if (mode & ATX_FILE_BYTE_STREAM_MODE_CREATE) { flags |= O_CREAT; } if (mode & ATX_FILE_BYTE_STREAM_MODE_TRUNCATE) { flags |= O_TRUNC; } /* try to open the file */ fd = open(filename, flags, S_IWOTH | S_IRGRP | S_IWGRP | S_IWUSR | S_IRUSR); if (fd == -1) { switch (errno) { case EACCES: return ATX_ERROR_ACCESS_DENIED; case ENOENT: return ATX_ERROR_NO_SUCH_FILE; default: return ATX_ERROR_ERRNO(errno); } } } /* allocate new object */ stream = (FileByteStream*)ATX_AllocateZeroMemory(sizeof(FileByteStream)); if (stream == NULL) { ATX_CLEAR_OBJECT(object); return ATX_ERROR_OUT_OF_MEMORY; } /* construct object */ stream->reference_count = 1; stream->fd = fd; stream->offset = 0; /* get the size */ { struct stat info; if (fstat(fd, &info) == 0) { stream->size = info.st_size; } else { stream->size = 0; } } /* return reference */ ATX_INSTANCE(object) = (ATX_ByteStreamInstance*)stream; ATX_INTERFACE(object) = &FileByteStream_ATX_ByteStreamInterface; return ATX_SUCCESS; }