gusucode.com > audiovideo工具箱matlab源码程序 > audiovideo/+audiovideo/+internal/+writer/+plugin/MJ2000Plugin.m
classdef (Hidden) MJ2000Plugin < audiovideo.internal.writer.plugin.IPlugin %MJ2000Plugin Extension of the IPlugin class to write Motion JPEG 2000 files. % % This file is the plugin for writing Motion JPEG 2000 plugins. % Copyright 2010-2013 The MathWorks, Inc. properties ColorFormat = [] ColorChannels = []; BitsPerPixel = []; end properties (Access=protected) FileName; end methods function obj = MJ2000Plugin(fileName) %MJ2000Plugin Construct a MJ2000Plugin object. % % OBJ = MJ2000Plugin(FILENAME) constructs a MJ2000Plugin % object pointing to the file specified by FILENAME. The file % is not created until MJ2000Plugin.open() is called. % % See also MJ2000Plugin/open, MJ2000Plugin/close. obj = obj@audiovideo.internal.writer.plugin.IPlugin(); % Handle the zero argument constructor. This is needed, for % example, when constructing empty profile objects. if isempty(fileName) obj.Channel = []; return; end obj.FileName = fileName; end function set.FileName(obj, value) obj.FileName = value; % After setting the value, create the asyncio Channel object. % This is done here instead of in the constructor % so that the channel is initialized properly during load and % save obj.createChannel(); end function open(obj, options) %OPEN Opens the channel for writing. % MATFilePlugin objects must be open prior to calling % writeVideoFrame. assert(~isempty(obj.Channel), 'Channel must be set before opening the plugin'); obj.open@audiovideo.internal.writer.plugin.IPlugin(); try obj.Channel.open(options); catch devErr obj.handleDeviceError(devErr.identifier, devErr.message); end end function writeVideoFrame(obj, data) %writeVideoFrame Write a single video frame to the channel. % obj.writeVideoFrame(data) will write a single video frame % to the channel. Since the MATFilePlugin isn't actually a % video plugin, MATFilePlugin/writeVideoFrame will accept any % data in any format, which is useful for testing. assert(~isempty(obj.Channel), 'Channel must be set before writing to the plugin'); assert(obj.Channel.isOpen(), 'Channel must be open before writing data.'); assert(isnumeric(data),'Data to write must be numeric'); try obj.Channel.OutputStream.write(data); catch devErr obj.handleDeviceError(devErr.identifier, devErr.message); end end function [pluginName, mlConverterName, slConverterName, options] = ... getChannelInitOptions(obj) %GETCHANNELINITOPTIONS options for asyncio channel creation % Setup options used in createChannel function. % Subclasses can override this function to provide custom % plugins and options pluginName = 'videomj2000writerplugin'; [mlConverterName, slConverterName] = obj.getConverterName; options.OutputFileName = obj.FileName; end function [filterName, options] = getFilterInitOptions(obj) filterName = 'videotransformfilter'; options.InputFrameType = 'RawPlanarColumn'; if ~isempty(obj.Channel) options.OutputFrameType = obj.Channel.ExpectedFrameType; else options.OutputFrameType = ''; end end end methods(Access=protected) function [mlErrorID, msgHoles] = deviceErrorToErrorID(obj, deviceErr, deviceMsg) %DEVICEERRORTOERRORID conversion from Device Error ID to MATLAB %Error ID % Convert the Error ID generated by the Device Plugin to a % MATLAB Error ID. Each plugin has knowledge about the % specific errors that are thrown by the corresponding Device % Plugin msgHoles = {}; mlPrefix = audiovideo.internal.writer.plugin.IPlugin.ErrorPrefix; switch(deviceErr) case 'mj2000Plugin:invalidFileName' mlErrorID = sprintf('%s:%s', mlPrefix, 'invalidFileName'); case 'mj2000Plugin:invalidFrameRate' mlErrorID = sprintf('%s:%s', mlPrefix, 'invalidFrameRate'); case 'mj2000Plugin:kakaduError' mlErrorID = sprintf('%s:%s', mlPrefix, 'kakaduError'); msgHoles = {deviceMsg}; case 'mj2000Plugin:invalidCharInFileName' mlErrorID = sprintf('%s:%s', mlPrefix, 'invalidCharInFileName'); otherwise mlErrorID = sprintf('%s:%s', mlPrefix, 'unexpectedError'); end end end end