| 107 | } |
| 108 | |
| 109 | void Compute(OpKernelContext* context) override { |
| 110 | OP_REQUIRES( |
| 111 | context, context->num_inputs() == 4, |
| 112 | errors::InvalidArgument("DecodeAudio requires exactly four inputs.")); |
| 113 | |
| 114 | const Tensor& contents_tensor = context->input(0); |
| 115 | const Tensor& file_format_tensor = context->input(1); |
| 116 | const Tensor& samples_per_second_tensor = context->input(2); |
| 117 | const Tensor& channel_count_tensor = context->input(3); |
| 118 | |
| 119 | OP_REQUIRES(context, TensorShapeUtils::IsScalar(contents_tensor.shape()), |
| 120 | errors::InvalidArgument( |
| 121 | "contents must be a rank-0 tensor but got shape ", |
| 122 | contents_tensor.shape().DebugString())); |
| 123 | OP_REQUIRES(context, TensorShapeUtils::IsScalar(file_format_tensor.shape()), |
| 124 | errors::InvalidArgument( |
| 125 | "file_format must be a rank-0 tensor but got shape ", |
| 126 | file_format_tensor.shape().DebugString())); |
| 127 | OP_REQUIRES(context, |
| 128 | TensorShapeUtils::IsScalar(samples_per_second_tensor.shape()), |
| 129 | errors::InvalidArgument( |
| 130 | "samples_per_second must be a rank-0 tensor but got shape ", |
| 131 | samples_per_second_tensor.shape().DebugString())); |
| 132 | OP_REQUIRES(context, |
| 133 | TensorShapeUtils::IsScalar(channel_count_tensor.shape()), |
| 134 | errors::InvalidArgument( |
| 135 | "channel_count must be a rank-0 tensor but got shape ", |
| 136 | channel_count_tensor.shape().DebugString())); |
| 137 | |
| 138 | const tensorflow::StringPiece contents = |
| 139 | contents_tensor.scalar<tstring>()(); |
| 140 | const string file_format = |
| 141 | absl::AsciiStrToLower(file_format_tensor.scalar<tstring>()()); |
| 142 | const int32 samples_per_second = |
| 143 | samples_per_second_tensor.scalar<int32>()(); |
| 144 | const int32 channel_count = channel_count_tensor.scalar<int32>()(); |
| 145 | |
| 146 | const std::set<string> valid_file_formats( |
| 147 | kValidFileFormats, kValidFileFormats + TF_ARRAYSIZE(kValidFileFormats)); |
| 148 | OP_REQUIRES(context, valid_file_formats.count(file_format) == 1, |
| 149 | errors::InvalidArgument("file_format must be one of {", |
| 150 | absl::StrJoin(valid_file_formats, ", "), |
| 151 | "}, but was: \"", file_format, "\"")); |
| 152 | OP_REQUIRES(context, samples_per_second > 0, |
| 153 | errors::InvalidArgument( |
| 154 | "samples_per_second must be positive, but got: ", |
| 155 | samples_per_second)); |
| 156 | OP_REQUIRES( |
| 157 | context, channel_count > 0, |
| 158 | errors::InvalidArgument("channel_count must be positive, but got: ", |
| 159 | channel_count)); |
| 160 | |
| 161 | Decode(context, contents, file_format, samples_per_second, channel_count, |
| 162 | stream_); |
| 163 | } |
| 164 | |
| 165 | private: |
| 166 | string stream_; |
nothing calls this directly
no test coverage detected